xxxxxxxxxx
70
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
translate(x, y)
// Change size base of mouse press
if (mouseIsPressed)
scale(1)
else
scale(.6)
let neckY = - bodyHeight - neckHeight - radius
// Start drawing
background(204)
// Neck
stroke(102)
line( 2, -bodyHeight, 2, neckY)
line(12, -bodyHeight, 12, neckY)
line(22, -bodyHeight, 22, neckY)
// Body
noStroke()
fill(102)
circle(0, -33, 33)
fill(0)
rect(-45, -bodyHeight, 90, bodyHeight-33)
fill(102)
rect(-45, -bodyHeight+17, 90, 6)
// Hair
push()
translate(12, neckY)
let angle = -PI/30
stroke(102)
for (let i = 0; i <= 30; i++) {
line(80, 0, 0, 0)
rotate(angle)
}
pop()
// Head
fill(0)
circle(12, neckY, radius)
fill(255)
circle(24, neckY-6, 14)
fill(0)
circle(24, neckY-6, 3)
fill(153)
circle(0, neckY-8, 5)
circle(30, neckY-26, 4)
circle(41, neckY+6, 3)
}