Code Sketch
samarth pandit
Category: Art
clear()
cleari()
originBottomLeft()
class Sketch {
var t = 0.0
var blink = 0.0
var pulse = 0.0
var wave = 0.0
def setup(c: CanvasDraw): Unit = {
c.background(5, 10, 30)
}
// BACKGROUND
def drawBackground(c: CanvasDraw): Unit = {
c.background(5, 10, 30)
c.fill(10, 25, 50)
c.noStroke()
c.rect(0, 0, cwidth, 70)
// Floor grid
c.stroke(0, 120, 200, 100)
c.strokeWeight(1)
for (i <- 0 until 15) {
val x = i * cwidth / 14.0
c.line(x, 0, cwidth / 2.0, 100)
}
for (i <- 0 until 5) {
val y = 12.0 + i * 12
c.line(0, y, cwidth, y)
}
// Floating particles
for (i <- 0 until 35) {
val x = ((i * 79) % cwidth).toDouble
val y = 90.0 + ((i * 53) % (cheight - 110))
val glow = (120 + 100 * math.sin(t * 2 + i)).toInt
c.fill(0, 200, 255, glow)
c.noStroke()
c.ellipse(x, y, 3, 3)
}
}
// CYBER LAB
def drawLab(c: CanvasDraw): Unit = {
val cx = cwidth / 2.0
// Holographic rings
c.noFill()
c.stroke(0, 180, 255, 90)
c.strokeWeight(2)
c.ellipse(cx, 180, 300, 300)
c.ellipse(cx, 180, 250, 250)
c.ellipse(cx, 180, 200, 200)
// Side panels
c.fill(10, 30, 55)
c.stroke(0, 180, 255)
c.strokeWeight(2)
c.rect(30, 130, 75, 190)
c.rect(cwidth - 105, 130, 75, 190)
// Panel lights
for (i <- 0 until 7) {
val y = 150 + i * 22
c.fill(0, 200, 255, 180)
c.noStroke()
c.rect(42, y, 50, 4)
c.fill(0, 255, 170, 180)
c.rect(cwidth - 93, y, 50, 4)
}
}
// AI ROBOT
def drawRobot(c: CanvasDraw): Unit = {
val x = cwidth / 2.0
val bob = math.sin(t * 2) * 3
val y = 190 + bob
val energy = (160 + 80 * math.sin(pulse)).toInt
// Shadow
c.fill(0, 0, 0, 100)
c.noStroke()
c.ellipse(x, 75, 145, 25)
// Legs
c.fill(130, 150, 175)
c.stroke(0, 200, 255)
c.strokeWeight(2)
c.rect(x - 38, y - 65, 25, 45)
c.rect(x + 13, y - 65, 25, 45)
// Feet
c.fill(35, 65, 90)
c.rect(x - 45, y - 75, 40, 12)
c.rect(x + 5, y - 75, 40, 12)
// Body
c.fill(180, 200, 220)
c.stroke(0, 220, 255)
c.strokeWeight(3)
c.rect(x - 52, y - 20, 104, 85)
// Chest armor
c.fill(15, 45, 70)
c.rect(x - 38, y - 5, 76, 53)
// Energy core
c.fill(0, 180, 255, energy)
c.ellipse(x, y + 22, 34, 34)
c.fill(180, 255, 255)
c.ellipse(x, y + 22, 14, 14)
// Chest label
c.fill(0, 230, 255)
c.text("A I", x - 8, y - 18)
// Animated arms
val armSwing = math.sin(wave) * 12
c.stroke(170, 195, 215)
c.strokeWeight(12)
c.line(x - 52, y + 48, x - 77, y + 12 + armSwing)
c.line(x + 52, y + 48, x + 77, y + 12 - armSwing)
// Hands
c.fill(100, 180, 210)
c.stroke(0, 220, 255)
c.strokeWeight(2)
c.ellipse(x - 77, y + 8 + armSwing, 23, 23)
c.ellipse(x + 77, y + 8 - armSwing, 23, 23)
// Head
val hy = y + 95
c.fill(185, 205, 225)
c.stroke(0, 220, 255)
c.strokeWeight(3)
c.rect(x - 42, hy - 27, 84, 58)
// Side ears
c.fill(40, 90, 120)
c.ellipse(x - 47, hy, 12, 25)
c.ellipse(x + 47, hy, 12, 25)
// Visor
c.fill(5, 20, 40)
c.stroke(0, 180, 255)
c.rect(x - 33, hy - 12, 66, 29)
// Blinking eyes
val eyeHeight =
if (math.sin(blink) > 0.97) 2.0 else 10.0
c.fill(0, 240, 255)
c.noStroke()
c.ellipse(x - 16, hy + 2, 10, eyeHeight)
c.ellipse(x + 16, hy + 2, 10, eyeHeight)
// Antenna
c.stroke(0, 200, 255)
c.strokeWeight(3)
c.line(x, hy + 31, x, hy + 45)
c.fill(0, 255, 180, energy)
c.noStroke()
c.ellipse(x, hy + 50, 12, 12)
// Head indicator
c.fill(0, 255, 200)
c.text("AI-01", x - 16, hy - 20)
}
// SPEECH PANEL
def drawSpeech(c: CanvasDraw): Unit = {
val x = cwidth / 2.0 + 115
val y = 320.0
c.fill(10, 35, 60, 235)
c.stroke(0, 220, 255)
c.strokeWeight(2)
c.rect(x, y, 155, 70)
c.fill(0, 255, 200)
c.noStroke()
c.text("SYSTEM ONLINE", x + 12, y + 48)
c.fill(220, 245, 255)
c.text("HELLO, HUMAN!", x + 12, y + 30)
c.fill(0, 200, 255)
c.text("POWER: 100%", x + 12, y + 13)
}
// STATUS DISPLAY
def drawStatus(c: CanvasDraw): Unit = {
c.fill(0, 230, 255)
c.noStroke()
c.text("CYBER LAB // AI ROBOT", 25, cheight - 30)
c.fill(180, 220, 255)
c.text("NEURAL CORE ACTIVE", 25, cheight - 50)
c.fill(0, 255, 180)
c.text("SYSTEM: ONLINE", cwidth - 155, cheight - 30)
}
// ANIMATION LOOP
def drawLoop(c: CanvasDraw): Unit = {
t += 0.04
blink += 0.035
pulse += 0.08
wave += 0.12
drawBackground(c)
drawLab(c)
drawRobot(c)
drawSpeech(c)
drawStatus(c)
}
}
// START ANIMATION
val sketch = new Sketch
canvasSketch(sketch)