-
Notifications
You must be signed in to change notification settings - Fork 0
/
plaid.js
121 lines (72 loc) · 2.1 KB
/
plaid.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
113
114
115
116
117
118
119
let PlaidMaxAge =4000; // expressed in milliseconds
let plaidList = []; // contains every plaid in the game/simulation
let plaidLinesColor = "white";
let plaidLinesThickness = "1";
class Plaid {
constructor(){
this.tob = Date.now();
this.speed = 1;
}
makeBaby() {
this.tob = Date.now() + Math.random() * 100;
this.speed = Math.ceil(Math.random() * 2);
}
}
function calcPlaidSize(plaidAge, pSpeed){
let size = (plaidAge/PlaidMaxAge) * height;
size *= pSpeed;
if (size >= height ) return height;
else return size;
}
function drawHline(ypos){
let p1 = {x: 0, y:ypos};
let p2 = {x: width, y:ypos};
line(p1.x, p1.y, p2.x, p2.y);
}
function drawVline(xpos){
let p1 = {x: xpos, y:0};
let p2 = {x: xpos, y:height};
line(p1.x, p1.y, p2.x, p2.y);
}
function calcPlaidAge(tob) {
return Date.now() - tob ;
}
function drawPlaid(size) {
// a plaid is made of two v lines and two h lines.
// the lines form an ever-expanding square
stroke(plaidLinesColor); // <--- this is the color command
strokeWeight(plaidLinesThickness);
drawVline(width/2 + size);
drawVline(width/2 - size);
drawHline(height/2 + size);
drawHline(height/2 - size);
}
function correctPlaidSize(p) {
let plaidAge = calcPlaidAge(p.tob);
let plaidSize = calcPlaidSize(plaidAge,p.speed);
if( (plaidSize >= height/2) || (plaidAge >= PlaidMaxAge) )
p.makeBaby();
// else
//console.log(plaidSize);
}
function setLineThickness(p) {
// plaidLinesThickness = (calcPlaidSize(calcPlaidAge(p.tob),p.speed) /width) * 50;
}
function draw() {
background("#15291a");
plaidList.forEach(p => {
// console.log(p);
setLineThickness(p);
let age = calcPlaidAge(p.tob);
drawPlaid(calcPlaidSize(age, p.speed));
correctPlaidSize(p);
});
}
function setup() {
createCanvas(400, 400);
for(var i=0; i < 90; i++) {
let p = new Plaid();
plaidList.push(p);
// console.log(p);
}
}