-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsketch.js
More file actions
120 lines (104 loc) · 2.54 KB
/
sketch.js
File metadata and controls
120 lines (104 loc) · 2.54 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
/// <reference types="p5/global" />
// constants
const PARTICLE_COUNT = 50;
const SEQUENCER_STEPS = 8;
const SEQUENCER_FREQUENCY = 8;
class Particle {
constructor() {
this.position = createVector(random(0, width), random(0, height));
this.color = color(random(0, 255), random(0, 255), random(0, 255));
this.angle = random(0, TWO_PI);
this.sequencers = {
size: createSequencer({
frequency: TimeFunction.frames(SEQUENCER_FREQUENCY),
steps: SEQUENCER_STEPS,
min: random(50, 100),
max: random(150, 200),
}),
angle: createSequencer({
frequency: TimeFunction.frames(SEQUENCER_FREQUENCY),
steps: SEQUENCER_STEPS,
min: -PI,
max: PI,
}),
};
}
update() {}
draw() {
push();
fill(this.color);
noStroke();
translate(this.position.x, this.position.y);
rotate(this.sequencers.angle.value);
rect(0, 0, this.sequencers.size.value, this.sequencers.size.value);
pop();
}
}
// locals
let lfo1;
let sequencer1, sequencer2;
function setup() {
createCanvas(700, 700);
rectMode(CENTER);
// lfo1 = createLfo({
// waveform: WAVE_SINE,
// frequency: TimeFunction.frames(6),
// min: -PI,
// max: PI,
// });
particles = [];
for (let i = 0; i < PARTICLE_COUNT; i++) {
particles.push(new Particle());
}
// pixelDensity(1);
// background(0);
sequencer1 = createSequencer({
steps: 8,
min: 0,
max: 1,
frequency: TimeFunction.frames(SEQUENCER_FREQUENCY),
});
sequencer2 = createSequencer({
steps: 8,
min: 0,
max: 1,
frequency: TimeFunction.frames(SEQUENCER_FREQUENCY),
});
}
function draw() {
background(0, 0, 0, 100);
particles.forEach((particle) => {
particle.update();
particle.draw();
});
// draw sequencer1
for (let i = 0; i < sequencer1.steps; i++) {
const x = map(i, 0, sequencer1.steps, 0, width);
const y = map(sequencer1.value, 0, 1, height, 0);
const w = width / sequencer1.steps;
const h = height - y;
if (i === sequencer1.step) {
fill(255, 0, 0);
} else {
fill(0);
}
rect(x, y, w, h);
}
// draw sequencer2
for (let i = 0; i < sequencer2.steps; i++) {
const x = map(i, 0, sequencer2.steps, 0, width);
const y = map(sequencer2.value, 0, 1, height, 0);
const w = width / sequencer2.steps;
const h = height - y;
if (i === sequencer2.step) {
fill(0, 255, 0);
} else {
fill(0);
}
rect(x, y, w, h);
}
}
let isLooping = true;
function mouseClicked() {
isLooping = !isLooping;
}