xxxxxxxxxx
68
class Point {
constructor(x, y) {
this.x = x
this.y = y
}
static random() {
let m = 20
return new Point(
m + random(width - 2*m),
m + random(height - 2*m)
)
}
}
class Trigon {
constructor(P1, P2, P3) {
this.P1 = P1
this.P2 = P2
this.P3 = P3
this.C = new Point(
(P1.x + P2.x + P3.x) / 3,
(P1.y + P2.y + P3.y) / 3
)
}
draw() {
stroke(180)
strokeWeight(1)
triangle(this.P1.x, this.P1.y,
this.P2.x, this.P2.y,
this.P3.x, this.P3.y )
strokeWeight(3)
stroke(0)
point(this.C.x, this.C.y)
strokeWeight(1)
beginShape()
vertex(this.P1.x, this.P1.y)
quadraticVertex(this.C.x, this.C.y,
this.P2.x, this.P2.y)
quadraticVertex(this.C.x, this.C.y,
this.P3.x, this.P3.y)
quadraticVertex(this.C.x, this.C.y,
this.P1.x, this.P1.y)
endShape()
}
}
function setup() {
noLoop()
noFill()
createCanvas(400, 400);
}
function draw() {
background(220);
let t1 = new Trigon(
Point.random(),
Point.random(),
Point.random()
)
t1.draw()
}