Renamed JS folder and started learning Crystal
This commit is contained in:
36
JavaScript/SimpleWebServer/public/JS/Starfeild/Star.js
Normal file
36
JavaScript/SimpleWebServer/public/JS/Starfeild/Star.js
Normal file
@@ -0,0 +1,36 @@
|
||||
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() {
|
||||
fill(255);
|
||||
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, 4, 0);
|
||||
ellipse(sx, sy, r, r);
|
||||
|
||||
var px = map(this.x / this.pz, 0, 1, 0, width);
|
||||
var py = map(this.y / this.pz, 0, 1, 0, height);
|
||||
|
||||
this.pz = this.z;
|
||||
|
||||
stroke(255);
|
||||
line(px, py, sx, sy);
|
||||
|
||||
}
|
||||
}
|
||||
20
JavaScript/SimpleWebServer/public/JS/Starfeild/sketch.js
Normal file
20
JavaScript/SimpleWebServer/public/JS/Starfeild/sketch.js
Normal file
@@ -0,0 +1,20 @@
|
||||
var stars = [];
|
||||
|
||||
var speed;
|
||||
|
||||
function setup() {
|
||||
createCanvas(600, 600);
|
||||
for (var i = 0; i < 800; i++) {
|
||||
stars[i] = new Star();
|
||||
}
|
||||
}
|
||||
|
||||
function draw() {
|
||||
speed = map(mouseX, 0, width, 0, 20);
|
||||
background(0);
|
||||
translate(width / 2, height / 2);
|
||||
for (var i = 0; i < stars.length; i++) {
|
||||
stars[i].update();
|
||||
stars[i].show();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user