xxxxxxxxxx
51
class Eye extends NoisyCircle{
constructor(x, y, sz, col){
super()
this.col = col.concat([random(50,250)])
this.parentX = x
this.parentY = y
this.parentSz = sz
this.sz = sz/random(4.0,7.0)
this.initSz = this.sz
this.szInc = random(-0.2, 0.2)
this.offSetX = random(-this.parentSz/4, this.parentSz/4)
this.offSetY = random(-this.parentSz/4, this.parentSz/4)
this.x = this.parentX + this.offSetX
this.y = this.parentY + this.offSetY
this.points = this.getPoints()
this.pupil = new Pupil(this.x, this.y, this.sz/10, 'yellow')
}
render(){
fill(this.col)
stroke(200, 200, 200)
strokeWeight(1)
//circle(this.x, this.y, this.sz)
beginShape()
this.points.forEach(pt => vertex(pt.x, pt.y))
endShape(CLOSE)
this.pupil.render()
}
update(x, y){
this.parentX = x
this.parentY = y
this.x = this.parentX + this.offSetX
this.y = this.parentY + this.offSetY
if(this.sz < -30 || this.sz > this.initSz * 2){
this.szInc *= -1
}
this.sz += this.szInc
this.updatePoints()
this.pupil.update(this.x, this.y)
}
}