-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
112 lines (89 loc) · 2.24 KB
/
sketch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/* eslint-disable */
var vehicle, cnv, stayWithinWalls;
var food = [];
var colors = [];
var gradColors = [];
function setup() {
// let w = $('.canvas-container').width();
// let h = $('.canvas-container').height();
// console.log(450, 600);
cnv = createCanvas(650, 550);
cnv.parent('#cnv');
gradColors = [
color(255, 165, 0),
color(228, 137, 35),
color(216, 124, 50),
color(197, 104, 73),
color(98, 15, 163),
color(113, 27, 153),
color(128, 39, 142),
color(146, 55, 127),
];
// $("canvas").css("position", "static");
vehicle = new Vehicle();
centre = createVector(width / 2, height / 2);
stayWithinWalls = $('#within-walls');
noStroke();
for (var i = 0; i < 20; i++) {
var x = random(30, width - 30);
var y = random(30, height - 30);
var clrIndex = Math.floor(random(gradColors.length));
food.push(new Food(x, y, gradColors[clrIndex]));
// var r = random(255);
// var g = random(255);
// var b = random(255);
// colors.push(color(255, 165, 0));
}
cnv.mouseClicked(function () {
food.push(
new Food(
mouseX,
mouseY,
gradColors[Math.floor(random(gradColors.length))]
)
);
$('#checkpoint-count').css('opacity', 0.5);
$('#checkpoint-count').css('color', '#8f8f8f');
// colors.push(color(random(255), random(255), random(255)));
});
}
function draw() {
// push();
// fill('white');
// text('Points passed = ' + vehicle.numOfObjectsPassed, 10, 20);
// pop();
background(22, 22, 22);
vehicle.render();
if (food.length != 0) {
vehicle.seek(food);
} else {
finish();
}
for (var i = 0; i < food.length; i++) {
// console.log(gradColors.length);
// var ind = Math.floor(random(gradColors.length));
// console.log(gradColors[i]);
// ind++;
// fill(gradColors[ind % 8]);
// ellipse(food[i].x, food[i].y, 8, 8);
food[i].display();
}
// updateCheckpointCount();
}
function finish() {
vehicle.reset();
push();
textAlign(CENTER);
textSize(32);
fill('white');
text('FINISHED', width / 2, height / 2);
pop();
$('#checkpoint-count').css('opacity', 1);
$('#checkpoint-count').css('color', '#ffbb00');
}
// function windowResized() {
// let w = $('.canvas-container').width();
// let h = $('.canvas-container').height();
// // console.log(w, h);
// resizeCanvas(w, h);
// }