cleari()
originBottomLeft()
class Sketch {
var t = 0.0
var robotX = 50.0 // Starting position on the left
val targetX = cwidth / 2 // Center of the screen
var bob = 0.0
var handshakeAngle = 0.0
def setup(c: CanvasDraw): Unit = {
c.background(230, 242, 250)
}
def drawBackground(c: CanvasDraw): Unit = {
c.background(230, 242, 250)
c.noStroke()
c.fill(60, 140, 90)
c.rect(0, 0, cwidth, 45)
// Grid lines
c.stroke(200, 215, 230)
c.strokeWeight(1)
for (i <- 0 until cwidth.toInt by 40) {
c.line(i, 45, i, cheight)
}
}
def drawRobot(c: CanvasDraw): Unit = {
val x = robotX
val y = 140.0 + bob
// Robot Shadow
c.noStroke()
c.fill(0, 0, 0, 35)
c.ellipse(x, 38, 70, 12)
// Legs
c.stroke(160, 180, 200)
c.strokeWeight(10)
c.line(x - 14, y - 15, x - 14, y - 45)
c.line(x + 14, y - 15, x + 14, y - 45)
// Feet
c.fill(50, 70, 90)
c.stroke(30, 45, 60)
c.strokeWeight(2)
c.ellipse(x - 14, y - 49, 24, 11)
c.ellipse(x + 14, y - 49, 24, 11)
// Left Arm
c.stroke(190, 210, 225)
c.strokeWeight(9)
c.line(x - 28, y + 30, x - 48, y + 10)
c.fill(50, 160, 210)
c.stroke(30, 60, 80)
c.ellipse(x - 48, y + 10, 14, 14)
// Right Handshaking Arm (active when stopped in the center)
val handRaise = math.sin(handshakeAngle) * 12.0
c.stroke(190, 210, 225)
c.strokeWeight(9)
c.line(x + 28, y + 30, x + 55, y + 20 + handRaise)
c.fill(50, 160, 210)
c.stroke(30, 60, 80)
c.strokeWeight(2)
c.ellipse(x + 58, y + 20 + handRaise, 16, 16)
// Main Body (Torso)
c.fill(90, 150, 200)
c.stroke(40, 60, 80)
c.strokeWeight(2.5)
c.rect(x - 32, y - 15, 64, 55)
// Chest Screen (Heartbeat Monitor)
c.fill(215, 215, 220)
c.stroke(50, 70, 90)
c.rect(x - 24, y + 2, 48, 30)
// ECG Line
c.stroke(180, 30, 30)
c.strokeWeight(2)
c.line(x - 20, y + 17, x - 10, y + 17)
c.line(x - 10, y + 17, x - 6, y + 7)
c.line(x - 6, y + 7, x - 2, y + 27)
c.line(x - 2, y + 27, x + 3, y + 12)
c.line(x + 3, y + 12, x + 8, y + 17)
c.line(x + 8, y + 17, x + 20, y + 17)
// Neck & Head
c.fill(100, 115, 130)
c.noStroke()
c.rect(x - 7, y + 40, 14, 8)
val hy = y + 68
c.fill(90, 150, 200)
c.stroke(40, 60, 80)
c.strokeWeight(2.5)
c.rect(x - 34, hy - 16, 68, 40)
// Ears / Antennas
c.fill(40, 60, 80)
c.ellipse(x - 37, hy + 4, 8, 14)
c.ellipse(x + 37, hy + 4, 8, 14)
// Eyes
c.fill(40, 10, 10)
c.stroke(20, 0, 0)
c.ellipse(x - 14, hy + 4, 12, 12)
c.ellipse(x + 14, hy + 4, 12, 12)
c.fill(255, 60, 60)
c.noStroke()
c.ellipse(x - 14, hy + 4, 5, 5)
c.ellipse(x + 14, hy + 4, 5, 5)
// Mouth Grill
c.stroke(40, 60, 80)
c.strokeWeight(1.5)
c.fill(40, 60, 80)
c.rect(x - 16, hy - 10, 32, 8)
c.stroke(200, 220, 240)
for (i <- -10 until 12 by 6) {
c.line(x + i, hy - 10, x + i, hy - 2)
}
// Top Antenna
c.stroke(60, 80, 100)
c.strokeWeight(2)
c.line(x, hy + 24, x, hy + 36)
c.fill(255, 80, 80)
c.noStroke()
c.ellipse(x, hy + 39, 8, 8)
}
// Animation Loop updating movement and handshake
def Loop_legend1404(c: CanvasDraw): Unit = {
t += 0.05
bob = math.sin(t * 3) * 2.5
// Move from left towards the center
if (robotX < targetX) {
robotX += 1.5 // Walking speed towards center
} else {
// Reached center, trigger handshake motion
handshakeAngle += 0.2
}
drawBackground(c)
drawRobot(c)
c.noStroke()
c.fill(30, 80, 120)
val statusText = if (robotX < targetX) "Robot Walking to Center..." else "Loop_legend1404: Handshaking in Center!"
c.text(statusText, 25, cheight - 30)
}
def drawLoop(c: CanvasDraw): Unit = {
Loop_legend1404(c)
}
} //> class Sketch
val sketch = new Sketch //> val sketch: Sketch = Sketch@2226c754
canvasSketch(sketch)
val score = MusicScore(
Melody("Acoustic_Grand", " A B C D G C6h A G B D C C6h "),
Rhythm("Acoustic_Bass_Drum", "q", "o.o.o.o.o.o.o.o")
) //> val score: net.kogics.kojo.core.Score = Score(ArraySeq(Melody(Acoustic_Grand, A B C D G C6h A G B D C C6h ), Rhythm(Acoustic_Bass_Drum,q,o.o.o.o.o.o.o.o)))
playMusic(score)