class Tile {
constructor(x, y, w, n) {
this.x = x
this.y = y
this.w = w
this.n = n
this.angle = Math.PI / 2 * randInt(4)
this.isAnimated = random() < .5
this.offset = random(.1)
this.c1 = palette[randInt(1, palette.length)]
this.c2 = palette[randInt(1, palette.length)]
while(this.c1 === this.c2) this.c2 = palette[randInt(1, palette.length)]
}
display(s, t) {
s.push()
s.translate(this.x + this.w / 2, this.y + this.w / 2)
if(this.isAnimated) {
s.rotate((ease(linearstep(t, .05, .2), 2) + ease(linearstep(t, .55, .7), 2)) * s.PI/2)
}
else {
s.rotate((ease(linearstep(t, .3, .45), 2) + ease(linearstep(t, .8, .95), 2)) * s.PI/2)
}
s.noStroke()
s.fill(this.c1)
s.rectMode(s.CENTER)
s.rect(0, 0, this.w, this.w)
s.circle(-this.w / 2, -this.w / 2, this.w / 3 * 2)
s.circle(this.w / 2, -this.w / 2, this.w / 3 * 2)
s.circle(this.w / 2, this.w / 2, this.w / 3 * 2)
s.circle(-this.w / 2, this.w / 2, this.w / 3 * 2)
s.rotate(this.angle)
s.noFill()
s.stroke(this.c2)
s.strokeWeight(this.w / 3)
s.strokeCap(s.ROUND)
s.arc(-this.w / 2, -this.w / 2, this.w, this.w, 0, s.PI/2)
s.arc(this.w / 2, this.w / 2, this.w, this.w, s.PI, s.PI*3/2)
s.pop()
}
}