Code Sketch
SIDDHI SABALE
Category: Programming
cleari()
originBottomLeft()
// ============================================================
// ISRO SPACE MISSION - SATELLITE REPAIR ROBOT EDITION
// Zero Gravity Floating, Laser Welding, Sparks & Earth View
// ============================================================
var robotX = 260.0
var robotY = 200.0
var robotTime = 0.0
var robotGlow = 0.0
var floatBob = 0.0
// ------------------------------------------------------------
// Repair Work States (?????????? ?????)
// 0: Positioning (??????), 1: Welding (???????? ????), 2: Diagnostic Scan (??????)
// ------------------------------------------------------------
var robotState = 1
var stateTimer = 0.0
// ------------------------------------------------------------
// Sparks Array for Welding Effect (???????????? ???????)
// ------------------------------------------------------------
val sparkCount = 30
val sparkX = Array.fill(sparkCount)(0.0)
val sparkY = Array.fill(sparkCount)(0.0)
val sparkVX = Array.fill(sparkCount)(0.0)
val sparkVY = Array.fill(sparkCount)(0.0)
val sparkLife = Array.fill(sparkCount)(0.0)
// Initializing Sparks
for (i <- 0 until sparkCount) {
sparkLife(i) = 0.0
}
// ------------------------------------------------------------
// Background Stars
// ------------------------------------------------------------
val starCount = 80
val starX = Array.fill(starCount)(randomDouble(0, cwidth))
val starY = Array.fill(starCount)(randomDouble(0, cheight))
// ------------------------------------------------------------
// Robot Colors
// ------------------------------------------------------------
val whiteRobot = cm.rgb(245, 248, 250)
val whiteShadow = cm.rgb(190, 200, 205)
val greenMain = cm.rgb(0, 210, 80)
val greenDark = cm.rgb(0, 105, 45)
val greenGlow = cm.rgb(40, 255, 120)
val blackScreen = cm.rgb(5, 8, 18)
// ------------------------------------------------------------
// UPDATE LOGIC (??????? ?????)
// ------------------------------------------------------------
def updateSpaceRobot() {
robotTime += 0.018
robotGlow += 0.08
stateTimer += 0.018
// Space Floating Motion (???? ??????????????? ??????)
floatBob = math.sin(robotTime * 1.8) * 8.0
// ----------------------------------------------------------
// State Machine (?????????? ??? ?????)
// ----------------------------------------------------------
if (robotState == 0) { // POSITIONING
if (stateTimer > 3.0) {
robotState = 1 // Switch to Welding
stateTimer = 0.0
}
} else if (robotState == 1) { // WELDING SATELLITE (???????? ????)
// Sparks Generation (??????? ??????? ????)
val weldTargetX = cwidth - 240
val weldTargetY = cheight / 2 + 10
for (i <- 0 until sparkCount) {
if (sparkLife(i) <= 0) {
sparkX(i) = weldTargetX
sparkY(i) = weldTargetY
sparkVX(i) = randomDouble(-4.0, 4.0)
sparkVY(i) = randomDouble(-3.0, 5.0)
sparkLife(i) = randomDouble(0.3, 0.8)
} else {
sparkX(i) += sparkVX(i)
sparkY(i) += sparkVY(i)
sparkLife(i) -= 0.025
}
}
if (stateTimer > 6.0) {
robotState = 2 // Switch to Scan
stateTimer = 0.0
}
} else if (robotState == 2) { // DIAGNOSTIC SCAN
if (stateTimer > 4.0) {
robotState = 1 // Back to Welding cycle
stateTimer = 0.0
}
}
}
// ============================================================
// DRAW SATELLITE (??????? ????????)
// ============================================================
def drawISROSatellite(canvas: CanvasDraw, sx: Double, sy: Double) {
// Solar Panel Left (Repaired Part)
canvas.fill(20, 80, 180)
canvas.stroke(50, 130, 230)
canvas.strokeWeight(1.5)
canvas.rect(sx - 160, sy - 30, 110, 60)
// Grid Lines on Left Solar Panel
canvas.stroke(100, 170, 255)
canvas.line(sx - 110, sy - 30, sx - 110, sy + 30)
canvas.line(sx - 160, sy, sx - 50, sy)
// Solar Panel Right
canvas.fill(20, 80, 180)
canvas.stroke(50, 130, 230)
canvas.strokeWeight(1.5)
canvas.rect(sx + 50, sy - 30, 110, 60)
canvas.line(sx + 105, sy - 30, sx + 105, sy + 30)
canvas.line(sx + 50, sy, sx + 160, sy)
// Panel Connectors
canvas.stroke(180, 180, 190)
canvas.strokeWeight(3)
canvas.line(sx - 50, sy, sx - 25, sy)
canvas.line(sx + 25, sy, sx + 50, sy)
// Satellite Main Body (Gold Foil Thermal Shielding)
canvas.fill(230, 170, 20)
canvas.stroke(190, 130, 10)
canvas.strokeWeight(2)
canvas.rect(sx - 25, sy - 40, 50, 80)
// Dish Antenna (????? ??????)
canvas.fill(220, 225, 230)
canvas.stroke(160, 165, 170)
canvas.ellipse(sx, sy + 55, 36, 18)
canvas.strokeWeight(2)
canvas.line(sx, sy + 40, sx, sy + 55)
// ISRO Tricolor Logo on Satellite
canvas.fill(255, 153, 51); canvas.noStroke(); canvas.rect(sx - 12, sy + 10, 24, 3)
canvas.fill(255, 255, 255); canvas.rect(sx - 12, sy + 7, 24, 3)
canvas.fill(19, 136, 8); canvas.rect(sx - 12, sy + 4, 24, 3)
// Glowing Thrusters/Sensors
canvas.fill(0, 220, 255, 180)
canvas.ellipse(sx - 20, sy - 42, 6, 6)
canvas.ellipse(sx + 20, sy - 42, 6, 6)
}
// ============================================================
// WELDING LASER & SPARKS (???????? ??????)
// ============================================================
def drawWeldingEffects(canvas: CanvasDraw, rx: Double, ry: Double, sx: Double, sy: Double) {
val weldPointX = sx - 60
val weldPointY = sy + 10
if (robotState == 1) { // Laser Welding State
// Laser Beam (??????? ??????? ?????-???? ???????? ????)
canvas.stroke(255, 220, 50, 230)
canvas.strokeWeight(3.5)
canvas.line(rx + 35, ry + 80, weldPointX, weldPointY)
canvas.stroke(255, 255, 255, 255)
canvas.strokeWeight(1.5)
canvas.line(rx + 35, ry + 80, weldPointX, weldPointY)
// Intense Welding Arc Point (????? ???????? ?????)
canvas.fill(255, 255, 255)
canvas.noStroke()
canvas.ellipse(weldPointX, weldPointY, 12, 12)
canvas.fill(0, 200, 255, 150)
canvas.ellipse(weldPointX, weldPointY, 24, 24)
// Flying Sparks Effect (???????? ???????)
for (i <- 0 until sparkCount) {
if (sparkLife(i) > 0) {
val alpha = (sparkLife(i) * 350).toInt.min(255)
canvas.fill(255, 180, 30, alpha)
canvas.ellipse(sparkX(i), sparkY(i), 3, 3)
}
}
} else if (robotState == 2) { // Diagnostic Scan (????? ??????)
canvas.stroke(0, 255, 120, 180)
canvas.strokeWeight(2)
canvas.line(rx + 35, ry + 80, sx - 100, sy - 30)
canvas.line(rx + 35, ry + 80, sx - 100, sy + 30)
canvas.fill(0, 255, 100, 40)
canvas.noStroke()
canvas.rect(sx - 160, sy - 30, 110, 60)
}
}
// ============================================================
// BACKGROUND: SPACE, STARS & EARTH
// ============================================================
def drawSpaceBackground(canvas: CanvasDraw) {
// Deep Space Dark Background
canvas.fill(5, 8, 18)
canvas.noStroke()
canvas.rect(0, 0, cwidth, cheight)
// Stars
canvas.fill(255, 255, 255)
for (i <- 0 until starCount) {
val twinkle = (math.sin(robotTime * 3.0 + i) * 1.2 + 1.8).toFloat
canvas.ellipse(starX(i), starY(i), twinkle, twinkle)
}
// Planet Earth in Background (??????)
val ex = 110.0
val ey = 90.0
canvas.fill(30, 90, 200, 40); canvas.ellipse(ex, ey, 180, 180) // Atmosphere Glow
canvas.fill(20, 100, 210); canvas.ellipse(ex, ey, 140, 140) // Ocean Body
// Landmasses (Green/Brown Continents)
canvas.fill(40, 160, 80, 200)
canvas.ellipse(ex - 20, ey + 20, 50, 35)
canvas.ellipse(ex + 25, ey - 10, 45, 40)
canvas.ellipse(ex - 10, ey - 30, 35, 25)
// White Cloud Layers
canvas.fill(255, 255, 255, 160)
canvas.ellipse(ex - 15, ey + 10, 60, 15)
canvas.ellipse(ex + 20, ey - 20, 50, 12)
}
// ============================================================
// ROBOT PARTS (ZERO GRAVITY FLOATING ROBOT)
// ============================================================
def drawSpaceRobot(canvas: CanvasDraw, rx: Double, ry: Double) {
// Thruster Jets at Feet (???????? ????? ??????????? ?????????)
val jetGlow = (math.sin(robotTime * 15.0) * 4 + 12).toFloat
canvas.fill(0, 200, 255, 180); canvas.noStroke()
canvas.ellipse(rx - 20, ry - 30, 12, jetGlow)
canvas.ellipse(rx + 20, ry - 30, 12, jetGlow)
// Feet
canvas.fill(whiteRobot); canvas.stroke(whiteShadow); canvas.strokeWeight(2)
canvas.ellipse(rx - 20, ry - 20, 32, 18)
canvas.ellipse(rx + 20, ry - 20, 32, 18)
// Legs
canvas.rect(rx - 28, ry - 10, 16, 40)
canvas.rect(rx + 12, ry - 10, 16, 40)
// Body
canvas.fill(whiteRobot); canvas.stroke(whiteShadow); canvas.strokeWeight(2.5)
canvas.rect(rx - 40, ry + 30, 80, 85)
canvas.fill(greenMain); canvas.noStroke(); canvas.rect(rx - 40, ry + 38, 80, 10)
// Core Reactor
canvas.fill(235, 240, 242); canvas.stroke(180, 190, 195); canvas.strokeWeight(1.5)
canvas.ellipse(rx, ry + 80, 30, 30)
canvas.fill(0, 220, 80); canvas.noStroke()
canvas.ellipse(rx, ry + 80, 14, 14)
// ISRO Logo on Chest
canvas.fill(20, 30, 30); canvas.text("ISRO", rx - 16, ry + 100)
// Left Stabilizer Arm
canvas.fill(whiteRobot); canvas.stroke(whiteShadow); canvas.strokeWeight(2)
canvas.rect(rx - 62, ry + 50, 20, 45)
// Right Repair Arm (Holding Welding Tool - ??????????? ??????? ???)
canvas.pushMatrix()
canvas.translate(rx + 35, ry + 85)
canvas.rotate(-25.0)
canvas.fill(whiteRobot); canvas.stroke(whiteShadow); canvas.strokeWeight(2)
canvas.rect(-8, -40, 16, 42)
// Welding Tool Tip
canvas.fill(greenMain); canvas.rect(-5, -50, 10, 12)
canvas.fill(255, 200, 0); canvas.ellipse(0, -52, 6, 6)
canvas.popMatrix()
// Head & Helmet Visor
val hx = rx
val hy = ry + 130
// Antenna Beacon
canvas.stroke(180, 190, 200); canvas.strokeWeight(2)
canvas.line(hx, hy + 40, hx, hy + 62)
canvas.fill(0, 255, 100); canvas.noStroke(); canvas.ellipse(hx, hy + 62, 8, 8)
// Head Base
canvas.fill(whiteRobot); canvas.stroke(whiteShadow); canvas.strokeWeight(2)
canvas.rect(hx - 36, hy - 5, 72, 50)
// Visor Screen & LED Eyes
canvas.fill(blackScreen); canvas.stroke(20, 40, 50); canvas.strokeWeight(2)
canvas.rect(hx - 28, hy + 5, 56, 32)
canvas.fill(40, 180, 255); canvas.noStroke()
canvas.ellipse(hx - 12, hy + 22, 6, 6)
canvas.ellipse(hx + 12, hy + 22, 6, 6)
}
// ============================================================
// HEADS UP DISPLAY (HUD)
// ============================================================
def drawSpaceHUD(canvas: CanvasDraw) {
canvas.fill(255, 220, 200)
canvas.text("ISRO SATELLITE SERVICING MISSION", 25, cheight - 30)
if (robotState == 1) {
canvas.fill(255, 200, 0)
canvas.text("STATUS : WELDING & REPAIRING SOLAR ARRAY (SPARKS ACTIVE)", 25, cheight - 55)
} else if (robotState == 2) {
canvas.fill(0, 255, 120)
canvas.text("STATUS : RUNNING DIAGNOSTIC SCAN... ALL SYSTEMS OK", 25, cheight - 55)
} else {
canvas.fill(0, 200, 255)
canvas.text("STATUS : POSITIONING IN ZERO-GRAVITY ORBIT", 25, cheight - 55)
}
// Energy Status
canvas.fill(30, 40, 45); canvas.stroke(0, 255, 120); canvas.strokeWeight(2)
canvas.rect(cwidth - 190, cheight - 65, 150, 18)
canvas.fill(0, 230, 90)
canvas.rect(cwidth - 186, cheight - 61, 138, 10)
canvas.fill(255, 255, 255)
canvas.text("POWER 98%", cwidth - 180, cheight - 72)
}
// ============================================================
// MAIN RENDER LOOP
// ============================================================
def viewSpaceMission(canvas: CanvasDraw) {
drawSpaceBackground(canvas)
val satX = cwidth - 200.0
val satY = cheight / 2 + 10.0
val currentRobotY = robotY + floatBob
drawISROSatellite(canvas, satX, satY)
drawSpaceRobot(canvas, robotX, currentRobotY)
drawWeldingEffects(canvas, robotX, currentRobotY, satX, satY)
drawSpaceHUD(canvas)
}
// ============================================================
// START ANIMATION
// ============================================================
animateWithCanvasDraw { canvas =>
updateSpaceRobot()
viewSpaceMission(canvas)
}