-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmySketch.js
85 lines (71 loc) · 1.93 KB
/
mySketch.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
const randint = (m ,M) => m + Math.floor((M - m) * Math.random());
let s = randint(2, 8);
var puzzle = [...Array(s)].map(x=>[...Array(s)].map(y=>1));
var fQ = randint(2, s * s);
function toggle(y, x, puzzle){
for(let i = 0; i < puzzle.length; i++){
for(let j = 0; j < puzzle.length; j++){
if(i == y || x == j)
puzzle[i][j] = 1 - puzzle[i][j];
}
}
}
for(let _ = 0; _ < fQ; _++){
let row = randint(0, s);
let col = randint(0, s);
toggle(row, col, puzzle);
}
function setup() {
createCanvas(500, 500);
}
function drawTheBoard(size, puzzle){
noFill();
strokeWeight(7);
stroke(140, 22, 0);
rect(0, 0, height, height);
let num = puzzle.length;
for(let i = 0; i < num; i++){
for(let j = 0; j < num; j++){
stroke(160);
strokeWeight(1);
fill(0, 0, 18);
rect(j*size + size/15, i*size + size/15, size - 2*size/15, size - 2*size/15);
if(puzzle[i][j]){
noStroke();
fill(255, 255, 0, 100);
ellipse(size * (j + 0.5), size * (i + 0.5), size/1.5, size/1.5);
fill(255, 255, 0, 150);
ellipse(size * (j + 0.5), size * (i + 0.5), size/3, size/3)
fill(255, 250, 0)
ellipse(size * (j + 0.5), size * (i + 0.5), size/10, size/10)
}
}
}
}
var LOL = 0;
function draw() {
if(LOL-- > 0){
background(randint(2, 255), randint(2, 255), randint(2, 255));
}
else{
background(255, 255, 255);
let size = height/puzzle.length;
drawTheBoard(size, puzzle);
let x = mouseX/size | 0, y = mouseY / size | 0;
if(mouseX > -1 && mouseY >-1 && y < puzzle.length && x < puzzle.length && mouseIsPressed){
toggle(y, x, puzzle);
mouseIsPressed = false;
}
if(puzzle.every(x=>x.every(y=>y==1))){
LOL = 70;
s = randint(2, 10);
puzzle = [...Array(s)].map(x=>[...Array(s)].map(y=>1));
fQ = randint(2, s * s);
for(let _ = 0; _ < fQ; _++){
let row = randint(0, s);
let col = randint(0, s);
toggle(row, col, puzzle);
}
}
}
}