xxxxxxxxxx
var inc = 0.1;
var scl = 20;
var cols, rows;
var zoff = 0;
var particles = [];
var flowfield;
var midPoint;
var stars = [];
var speed;
var fas =[];
let fafafishs=[];
var bg
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
function setup() {
background(0);
createCanvas(windowWidth, windowHeight);
bg=createGraphics(windowWidth, windowHeight) //secondary background
midPoint = createVector(width/2, height/2)
colorMode(RGB, 255);
cols = floor(width / scl);
rows = floor(height / scl);
flowfield = new Array(cols * rows);
for (var i = 0; i <120; i++) {
particles[i] = new Particle();
}
for (var i = 0; i < 400; i++) {
stars[i] = new Star();
}
for (let f =0; f<10; f++) {
fafafishs[f]=new Fafafish();
}
}
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
function draw() {
background(0);
push()
translate(width/2,height/2)
scale( pow(frameCount,0.3)/5)
bg.background(0,1)
image(bg,-width/2,-height/2)
pop()
push();
var yoff = 0;
for (var y = 0; y < rows; y++) {
var xoff = 0;
for (var x = 0; x < cols; x++) {
var index = x + y * cols;
var angle = noise(xoff, yoff, zoff) * TWO_PI * 4;
var v = p5.Vector.fromAngle(angle);
v.setMag(0.35);
flowfield[index] = v;
xoff += inc;
}
yoff += inc;
zoff += 0.0003;
}
for (var i = 0; i < particles.length; i++) {
particles[i].follow(flowfield);
var ff = pow((frameCount/50+0.5),0.7);
var r = height/2-height/2*(1/ff) + 40* sin(frameCount/10+ degrees(midPoint.copy().sub(particles[i].pos).heading())/2)
if (particles[i].pos.dist(midPoint)>r) { //bounding back if hit the circle
var distToCirBound = particles[i].pos.dist(midPoint)-r
var pullVel = midPoint.copy().sub(particles[i].pos).limit(5).normalize().mult( distToCirBound*3 )
particles[i].applyForce(pullVel)
}
particles[i].update();
particles[i].show();
}
pop();
/////////////////////////////////////////////////////////////////////////////
push();
speed = (10);
translate(width / 2, height / 2);
for (var i = 0; i < stars.length; i++) {
stars[i].update();
stars[i].show();
}
pop();
/////////////////////////////////////////////////////////////////////////////
push();
speedf = (0.5);
translate(width / 2, height / 2);
for (let f =0; f<fafafishs.length; f++) {
fafafishs[f].update();
fafafishs[f].ffdisplay(f);
}
pop();
}
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
function Particle() {
this.pos = createVector(random(-5, 5)+width/2, random(-5, 5)+(height/2));
this.vel = createVector(0, 0);
this.acc = createVector(0, 0);
this.maxspeed =3;
this.h = 0;
this.prevPos = this.pos.copy();
this.update = function() {
this.vel.add(this.acc);
this.vel.limit(this.maxspeed);
this.pos.add(this.vel);
this.acc.mult(0);
}
this.follow = function(vectors) {
var x = floor(this.pos.x / scl);
var y = floor(this.pos.y / scl);
var index = x + y * cols;
var force = vectors[index];
this.applyForce(force);
}
this.applyForce = function(force) {
this.acc.add(force);
}
this.show = function() {
var dis = dist(this.pos.x, this.pos.y, width/2, height/2);
bg.r=dis*0.5
bg.r2=dis*0.6
bg.g=(abs(155-dis*0.5))
bg.g2=(abs(100-dis*0.4))
bg.b= (200-dis*1)
bg.b2= (230-dis*0.7)
bg.stroke (bg.r, bg.g, bg.b, 45);
// bg.stroke (bg.r2, bg.g2, bg.b2, 45);
if (mouseIsPressed) {
bg.r=bg.r2
bg.g=bg.g2
bg.b=bg.b2
} else {
bg.stroke (bg.r2, bg.g2, bg.b2, 45);
}
this.h = this.h + 1;
if (this.h > 255) {
this.h = 0;
}
bg.strokeWeight(2);
bg.line(this.pos.x, this.pos.y, this.prevPos.x, this.prevPos.y);
this.updatePrev();
}
this.updatePrev = function() {
this.prevPos.x = this.pos.x;
this.prevPos.y = this.pos.y;
}
}
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
function Star() {
this.x = random(-width, width);
this.y = random(-height, height);
this.z = random(width);
this.update = function() {
this.z = this.z - speed;
if (this.z < 1) {
//background(0);
this.z = width;
this.x = random(-width, width);
this.y = random(-height, height);
}
}
this.show = function() {
fill(190);
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);
strokeWeight(1);
ellipse(sx, sy, r, r);
}
}
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
function Fafafish() {
this.x = random(-width, width);
this.y = random(-height, height);
this.z = random(width);
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.ffdisplay = function() {
fill(190);
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, 8, 0);
noFill();
push()
translate(sx,sy);
scale(r/5);
translate(-180,-250);
strokeWeight(1.5);
stroke(255, 222, 111);
ellipse(164, 270, 55, 55);
ellipse(166, 274, 56, 55);
ellipse(168, 270, 57, 56);
ellipse(162, 272, 55, 57);
ellipse(162, 268, 57, 55);
//fish
strokeWeight(4.3);
point(207, 257);
strokeWeight(1.8);
strokeCap(ROUND);
stroke(250, 119, 119);
bezier(216, 259, 209, 273, 198, 261, 198, 261);
//petal
strokeWeight(4);
stroke(255);
bezier(159, 250, 256, 14, 299, 324, 185, 262);
bezier(139, 252, 26, 98, 199, 173, 162, 245);
bezier(139, 252, 28, 162, 29, 306, 141, 270);
bezier(156, 283, 98, 454, 39, 306, 141, 270);
bezier(156, 283, 78, 436, 202, 377, 173, 294);
bezier(191, 281, 328, 403, 184, 393, 173, 294);
bezier(191, 281, 390, 354, 266, 193, 185, 262);
pop()
}
}
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////