• Black Vimeo Icon

©2020 BY JENNY LIN

Communication between Diamonds

Updated: Oct 28, 2019

After seeing how lines could create extraordinary patterns, I decided to try it myself this week.

This is what I got!



I used arrays to generate the diamonds consisting of lines, and they could sense each other as the fill applies when they intersect with each other on a certain level.

Click here to modify the codes yourself!


Before I made the diamonds communicate with each other, this is what I had.






Codes


let angle1, angle2;

let diamonds = [];


function setup() {

createCanvas(600, 600);

angleMode(DEGREES);

for (i = 0; i < 10; i++) {

let d = new Diamond(random(3 / 2 * width), random(3 / 2 * height), random(width / 2), random(150, 255), random(50, 100), random(150, 255), random(1, 2))

diamonds.push(d);

}

}


function draw() {

background(20, 30);

for (let d in diamonds) {

diamonds[d].show();

diamonds[d].move();


let overlapping = false;

for (let other in diamonds) {

if (diamonds[d] !== diamonds[other] && diamonds[d].intersect(diamonds[other])) {

overlapping = true;

}

}

if (overlapping) {

diamonds[d].fillColor();

} else {

diamonds[d].show();

}

}

}


class Diamond {

constructor(_x, _y, _r, _colr, _colg, _colb, _strW) {

this.x = _x;

this.y = _y;

this.r = _r;

this.colr = _colr;

this.colg = _colg;

this.colb = _colb;

this.strW = _strW

}


show() {

stroke(this.colr, this.colg, this.colb);

strokeWeight(this.strW);

angle1 = map(millis(), 0, 1000, 0, 180);

angle2 = map(millis(), 0, 1000, 180, 0);


push();

translate(this.x, this.y);

beginShape();

vertex(constrain(this.r * cos(angle1), -this.r, this.r), 0);

vertex(0, constrain(this.r * sin(angle1), -this.r, this.r));

vertex(constrain(this.r * cos(angle2), -this.r, this.r), 0);

vertex(0, constrain(this.r * sin(angle2), -this.r, this.r));

endShape();


rotate(180);

beginShape();

vertex(constrain(this.r * cos(angle1), -this.r, this.r), 0);

vertex(0, constrain(this.r * sin(angle1), -this.r, this.r));

vertex(constrain(this.r * cos(angle2), -this.r, this.r), 0);

vertex(0, constrain(this.r * sin(angle2), -this.r, this.r));

endShape();

pop();

}


move() {

this.x += random(-5, 5);

this.y += random(-5, 5);

}


intersect(other) {

let d = dist(this.x, this.y, other.x, other.y);

return (d < (this.r + other.r) / 2);

}


fillColor() {

fill(this.colr, this.colg, this.colb);

push();

translate(this.x, this.y);

beginShape(TRIANGLES);

vertex(constrain(this.r * cos(angle1), -this.r, this.r), 0);

vertex(0, constrain(this.r * sin(angle1), -this.r, this.r));

vertex(constrain(this.r * cos(angle2), -this.r, this.r), 0);

vertex(0, constrain(this.r * sin(angle2), -this.r, this.r));

endShape();


rotate(180);

beginShape(TRIANGLES);

vertex(constrain(this.r * cos(angle1), -this.r, this.r), 0);

vertex(0, constrain(this.r * sin(angle1), -this.r, this.r));

vertex(constrain(this.r * cos(angle2), -this.r, this.r), 0);

vertex(0, constrain(this.r * sin(angle2), -this.r, this.r));

endShape();

pop();

}

}


#ITP #ICM #computationalMedia #diamonds #lines #intersect #arrays #class #objects