xxxxxxxxxx
65
let x = 160, y = 390
let bodyHeight = 160
let neckHeight = 70
let radius = 45
let easing = 0.04
function setup() {
createCanvas(720, 480)
strokeWeight(2)
ellipseMode(RADIUS) // spcify radiud rather than width
}
function draw() {
// Interactive robot location and size
// Update x position with easing
x += (mouseX - x) * easing
// Change size base of mouse press
if (mouseIsPressed) {
neckHeight = 16
bodyHeight = 90
} else {
neckHeight = 70
bodyHeight = 160
}
let neckY = y - bodyHeight - neckHeight - radius
// Start drawing
background(204)
// Neck
stroke(102)
line(x+ 2, y-bodyHeight, x+ 2, neckY)
line(x+12, y-bodyHeight, x+12, neckY)
line(x+22, y-bodyHeight, x+22, neckY)
// Antennae
line(x+12, neckY, x-18, neckY-43)
line(x+12, neckY, x+42, neckY-99)
line(x+12, neckY, x+78, neckY+15)
// Body
noStroke()
fill(102)
circle(x, y-33, 33)
fill(0)
rect(x-45, y-bodyHeight, 90, bodyHeight-33)
fill(102)
rect(x-45, y-bodyHeight+17, 90, 6)
// Head
fill(0)
circle(x+12, neckY, radius)
fill(255)
circle(x+24, neckY-6, 14)
fill(0)
circle(x+24, neckY-6, 3)
fill(153)
circle(x, neckY-8, 5)
circle(x+30, neckY-26, 4)
circle(x+41, neckY+6, 3)
}