Skip to content

Commit 3d53607

Browse files
committed
adds spider legs
1 parent 0d38679 commit 3d53607

File tree

6 files changed

+120
-0
lines changed

6 files changed

+120
-0
lines changed

public/ep-l/index.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
7+
<title>Spider Legs</title>
8+
9+
<link rel="stylesheet" type="text/css" href="style.css">
10+
11+
<script src="libraries/p5.min.js"></script>
12+
</head>
13+
14+
<body>
15+
<script src="sketch.js"></script>
16+
</body>
17+
</html>

public/ep-l/jsconfig.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"include": [
3+
"*.js",
4+
"libraries/*.js",
5+
"/home/rohanoahmad/.vscode/extensions/samplavigne.p5-vscode-1.2.7/p5types/global.d.ts"
6+
]
7+
}

public/ep-l/libraries/p5.min.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/ep-l/sketch.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
const numRays = 8;
2+
const shadeStep = 1;
3+
const fadeDurationSeconds = 2;
4+
const minRayLength = 100;
5+
const maxRayLength = 300;
6+
const angleNoiseSpeed = 0.1;
7+
const lengthNoiseSpeed = 2;
8+
const positionNoiseSpeed = 0.4;
9+
10+
let shade = 255;
11+
let shadeDirection = -1;
12+
let angleOffsets = [];
13+
let lengthOffsets = [];
14+
let xOffset;
15+
let yOffset;
16+
let emitterX;
17+
let emitterY;
18+
19+
function setup() {
20+
createCanvas(windowWidth, windowHeight);
21+
background(0);
22+
strokeWeight(10);
23+
strokeCap(ROUND);
24+
25+
angleMode(RADIANS);
26+
noiseDetail(2, 0.5);
27+
28+
for (let i = 0; i < numRays; i += 1) {
29+
angleOffsets[i] = random(1000) + i * 50;
30+
lengthOffsets[i] = random(2000) + i * 100;
31+
}
32+
33+
xOffset = random(5000);
34+
yOffset = random(6000);
35+
emitterX = width / 2;
36+
emitterY = height / 2;
37+
}
38+
39+
function windowResized() {
40+
resizeCanvas(windowWidth, windowHeight);
41+
background(0);
42+
}
43+
44+
function draw() {
45+
const dtSeconds = deltaTime * 0.001;
46+
const fadeAlpha = min((255 * dtSeconds) / fadeDurationSeconds, 255);
47+
noStroke();
48+
fill(0, fadeAlpha);
49+
rect(0, 0, width, height);
50+
51+
xOffset += positionNoiseSpeed * dtSeconds;
52+
yOffset += positionNoiseSpeed * dtSeconds;
53+
54+
emitterX = map(noise(xOffset), 0, 1, 0, width);
55+
emitterY = map(noise(yOffset), 0, 1, 0, height);
56+
57+
strokeWeight(4);
58+
59+
for (let i = 0; i < numRays; i += 1) {
60+
const angleNoise = noise(angleOffsets[i]);
61+
const lengthNoise = noise(lengthOffsets[i]);
62+
const angle = angleNoise * TWO_PI;
63+
const rayLength = map(lengthNoise, 0, 1, minRayLength, maxRayLength);
64+
const targetX = emitterX + cos(angle) * rayLength;
65+
const targetY = emitterY + sin(angle) * rayLength;
66+
67+
stroke(shade);
68+
line(emitterX, emitterY, targetX, targetY);
69+
70+
shade += shadeDirection * shadeStep;
71+
if (shade >= 255 || shade <= 0) {
72+
shade = constrain(shade, 0, 255);
73+
shadeDirection *= -1;
74+
}
75+
76+
angleOffsets[i] += angleNoiseSpeed * dtSeconds;
77+
lengthOffsets[i] += lengthNoiseSpeed * dtSeconds;
78+
}
79+
}
80+
81+
function mousePressed() {
82+
background(0);
83+
}

public/ep-l/style.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
html, body {
2+
margin: 0;
3+
padding: 0;
4+
}
5+
6+
canvas {
7+
display: block;
8+
}

public/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
<a href ="ep-i/index.html">Photo Lines</a> <br/>
3333
<a href ="ep-j/index.html">Duck Dots</a> <br/>
3434
<a href ="ep-k/index.html">Grey Triangles</a> <br/>
35+
<a href ="ep-l/index.html">Spider Legs</a> <br/>
36+
3537

3638
</body>
3739
</html>

0 commit comments

Comments
 (0)