xxxxxxxxxx
162
function make2DArray(cols, rows) {
let arr = new Array(cols);
for(let i = 0; i < arr.length; i++){
arr[i] = new Array(rows);
for(let j = 0; j < arr[i].length; j++){
arr[i][j] = 0;
}
}
return arr;
}
let w;
let rows, cols;
let dens;
let nzoom;
let dots;
let t1, t2;
let center;
let aim;
let here;
let speed;
let col;
let c;
function setup() {
createCanvas(900, 900);
// w = 1;
// cols = width / w;
// rows = height / w;
// grid = make2DArray(cols, rows);
dens = 5;
// nzoom = 200;
dots = [];
colors = ["#001524","#15616d","#ffecd1","#ff7d00","#78290f","#335c67","#fff3b0","#e09f3e","#9e2a2b","#540b0e"];
col = color(colors[0]);
t1 = 0;
t2 = 3;
t3 = 5;
// c = 0;
angles = 5;
speed = 1;
nzoom = 100;
// center = createVector(width / 2, height / 2);
// here = createVector(0, 0);
// there = createVector(0, 0);
// col = color(colors[floor(random(colors.length))]);
col = color("#001219");
count = width / dens * height / dens;
// for(i = 0; i < cols; i++){
// for(j = 0; j < rows; j++){
// grid[i][j] = createVector(1, 0);
// here = createVector(i * w, j * w);
// aim = p5.Vector.sub(center, here);
// // grid[i][j].setHeading(aim.heading() + HALF_PI + noise(i / nzoom + t1, j / nzoom + t2) * 5 + 2);
// grid[i][j].setHeading(aim.heading() + HALF_PI + noise(i / nzoom + t1, j / nzoom + t2) * 2);
// grid[i][j].setHeading(TWO_PI / angles * floor(map(grid[i][j].heading(), -TWO_PI, TWO_PI, -angles, angles) % angles));
// }
// }
for(i = 0; i < width / dens; i++){
for(j = 0; j < height / dens; j++){
dots[dots.length] = new Dot(i * dens + random(-dens, dens), j * dens + random(-dens, dens), dots.length);
}
}
background(col);
strokeWeight (1);
// stroke(30)
}
function draw() {
// col.setAlpha(20);
t1 = t1 + 0.01;
t2 = t2 + 0.02;
t3 = t3 + 0.04;
// nzoom = sin(t3) * 25
// if(frameCount % 250 == true){
// for(i = 0; i < cols; i++){
// for(j = 0; j < rows; j++){
// // here = createVector(i * w, j * w);
// // aim = p5.Vector.sub(center, here);
// // grid[i][j].setHeading(aim.heading() + HALF_PI + noise(i / nzoom + t1, j / nzoom + t2) * 5 + 2);
// // grid[i][j].setHeading(aim.heading() + HALF_PI + noise(i / nzoom + t1, j / nzoom + t2) * 1);
// grid[i][j].setHeading(noise(i / nzoom + t1, j / nzoom + t2) * TWO_PI * 2);
// grid[i][j].setHeading(TWO_PI / angles * floor(map(grid[i][j].heading(), -TWO_PI, TWO_PI, -angles, angles) % angles));
// }
// }
// }
for(i = 0; i < dots.length; i++){
if(dots[i] !== undefined){
dots[i].update();
}
}
}
class Dot {
constructor(x, y, index){
this.pos = createVector(x, y);
// this.length = floor(random(5) + 1);
// this.p = [];
// this.p1 = [];
// for(let a = 0; a <= this.length; a++){
// this.p[a] = createVector(x, y);
// }
this.index = index;
this.vel = createVector(1, 0);
// this.c = floor(colors.length / count * this.index % colors.length);
this.c = floor(this.index % colors.length);
// this.speed = 5 / ((width / dens * height / dens)) * this.index + 9;
this.speed = 1;
}
update(){
stroke(color(colors[this.c]));
if(this.pos.x < 0 || this.pos.x > width || this.pos.y < 0 || this.pos.y > height){
dots[this.index] = undefined;
}
// if(this.pos.x > 0 && this.pos.x < width && this.pos.y > 0 && this.pos.y < height){
// if(grid[floor(this.pos.x / w)][floor(this.pos.y / w)] !== undefined){
// this.vel.add(grid[floor(this.pos.x / w)][floor(this.pos.y / w)]);
// }
// } else {
// this.vel.setHeading(this.vel.heading() + HALF_PI)
// }
this.vel.setHeading(noise(this.pos.x / nzoom, this.pos.y / nzoom + this.index / (nzoom * 100000), this.c / 2) * TWO_PI * 4);
// this.vel.setMag(this.speed)
// this.vel.setHeading(this.vel.heading() + sin(frameCount / 2 + this.index / (this.length * 1)) * this.length * 0.02)
// for(let a = this.length; a > 1; a--){
// strokeWeight(this.length - a);
// this.p[a -1] = this.p[a - 2];
// line(this.p[a].x, this.p[a].y, this.p[a - 1].x, this.p[a - 1].y);
// }
// this.p[this.length] = this.p[this.length - 1];
this.vel.setHeading(TWO_PI / angles * floor((map(this.vel.heading(), -TWO_PI, TWO_PI, -angles, angles) ) + QUARTER_PI) + sin( this.pos.x / 400) + sin(t1) + sin(t2) * 0.5 + sin(t3) * 0.25);
// strokeWeight(random(0.1, 1));
// strokeWeight(this.speed);
// if(this.vel.mag() > this.speed){
// this.vel.setMag(this.speed)
// }
this.pos.add(this.vel);
point(this.pos.x, this.pos.y)
// this.p[0] = createVector(this.pos.x, this.pos.y);
}
}