-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisual-keyboard.pde
More file actions
152 lines (131 loc) · 3.49 KB
/
visual-keyboard.pde
File metadata and controls
152 lines (131 loc) · 3.49 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// Setup the Processing Canvas
void setup() {
doResize();
frameRate(30);
}
var _$doc = $(document);
var _$window = $(window);
var _blooms = [];
var _maxBlooms = 10;
// Plant seeds
for (var i = 0; i < _maxBlooms; i++) {
randomBloom();
}
void mouseClicked() {
var b = new LightBloom(mouseX, mouseY);
_blooms.push(b);
trimBlooms();
}
function randomBloom() {
var x = Math.random() * _$window.width();
var y = Math.random() * _$window.height();
var b = new LightBloom(x, y);
_blooms.push(b);
trimBlooms();
}
function trimBlooms() {
while (_blooms.length > _maxBlooms) {
_blooms.shift();
}
}
// Main draw loop
void draw() {
background(45, 45, 45);
for(var i = 0; i < _blooms.length; i++) {
var b = _blooms[i];
b.draw(frameCount);
}
}
// Classes
function Color(r, g, b) {
this.r = r;
this.g = g;
this.b = b;
}
function ColorRotator(color, min, max) {
this.color = color;
this.delta = new Color(0, 0, 0); // Contains offsets, so may be negative
this.min = min;
this.max = max;
this.step = 1;
}
ColorRotator.prototype.rotate = function rotateColor() {
if (this.color.r == this.max && this.color.g == this.min && this.color.b == this.min) {
this.delta.r = 0;
this.delta.g = this.step;
this.delta.b = 0;
}
else if (this.color.r == this.max && this.color.g == this.max && this.color.b == this.min) {
this.delta.r = -1 * this.step;
this.delta.g = 0;
this.delta.b = 0;
}
else if (this.color.r == this.min && this.color.g == this.max && this.color.b == this.min) {
this.delta.r = 0;
this.delta.g = 0;
this.delta.b = this.step;
}
else if (this.color.r == this.min && this.color.g == this.max && this.color.b == this.max) {
this.delta.r = 0;
this.delta.g = -1 * this.step;
this.delta.b = 0;
}
else if (this.color.r == this.min && this.color.g == this.min && this.color.b == this.max) {
this.delta.r = this.step;
this.delta.g = 0;
this.delta.b = 0;
}
else if (this.color.r == this.max && this.color.g == this.min && this.color.b == this.max) {
this.delta.r = 0;
this.delta.g = 0;
this.delta.b = -1 * this.step;
}
this.color.r += this.delta.r;
this.color.g += this.delta.g;
this.color.b += this.delta.b;
return this.color;
}
function LightBloom(x, y) {
this.x = x;
this.y = y;
var rand = Math.floor(Math.random() * 3);
var r = 100;
var g = 100;
var b = 100;
if (rand == 0) {
r = 200;
}
else if (rand == 1) {
g = 200
}
else {
b = 200;
}
this.rotator = new ColorRotator(new Color(r, g, b), 100, 200);
this.radius = 10;
var w = _$window.width();
var b1 = 150 + Math.random() * w / 3;
var b2 = 150 + Math.random() * w / 3;
this.maxRadius = Math.max(b1, b2);
this.minRadius = Math.min(b1, b2);
this.radiusStep = 1 + Math.random() * 3;
}
LightBloom.prototype.draw = function(frm) {
var c = this.rotator.rotate();
fill(c.r, c.g, c.b);
ellipse(this.x, this.y, this.radius, this.radius);
this.radius += this.radiusStep;
if (this.radius > this.maxRadius && this.radiusStep > 0) {
this.radiusStep *= -1;
}
else if (this.radius < this.minRadius && this.radiusStep < 0) {
this.radiusStep *= -1;
}
}
function doResize() {
var setupHeight = Math.max(_$doc.height(), _$window.height());
$('#Background').width(_$window.width());
$('#Background').height(setupHeight);
size(_$window.width(), setupHeight);
}
_$window.resize(doResize);