var ps = [];var n = 65;var cha
processing吧
全部回复
仅看楼主
level 1
var ps = [];
var n = 65;
var changey = 0;
var changeval;
function setup() {
createCanvas(windowWidth, windowHeight);
for(var i = 0; i < n; i++){
ps.push(new par());
}
ps.push(new center());
noStroke();
}
function draw() {
background(0,0,0,50);
changey = -100;
ps.sort(function(a, b){return a.order - b.order});
if((mouseX > windowWidth/2 && pmouseX < windowWidth/2) || (mouseX < windowWidth/2 && pmouseX > windowWidth/2)){
changey = mouseY;
changeval = mouseX - pmouseX;
}
for(var i = 0; i < n; i++){
ps[i].draw();
}
}
function par(){
this.y = random(windowHeight * 0.04, windowHeight * 0.96);
this.r = random(50, 200);
this.t = random(0, 2*PI);
this.c = random(0.008, 0.03);
this.s = random(1, 12);
this.colour = random(0, 255);
this.order = 0;
this.draw = function(){
fill(this.colour, 255-this.colour, 255, sin(this.t/2)*150 + 20);
ellipse(this.r * sin(this.t) + width/2, this.y, (sin(this.t/2)+2)* this.s);
if (this.y < changey + 90 && this.y > changey - 90){
this.c += changeval / 3000;
}
if (this.c > 0.03){
this.c = this.c* 0.99
} else if (this.c < -0.03){
this.c = this.c * 0.99
}
this.t -= this.c;
if (this.t < 0){
this.t = 2*PI;
} else if (this.t > 2*PI){
this.t = 0;
}
this.order = sin(this.t/2) * this.r;
}
}
function center(){
this.order = 2*PI;
this.draw = function(){
fill(200,200,255, 10);
rect(windowWidth/2 - 2,0,4,windowHeight);
}
}
2019年12月03日 13点12分 1
1