-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsketch.js
More file actions
55 lines (45 loc) · 1.14 KB
/
sketch.js
File metadata and controls
55 lines (45 loc) · 1.14 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
var stars = []
var speed;
function setup() {
var ht = document.getElementById('canvas').offsetHeight;
var wt = document.getElementById('canvas').offsetWidth;
var cnv=createCanvas(wt,ht);
cnv.parent("canvas");
for (var i = 0; i < 800; i++) {
stars[i] = new Star();
}
}
function draw() {
speed = 7;
background(0);
translate(width / 2, height / 2);
for (var i = 0; i < stars.length; i++) {
stars[i].update();
stars[i].show();
}
}
function Star() {
this.x = random(-width, width);
this.y = random(-height, height);
this.z = random(width);
this.pz = this.z;
this.update = function() {
this.z = this.z - speed;
if (this.z < 1) {
this.z = width;
this.x = random(-width, width);
this.y = random(-height, height);
this.pz = this.z;
}
}
this.show = function() {
var colors=["#fff","#0c9ba8","#a8170d","#0c9ba8"]
var col=colors[Math.floor(Math.random()*colors.length)]
fill(col);
noStroke();
var sx = map(this.x / this.z, 0, 1, 0, width);
var sy = map(this.y / this.z, 0, 1, 0, height);
var r = map(this.z, 0, width, 16, 0);
ellipse(sx, sy, r, r);
}
}