-
Notifications
You must be signed in to change notification settings - Fork 0
/
galaxy.js
61 lines (49 loc) · 1.23 KB
/
galaxy.js
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
var stars = [];
var speed;
var slider;
var sliderS;
var starAmount;
var sp;
var sa;
function setup() {
createCanvas(1080, 720);
starAmount = 500;
for(var i = 0; i < starAmount; i++){
stars[i] = new Star();
}
createP('');
createElement('label','Speed: ');
slider = createSlider(-50, 50, 2);
sp = createElement('label', speed);
createP('');
createElement('label','Amount of Stars: ');
sliderS = createSlider(0, 2000, 500);
sa = createElement('label', starAmount);
createP('');
}
function check(){
if(stars.length > starAmount){
stars.splice(starAmount, stars.length - starAmount);
}else if(stars.length < starAmount){
for(var i = stars.length; i < starAmount; i++){
stars[i] = new Star();
}
}
}
function draw() {
background(0);
//text
textSize(20);
fill(255, 0, 0);
noStroke();
speed = slider.value();
check();
sp.html(speed);
sa.html(starAmount);
translate(width / 2, height / 2);
for(var i = 0; i < stars.length; i++){
stars[i].update();
stars[i].show();
}
starAmount = sliderS.value();
}