xxxxxxxxxx
65
var stars = [];
var speed = 4;
function setup() {
createCanvas(600, 380);
background(0);
noStroke();
for (var i = 0; i < 600; i++) {
stars[i] = new Star();
}
}
function draw() {
fill(0,180);// draw an alpha
rect(0,0,width,height);
//background(0);
translate(width / 2, height / 2);
for (var i = 0; i < stars.length; i++) {
stars[i].update();
stars[i].show();
stroke(255);
strokeWeight(0.1);
//line(0,0,stars[i].x,stars[i].y);
}
}
function Star() {
//this.x = random(-width, width);
//this.y = random(-height, height);
//this.z = random(600);
this.position=createVector(random(-width,width),random(-height,height),random(600));
this.velocity=createVector(0,0,-1);
this.acceleration=createVector(0,0,-0.001);
this.update = function() {
// var mouse=createVector(mouseX,mouseY);
// this.acceleration=p5.Vector.sub(mouse,this.position);
// this.acceleration.setMag(0.01);
this.velocity.add(this.acceleration);
this.position.add(this.velocity);
if (this.position.z <1) {
this.position.z =600;
this.position.x = random(-width,width);
this.position.y = random(-height,height);
}
}
this.show = function() {
fill(255);
stroke(255,150);
strokeWeight(random(2));
var sx = map(this.position.x / this.position.z, 0, 1, 0, width);
var sy = map(this.position.y/this.position.z, 0, 1, 0, height);
var r = map(this.position.z, 0, width, 10, 0);
ellipse(sx, sy, r, r);
}
}