xxxxxxxxxx
function setup() {
createCanvas(960,600);
rectMode(CENTER);
noFill();
noStroke();
angleMode(DEGREES);
makeNodes();
colors = [
color(255, 0, 0),
color(0, 255, 0),
color(0, 0, 255)
];
}
//making the array of nodes
let nodes = [];
let num;
let colors;
function draw() {
//default blend mode
blendMode(BLEND);
background(255);
// turn on exclusion
blendMode(EXCLUSION);
//display every node and move them
for(let i = 0; i < nodes.length;i++){
nodes[i].display();
nodes[i].move();
}
}
function makeNodes(){
let num = 8;
let c = 0;
for(let i = 0; i < 360; i+=num){
nodes.push(new node(width/2,height/2,i,c));
c++;
}
}
class node{
constructor(x,y,a,c){
this.x = x;
this.y = y;
this.a = a;
this.i = c;
}
move(){
this.a+=1;
this.x = this.x+2*sin(this.a);
}
display(){
fill(colors[this.i%3]);
translate(this.x,this.y);
rect(0,0,abs(sin(this.a)*100)+200,200);
resetMatrix();
}
}