-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsquareTrail.js
More file actions
73 lines (59 loc) · 1.58 KB
/
squareTrail.js
File metadata and controls
73 lines (59 loc) · 1.58 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
const sq = (p) => {
let nSquares = 100;
let squares = [];
let angle = 0;
let squareSize = 40;
let alphaIncr = 255 / nSquares;
let sizeIncr = squareSize / nSquares;
let count = 0;
p.setup = () => {
//var myCanvas = createCanvas(windowWidth, windowHeight);
//myCanvas.parent("landing");
//myCanvas.id('canvasSquares');
p.createCanvas(p.windowWidth, p.windowHeight);
p.rectMode(p.CENTER);
p.noFill();
p.strokeWeight(3);
p.angleMode(p.DEGREES);
for (let i = 0; i < nSquares; i++) {
squares.push(new Square(p.mouseX, p.mouseY, squareSize, angle, 255));
count++;
}
};
p.draw = () => {
p.clear();
for (let s of squares) {
s.show(p);
}
};
p.mouseMoved = () => {
angle += 4;
squares.shift();
squares.push(new Square(p.mouseX, p.mouseY, squareSize, angle, 255));
};
p.windowResized = () => {
p.resizeCanvas(p.windowWidth, p.windowHeight);
};
};
let squareSketch = new p5(sq, 'canvasSquares');
class Square {
constructor(x, y, size, angle, a) {
this.x = x;
this.y = y;
this.size = size;
this.angle = angle;
this.a = a;
}
show(p) {
p.stroke(0, this.a);
p.push();
p.translate(this.x, this.y);
p.rotate(this.angle);
p.rect(0, 0, this.size, this.size, 1);
p.pop();
//this.a -= alphaIncr;
//this.size -= sizeIncr;
this.a -= 10;
this.size -= 1;
}
}