let cones = [];
function setup() {
createCanvas(360,240);
for (let i = 0; i < 50; i++) {
let x = random(0, 360);
let y = random(0, 240);
let x1 = random(0, 360);
let y1 = random(0, 240);
let x2 = random(0, 360);
let y2 = random(0, 240);
cones[i] = new Triangle(x,y,x1,y1,x2,y2);
}
}
function draw() {
background(0);
for(let i = 0; i < 5; i++) {
//cones[i].move();
cones[i].display();
}
}
function mousePressed() {
let x = random(0, 360);
let y = random(0, 240);
let x1 = random(0, 360);
let y1 = random(0, 240);
let x2 = random(0, 360);
let y2 = random(0, 240);
let c = new Triangle(mouseX, mouseY, x1, y1, x2, y2);
cones.push(c);
}
class Triangle {
constructor(x,y,x1, y1,x2,y2) {
this.x = x;
this.y = y;
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
}
display() {
stroke(50,194,232);
strokeWeight(4);
noFill();
triangle(this.x, this.y, this.x1, this.y1, this.x2, this.y2);
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.0.0/p5.min.js"></script>
I am trying to get a new triangle to add to the canvas every time the mouse is pressed... if you could also help me change the size/color that would be amazing!!