// Sketch: A Simple Robot // By: Deepak Kumar // Date: September 19, 2022
void setup() { size(800, 800); background(255); } // setup()
void draw() { drawRobot(150, 200, 150); } /// draw()
void drawRobot(float x, float y, float sz) { float h = 0.6 * sz, w = sz; // Draw Face noFill(); rect(x, y, w, h); // Draw Ears float earH = h/2, earW = w * 0.1; fill(100); rect(x-earW, y+h/4.0, earW, earH); rect(x+w, y+h/4.0, earW, earH); // Draw Eyes float eyeW = 0.4*h; float eyeX = x+w*0.25; float eyeY = y + 0.3*h; noFill(); circle(eyeX, eyeY, eyeW); fill(0); circle(eyeX, eyeY, eyeW*0.5); noFill(); circle(eyeX+w*0.5, eyeY, eyeW); fill(0); circle(eyeX+w*0.5, eyeY, eyeW*0.5); // Draw Mouth noFill();
float mouthY = y + 0.6*h; float mouthW = w*0.5, mouthH = h*0.25; float mouthX = x + mouthW/2; fill(200); rect(mouthX, mouthY, mouthW, mouthH); // Teeth line(mouthX+mouthW/4, mouthY, mouthX+mouthW/4, mouthY+mouthH); line(mouthX+mouthW/2, mouthY, mouthX+mouthW/2, mouthY+mouthH); line(mouthX+mouthW*0.75, mouthY, mouthX+mouthW*0.75, mouthY+mouthH); // Draw Antenna float antennaH = h*0.4; line(x+w/2, y, x+w/2, y-antennaH); fill(0); circle(x+w/2.0, y-antennaH, 0.1*w); // Draw base fill(0); float baseW = w/2, baseH = h * 0.1; rect(x+w/4, y+h, baseW, baseH); } // drawRobot
void mousePressed() { drawRobot(mouseX, mouseY, random(100, 250)); } // mousePressed()