-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmotion1.html
74 lines (63 loc) · 1.79 KB
/
motion1.html
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
<html>
<head>
<title>Art / Dev - Motion 2</title>
<script src="p5.min.js"></script>
<script>
var IMAGE_WIDTH = 640; // Don't change this.
var IMAGE_HEIGHT = 640; // Don't change this.
var particleCount = 300;
var particles = [];
var particleCounter = 0;
//=============== DO ALL YOUR WORK HERE =======================
function setup() {
createCanvas(IMAGE_WIDTH, IMAGE_HEIGHT); // don't change this
for (var i=0; i<particleCount; i++) {
particles[i] = {
x: 320,
y: 320,
vx: 0,
vy: 0,
curl: 0,
r: random(2, 4),
hue: random(-.2,.2)
};
}
noStroke()
colorMode(HSB, 1)
}
function draw() {
fill(.5,0,.4,.1)
rect(0,0,width,height)
var currentParticle = particles[particleCounter]
var magnitude = random(2,4)
var angle = random(0,2*PI)
currentParticle.x = mouseX
currentParticle.y = mouseY
// currentParticle.r = random(5, 10)
currentParticle.vx = magnitude*cos(angle)
currentParticle.vy = magnitude*sin(angle)
currentParticle.curl = pow(random(-1,1),7)
particleCounter = (particleCounter+1) % particleCount
particles.forEach(calculateParticle)
particles.forEach(drawParticle)
}
function calculateParticle(particle) {
particle.x += particle.vx
particle.y += particle.vy
particle.vx += particle.curl*particle.vy
particle.vy += -particle.curl*particle.vx
}
function drawParticle(particle) {
fill(particle.hue,0,1,1)
ellipse(particle.x,particle.y,particle.r,particle.r)
}
// =============== STOP WORKING HERE ==========================
</script>
<style>
body { padding: 0; margin: 5% 0 0; background-color: #666;}
canvas { margin: 0 auto; display:block; }
</style>
</head>
<body>
</body>
</html>