-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
89 lines (70 loc) · 1.91 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
var x = 1;
var y = 1;
var h = w = 25;
var m = 1;
var gsx = 0;
var gsy = 0;
var block = [];
var inc = 0.05;
var gridloaded = false;
var autoMargin = {x:0, y:0};
var fontsize = 12;
var zoff = 0;
function preload(){
font = loadFont('assets/SourceSansPro-Bold.otf');
}
function setup() {
createCanvas(windowWidth,windowHeight);
background(25);
textFont(font);
textSize(fontsize);
textAlign(CENTER, CENTER);
var gsx = Math.floor(windowWidth/(w+m));
var gsy = Math.floor(windowHeight/(h+m));
var lpx = gsx*(w+m);
var lpy = gsy*(h+m);
autoMargin.x = ((windowWidth-lpx)/2);
autoMargin.y = ((windowHeight-lpy)/2);
x = x + autoMargin.x
y = y + autoMargin.y
for (var i = 0; i < gsx*gsy; i++) {
block.push({x:x, y:y, s:0, b:0});
x += w+m;
if (x > gsx*(w+m)) {x=((windowWidth-lpx)/2)+1; y+= h+m};
}
}
function draw() {
var gsx = Math.floor(windowWidth/(w+m));
var gsy = Math.floor(windowHeight/(h+m));
var nx = Math.floor((mouseX+autoMargin.x)/(w+m));
var ny = Math.floor((mouseY-autoMargin.y)/(h+m));
var lpx = gsx*(w+m);
var lpy = gsy*(h+m);
if (nx>gsx) {nx=gsx};
if (ny>gsy) {ny=gsy};
var id = (gsx*ny)+nx-1;
noStroke();
colorMode(HSB, 100);
if (true) {
if ((gridloaded == true) && (id <= block.length) && (id >= 0)) {block[id].s ++; block[id].b += 20;}
var xoff = 0;
var yoff = 0;
for (var i = 0; i < block.length; i++) {
if (i % gsx == 0) {xoff = 0; yoff += inc;};
var hue = noise(xoff, yoff, zoff) * 150;
if (keyIsDown(DOWN_ARROW)) {block[i].b -= 20};
if (keyIsDown(UP_ARROW)) {block[i].b += 20};
fill(hue, 100, block[i].b);
rect(block[i].x, block[i].y, w, h);
xoff += inc;
}
gridloaded = true;
drawWords(windowWidth/2, 5);
}
zoff += 0.01;
}
function drawWords(x, y) {
fill(255);
text("move your mouse", x, y)
text("press UP and DOWN to change brightness", x, windowHeight-10)
}