-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch_GoF.js
69 lines (63 loc) · 1.24 KB
/
sketch_GoF.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
var cells = [];
var spacer;
var gameStart = false;
var cellsH;
var cellsW;
function setup() {
createCanvas(windowWidth, windowHeight);
cellsH = windowHeight/10;
cellsW = windowWidth/10;
for (var x = 0; x < cellsW; x++) {
cells[x] = []; // create nested array
}
spacer = 10;
frameRate(10);
}
function mouseDragged() {
cells[floor(mouseX/10)][floor(mouseY/10)] = true;
}
function clearCells() {
for (var x = 0; x < cellsW; x++) {
for (var y = 0; y < cellsH; y++) {
cells[x][y] = false;
}
}
}
function randomCells() {
for (var x = 0; x < cellsW; x++) {
for (var y = 0; y < cellsH; y++) {
var rdm = random(50)
if(rdm > 45){
cells[x][y] = true;
}
}
}
}
function keyPressed() {
if (keyCode === RIGHT_ARROW) {
gameStart = true;
} else if (keyCode === LEFT_ARROW) {
gameStart = false;
} else if (keyCode === 67){
print(key);
clear();
clearCells()
} else if (keyCode == 82){
print(key);
clear();
randomCells();
}
}
function draw() {
background(0);
for (var x = 0; x < cellsW; x++) {
for (var y = 0; y < cellsH; y++) {
if (cells[x][y]) {
rect(x*10 + spacer/2, y*10 + spacer/2, 10, 10);
}
}
}
if (gameStart) {
update();
}
}