-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLines2.html
51 lines (51 loc) · 1.38 KB
/
Lines2.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
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/p5.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/p5.dom.js"></script>
<style>
body{background-color:black;margin:0;padding:0;}
</style>
</head>
<body>
<script>
let rays=[];
let sep=5;
function setup(){
createCanvas(window.innerWidth,window.innerHeight);
background(0);
for(let i=0;i<height;i+=sep){
rays.push(new Beam(0,i,noise(i/200)));
}
}
function draw(){
for(let i=rays.length-1;i>=0;i--){
if(rays[i].show){
rays[i].show();
rays[i].update();
if(rays[i].pos.x>width || rays[i].pos.y>height || rays[i].pos.y<0){
rays=rays.slice(0,i).concat(rays.slice(i+1,rays.length));
}
}
}
}
class Beam{
constructor(x,y,noise){
this.pos=createVector(x,y);
this.vel=p5.Vector.fromAngle(noise*PI-PI/2);
this.pX=x;
this.pY=y;
}
show(){
stroke(255);
line(this.pos.x,this.pos.y,this.pX,this.pY);
}
update(){
this.pX=this.pos.x;
this.pY=this.pos.y;
this.pos.add(this.vel);
}
}
</script>
</body>
</html>