Code Sketch
samarth pandit
Category: Art
import scala.math._
cleari()
originBottomLeft()
class NeuralRobot {
// ==========================================================
// NEURAL CORE 3.0 ? ANIMATION ENGINE
// ==========================================================
var time = 0.0
var frame = 0
var headAngle = 0.0
var bodyFloat = 0.0
var eyePulse = 0.0
var reactorPulse = 0.0
var radarAngle = 0.0
var scanPosition = 0.0
var mouseTargetX = 0.0
var mouseTargetY = 0.0
var lookX = 0.0
var lookY = 0.0
var shockwave = 0.0
var shockActive = false
var waving = false
var waveTime = 0.0
var talking = true
var happy = true
val W = cwidth.toDouble
val H = cheight.toDouble
val cx = W / 2.0
val cy = H / 2.0
// ==========================================================
// UTILITIES
// ==========================================================
def clamp(v: Double, lo: Double, hi: Double): Double =
max(lo, min(hi, v))
def pulse(speed: Double, phase: Double = 0.0): Double =
(sin(time * speed + phase) + 1.0) / 2.0
def alpha(v: Double): Int =
clamp(v, 0.0, 255.0).toInt
def setup(c: CanvasDraw): Unit = {
c.background(3, 9, 22)
}
// ==========================================================
// CYBERPUNK BACKGROUND
// ==========================================================
def drawBackground(c: CanvasDraw): Unit = {
c.background(3, 9, 22)
c.noStroke()
// Ambient energy clouds
for (i <- 0 until 7) {
val x = cx + sin(time * 0.35 + i * 1.7) * W * 0.35
val y = cy + cos(time * 0.27 + i * 2.1) * H * 0.30
val radius = 90.0 + pulse(0.8, i) * 80.0
c.fill(0, 95, 150, 10)
c.ellipse(x, y, radius * 2, radius)
}
// Perspective floor grid
c.stroke(0, 115, 165, 38)
c.strokeWeight(1)
for (i <- 0 until 24) {
val yy = i * H / 24.0
c.line(0, yy, W, yy)
}
for (i <- 0 until 22) {
val xx = i * W / 21.0
c.line(cx, H * 0.40, xx, 0)
}
// Floating data particles
c.noStroke()
for (i <- 0 until 85) {
val px =
((i * 137.0 + time * (12 + i % 7)) % W)
val py =
((i * 83.0 + time * (7 + i % 5)) % H)
val r =
1.0 + pulse(2.0, i * 0.7) * 2.0
c.fill(
20,
180 + (pulse(1.0, i) * 60).toInt,
255,
alpha(35 + pulse(2.0, i) * 100)
)
c.ellipse(px, py, r, r)
}
}
// ==========================================================
// HOLOGRAPHIC RADAR
// ==========================================================
def drawRadar(c: CanvasDraw): Unit = {
val rx = W - 100.0
val ry = H - 100.0
c.noFill()
for (i <- 1 to 4) {
c.stroke(0, 180, 225, 75 - i * 8)
c.strokeWeight(1)
c.ellipse(rx, ry, i * 28.0, i * 28.0)
}
// Radar crosshair
c.stroke(0, 180, 220, 100)
c.line(rx - 60, ry, rx + 60, ry)
c.line(rx, ry - 60, rx, ry + 60)
// Rotating radar sweep
val ex = rx + cos(radarAngle) * 57
val ey = ry + sin(radarAngle) * 57
c.stroke(30, 245, 255, 220)
c.strokeWeight(2)
c.line(rx, ry, ex, ey)
// Radar targets
for (i <- 0 until 5) {
val a = i * 1.256 + 0.6
val d = 15.0 + i * 8.0
c.noStroke()
c.fill(0, 255, 210, alpha(80 + pulse(3, i) * 170))
c.ellipse(
rx + cos(a) * d,
ry + sin(a) * d,
4,
4
)
}
c.fill(80, 220, 255)
c.text("NEURAL RADAR", rx - 42, ry - 76)
}
// ==========================================================
// HOLOGRAPHIC ENERGY RINGS
// ==========================================================
def drawEnergyRings(c: CanvasDraw): Unit = {
val x = cx
val y = cy - 15 + bodyFloat
c.noFill()
// Main outer rings
for (i <- 0 until 4) {
val r = 95.0 + i * 13.0 + pulse(1.5, i) * 5.0
c.stroke(
0,
190 + i * 12,
255,
alpha(55 + pulse(2.0, i) * 75)
)
c.strokeWeight(if (i == 0) 2.5 else 1.0)
c.ellipse(x, y, r * 2, r * 1.4)
}
// Orbiting energy nodes
for (i <- 0 until 8) {
val a = time * 1.1 + i * Pi / 4.0
val r = 115.0
val px = x + cos(a) * r
val py = y + sin(a) * r * 0.70
c.noStroke()
c.fill(0, 235, 255, alpha(100 + pulse(4, i) * 155))
c.ellipse(px, py, 5, 5)
c.fill(0, 160, 255, 35)
c.ellipse(px, py, 13, 13)
}
}
// ==========================================================
// ROBOT BODY ? ARMOR SYSTEM
// ==========================================================
def drawBody(c: CanvasDraw): Unit = {
val x = cx
val y = cy - 38 + bodyFloat
// Shadow
c.noStroke()
c.fill(0, 0, 0, 90)
c.ellipse(x, y - 94, 150, 24)
// Torso armor
c.fill(23, 44, 65)
c.stroke(45, 190, 225)
c.strokeWeight(2)
c.ellipse(x, y - 25, 112, 112)
// Inner armor
c.fill(205, 223, 235)
c.stroke(100, 160, 190)
c.strokeWeight(2)
c.ellipse(x, y - 20, 86, 90)
// Chest panel
c.fill(15, 42, 62)
c.stroke(0, 220, 255)
c.strokeWeight(2)
c.rect(x - 31, y - 48, 62, 42)
// Reactor glow
val energy = alpha(100 + pulse(4.0) * 140)
c.noStroke()
c.fill(0, 180, 255, 30)
c.ellipse(x, y - 27, 66, 66)
c.fill(0, 220, 255, energy)
c.ellipse(x, y - 27, 31, 31)
c.fill(200, 255, 255, 240)
c.ellipse(x, y - 27, 12, 12)
// Reactor center
c.fill(255, 255, 255, alpha(160 + pulse(5) * 95))
c.ellipse(x, y - 27, 5, 5)
// Shoulder armor
c.fill(35, 100, 135)
c.stroke(0, 220, 255)
c.strokeWeight(2)
c.ellipse(x - 53, y + 8, 28, 36)
c.ellipse(x + 53, y + 8, 28, 36)
// Shoulder lights
c.noStroke()
c.fill(0, 240, 255, 210)
c.ellipse(x - 53, y + 8, 7, 7)
c.ellipse(x + 53, y + 8, 7, 7)
}
// ==========================================================
// ARTICULATED ARMS
// ==========================================================
def drawArms(c: CanvasDraw): Unit = {
val x = cx
val y = cy - 38 + bodyFloat
val waveAngle =
if (waving) sin(waveTime * 8) * 0.8 else 0.0
// Left upper arm
c.stroke(180, 205, 220)
c.strokeWeight(12)
c.line(x - 50, y + 8, x - 72, y - 10)
// Left elbow
c.fill(25, 110, 150)
c.stroke(0, 220, 255)
c.strokeWeight(2)
c.ellipse(x - 72, y - 10, 19, 19)
// Left forearm
c.stroke(205, 220, 230)
c.strokeWeight(9)
c.line(x - 72, y - 10, x - 78, y - 37)
c.fill(210, 225, 235)
c.noStroke()
c.ellipse(x - 78, y - 39, 17, 17)
// Right upper arm
c.stroke(180, 205, 220)
c.strokeWeight(12)
c.line(x + 50, y + 8, x + 73, y - 9)
// Right elbow
c.fill(25, 110, 150)
c.stroke(0, 220, 255)
c.strokeWeight(2)
c.ellipse(x + 73, y - 9, 19, 19)
// Animated right forearm
val hx = x + 80 + sin(waveAngle) * 9
val hy = y - 34 + sin(waveAngle) * 18
c.stroke(205, 220, 230)
c.strokeWeight(9)
c.line(x + 73, y - 9, hx, hy)
// Hand
c.fill(215, 230, 240)
c.stroke(0, 200, 245)
c.strokeWeight(1.5)
c.ellipse(hx, hy - 5, 18, 20)
// Fingers
c.stroke(0, 210, 245)
c.strokeWeight(2)
for (i <- 0 until 3) {
c.line(
hx + 5,
hy - 5 + i * 4,
hx + 12,
hy - 3 + i * 4
)
}
}
// ==========================================================
// AI HEAD ? EXPRESSIVE FACE
// ==========================================================
def drawHead(c: CanvasDraw): Unit = {
val hx = cx + headAngle
val hy = cy + 57 + bodyFloat
// Antenna
c.stroke(110, 165, 195)
c.strokeWeight(3)
c.line(hx, hy + 34, hx, hy + 53)
c.noStroke()
c.fill(0, 220, 255, alpha(100 + pulse(5) * 155))
c.ellipse(hx, hy + 57, 12, 12)
// Ears
c.fill(25, 65, 90)
c.stroke(0, 210, 245)
c.strokeWeight(2)
c.ellipse(hx - 45, hy, 15, 27)
c.ellipse(hx + 45, hy, 15, 27)
// Main head armor
c.fill(195, 215, 230)
c.stroke(80, 180, 220)
c.strokeWeight(2.5)
c.rect(hx - 41, hy - 31, 82, 63)
// Face visor
c.fill(5, 20, 38)
c.stroke(0, 220, 255)
c.strokeWeight(2)
c.rect(hx - 33, hy - 19, 66, 37)
// Eye blink
val blink = sin(eyePulse) > 0.985
val eyeHeight = if (blink) 2.0 else 11.0
// Eye glow
c.noStroke()
c.fill(0, 190, 255, 40)
c.ellipse(hx - 16 + lookX, hy + 1 + lookY, 23, 23)
c.ellipse(hx + 16 + lookX, hy + 1 + lookY, 23, 23)
// Eye cores
c.fill(65, 240, 255, 245)
c.ellipse(
hx - 16 + lookX,
hy + 1 + lookY,
8,
eyeHeight
)
c.ellipse(
hx + 16 + lookX,
hy + 1 + lookY,
8,
eyeHeight
)
// Mouth animation
c.stroke(0, 230, 255)
c.strokeWeight(2)
if (talking) {
val mouth = 3.0 + abs(sin(time * 9)) * 8
c.noFill()
c.ellipse(hx, hy - 11, 14, mouth)
} else if (happy) {
c.noFill()
c.arc(hx, hy - 5, 19, 12, Pi, 2 * Pi)
} else {
c.line(hx - 7, hy - 11, hx + 7, hy - 11)
}
// Forehead indicator
c.noStroke()
c.fill(0, 230, 255, alpha(120 + pulse(3) * 135))
c.ellipse(hx, hy + 25, 7, 4)
// Face side lights
c.fill(0, 210, 255, 170)
c.ellipse(hx - 37, hy - 4, 3, 12)
c.ellipse(hx + 37, hy - 4, 3, 12)
}
// ==========================================================
// HOLOGRAPHIC SCAN BEAM
// ==========================================================
def drawScanBeam(c: CanvasDraw): Unit = {
val left = cx - 165
val right = cx + 165
val bottom = cy - 5
val top = cy + 155
val yy = bottom + scanPosition
c.stroke(0, 230, 255, 100)
c.strokeWeight(2)
c.line(left, yy, right, yy)
c.stroke(0, 220, 255, 25)
c.strokeWeight(9)
c.line(left, yy, right, yy)
c.noFill()
c.stroke(0, 150, 210, 75)
c.strokeWeight(1)
c.rect(left, bottom, right - left, top - bottom)
}
// ==========================================================
// DIGITAL TELEMETRY
// ==========================================================
def drawTelemetry(c: CanvasDraw): Unit = {
c.fill(0, 225, 255)
c.noStroke()
c.text("N E U R A L C O R E // 03", 24, H - 35)
c.fill(120, 200, 225)
c.text("AI STATUS : ONLINE", 24, H - 58)
c.text(
"ENERGY : " + (85 + pulse(1.4) * 14).toInt + "%",
24,
H - 78
)
c.text(
"FRAME : " + frame,
24,
H - 98
)
c.text(
"NEURAL SYNC : " + (90 + pulse(2.0) * 9).toInt + "%",
24,
H - 118
)
// Energy bars
for (i <- 0 until 18) {
val active = pulse(2.0, i * 0.25) > 0.25
if (active) c.fill(0, 220, 255)
else c.fill(20, 65, 90)
c.rect(24 + i * 11, 22, 7, 4 + (i % 4) * 2)
}
c.fill(80, 200, 235)
c.text("TOUCH TO ACTIVATE NEURAL RESPONSE", cx - 112, 12)
}
// ==========================================================
// TOUCH SHOCKWAVE
// ==========================================================
def drawShockwave(c: CanvasDraw): Unit = {
if (shockActive) {
c.noFill()
for (i <- 0 until 4) {
val r = shockwave - i * 13
if (r > 0) {
c.stroke(
0,
225,
255,
alpha(210 - r * 0.5)
)
c.strokeWeight(2)
c.ellipse(
mouseTargetX,
mouseTargetY,
r * 2,
r * 2
)
}
}
shockwave += 4
if (shockwave > 110) {
shockActive = false
shockwave = 0
}
}
}
// ==========================================================
// ANIMATION UPDATE
// ==========================================================
def update(): Unit = {
time += 0.035
frame += 1
eyePulse += 0.035
reactorPulse += 0.07
radarAngle += 0.035
scanPosition += 1.8
if (scanPosition > 160) scanPosition = 0
// Smooth procedural body motion
bodyFloat = sin(time * 2.0) * 3.0
// Head follows target
val desiredHead =
clamp((mouseTargetX - cx) * 0.025, -12, 12)
headAngle += (desiredHead - headAngle) * 0.06
// Smooth eye tracking
lookX = clamp((mouseTargetX - cx) * 0.025, -5, 5)
lookY = clamp((mouseTargetY - cy) * 0.025, -4, 4)
if (waving) {
waveTime += 0.06
if (waveTime > 6.0) {
waving = false
waveTime = 0
}
}
}
// ==========================================================
// MAIN RENDER PIPELINE
// ==========================================================
def drawLoop(c: CanvasDraw): Unit = {
update()
drawBackground(c)
drawEnergyRings(c)
drawBody(c)
drawArms(c)
drawHead(c)
drawScanBeam(c)
drawRadar(c)
drawShockwave(c)
drawTelemetry(c)
// Mouse interaction
if (isMousePressed) {
mouseTargetX = clamp(mouseX.toDouble, 0, W)
mouseTargetY = clamp(mouseY.toDouble, 0, H)
shockActive = true
shockwave = 8
waving = true
waveTime = 0
talking = !talking
happy = true
}
}
}
// ============================================================
// BOOT NEURAL CORE
// ============================================================
val ai = new NeuralRobot
canvasSketch(ai)