Code Sketch


Harshwardhan Dube
By: Mhalsakant School
Category: Art
clear()
cleari()
originBottomLeft()

class Sketch {

  var t = 0.0
  var bob = 0.0
  var pulse = 0.0

  def setup(c: CanvasDraw): Unit = {
    c.background(5, 10, 25)
  }

  def drawBackground(c: CanvasDraw): Unit = {
    c.background(5, 10, 25)

    for (i <- 0 until 35) {
      val x = ((i * 97) % cwidth).toDouble
      val y = ((i * 67) % cheight).toDouble

      c.noStroke()
      c.fill(0, 180, 255, 180)
      c.ellipse(x, y, 3, 3)
    }
  }

  def drawRobot(c: CanvasDraw): Unit = {
    val x = cwidth / 2.0
    val y = 180.0 + bob

    // Legs
    c.stroke(150, 190, 210)
    c.strokeWeight(10)

    c.line(x - 20, y - 35, x - 25, y - 65)
    c.line(x + 20, y - 35, x + 25, y - 65)

    // Feet
    c.fill(20, 80, 110)
    c.stroke(0, 220, 255)
    c.strokeWeight(2)

    c.rect(x - 40, y - 75, 28, 12)
    c.rect(x + 12, y - 75, 28, 12)

    // Body
    c.fill(35, 65, 90)
    c.stroke(0, 220, 255)
    c.strokeWeight(3)

    c.ellipse(x, y, 85, 90)

    // Neck
    c.rect(x - 12, y + 35, 24, 15)

    // Chest core
    val glow = (100.0 + math.abs(math.sin(pulse)) * 155.0).toInt

    c.noStroke()
    c.fill(0, 220, 255, glow)
    c.ellipse(x, y, 30, 30)

    c.fill(230, 255, 255)
    c.ellipse(x, y, 12, 12)

    // Arms
    c.stroke(160, 190, 210)
    c.strokeWeight(10)

    c.line(x - 40, y + 20, x - 65, y)
    c.line(x + 40, y + 20, x + 65, y)

    // Head
    c.fill(35, 65, 90)
    c.stroke(0, 220, 255)
    c.strokeWeight(3)

    c.rect(x - 45, y + 55, 90, 65)

    // Face screen
    c.fill(2, 15, 30)
    c.noStroke()

    c.rect(x - 36, y + 64, 72, 45)

    // Eyes
    val eye = 7.0 + math.sin(pulse) * 2.0

    c.fill(0, 255, 255)
    c.ellipse(x - 18, y + 91, 10, eye)
    c.ellipse(x + 18, y + 91, 10, eye)

    // Mouth
    c.stroke(0, 220, 255)
    c.strokeWeight(2)

    c.line(x - 10, y + 73, x + 10, y + 73)

    // Antenna
    c.line(x, y + 120, x, y + 140)

    c.noStroke()
    c.fill(0, 255, 255)
    c.ellipse(x, y + 143, 9, 9)

    // Energy ring
    c.noFill()
    c.stroke(0, 220, 255, 150)
    c.strokeWeight(2)

    c.ellipse(x, y - 15, 125, 25)
    c.ellipse(x, y - 15, 155, 35)
  }

  def drawStatus(c: CanvasDraw): Unit = {
    c.noStroke()
    c.fill(0, 230, 255)

    c.text("CYBER AI ROBOT", 20, cheight - 25)

    c.fill(120, 220, 255)
    c.text("SYSTEM ONLINE", 20, cheight - 45)
  }

  def drawLoop(c: CanvasDraw): Unit = {
    t += 0.04
    bob = math.sin(t * 2.0) * 3.0
    pulse += 0.12

    drawBackground(c)
    drawRobot(c)
    drawStatus(c)
  }
}

val sketch = new Sketch
canvasSketch(sketch)