Code Sketch
yadnesh shahare using gemini
Category: Programming
// Start writing your Kojo code here
cleari()
setBackground(Color(5, 5, 20)) // Deep Cosmic Universe Background
// 3D Vector Representation
case class Vector3D(x: Double, y: Double, z: Double)
// Viewport and Geometry Configurations
val viewAngleHalf = Math.toRadians(90.0 / 2.0)
val size = canvasBounds.width * 0.5
// Planets Data: Jagannath Brahm in Center followed by Planets
case class PlanetInfo(name: String, orbitRadius: Double, radius: Double, color: Color, speed: Double)
val solarSystem = Seq(
PlanetInfo("Jagannath Brahm", 0, 48, Color(255, 215, 0), 0.0),
PlanetInfo("Mercury", 85, 7, Color(192, 192, 192), 4.0),
PlanetInfo("Venus", 135, 11, Color(230, 190, 138), 1.6),
PlanetInfo("Earth", 185, 13, Color(100, 149, 237), 1.0),
PlanetInfo("Mars", 235, 9, Color(220, 20, 60), 0.8),
PlanetInfo("Jupiter", 310, 25, Color(218, 165, 32), 0.4),
PlanetInfo("Saturn", 390, 20, Color(244, 164, 96), 0.3),
PlanetInfo("Uranus", 460, 15, Color(72, 209, 204), 0.2),
PlanetInfo("Neptune", 520, 14, Color(30, 144, 255), 0.1)
)
// Transformation Helpers
def rotateAroundX(angle: Double, point: Vector3D): Vector3D =
Vector3D(
point.x,
point.y * Math.cos(angle) - point.z * Math.sin(angle),
point.y * Math.sin(angle) + point.z * Math.cos(angle)
)
def normalisePoint(point: Vector3D): Vector3D =
Vector3D(point.x / size, point.y / size, point.z / size)
def toWorld(point: Vector3D): Vector3D =
Vector3D(point.x * size, point.y * size, point.z * size)
def toPerspective(point: Vector3D): Vector3D =
Vector3D(
point.x / (point.z * Math.tan(viewAngleHalf)),
point.y / (point.z * Math.tan(viewAngleHalf)),
point.z
)
// Static Background Stars for Brahmand Feel
val stars = (1 to 60).map { _ =>
(randomDouble(-canvasBounds.width/2, canvasBounds.width/2),
randomDouble(-canvasBounds.height/2, canvasBounds.height/2),
randomDouble(1, 3))
}
def drawStars(): Unit = {
stars.foreach { case (sx, sy, r) =>
val starPic = Picture.circle(r)
starPic.setFillColor(Color(255, 255, 255, 180))
starPic.setPenColor(noColor)
starPic.setPosition(sx, sy)
draw(starPic)
}
}
// Orbit Lines Drawing
def drawOrbit(orbitRadius: Double, tiltAngle: Double): Unit = {
val numSegments = 60
val points = (0 to numSegments).map { i =>
val theta = 2.0 * Math.PI * i / numSegments
val rawPoint = Vector3D(orbitRadius * Math.cos(theta), 0, orbitRadius * Math.sin(theta) + size + 100)
val centered = Vector3D(rawPoint.x, rawPoint.y, rawPoint.z - (size + 100))
val tilted = rotateAroundX(Math.toRadians(tiltAngle), centered)
val final3D = Vector3D(tilted.x, tilted.y, tilted.z + (size + 100))
toWorld(toPerspective(normalisePoint(final3D)))
}
val orbitPic = Picture.fromVertexShape { p =>
p.beginShape()
points.foreach(v => p.vertex(v.x, v.y))
p.endShape()
}
orbitPic.setPenColor(Color(255, 215, 0, 45)) // Golden Orbit Path
orbitPic.setPenThickness(1)
draw(orbitPic)
}
// Render Jagannath Brahm / Celestial Bodies
def renderPlanet(planet: PlanetInfo, currentAngle: Double, tiltAngle: Double): Unit = {
val orbitalRad = Math.toRadians(currentAngle * planet.speed)
val rawPos = if (planet.orbitRadius == 0) {
Vector3D(0, 0, size + 100)
} else {
val x = planet.orbitRadius * Math.cos(orbitalRad)
val z = planet.orbitRadius * Math.sin(orbitalRad)
Vector3D(x, 0, z + size + 100)
}
val centered = Vector3D(rawPos.x, rawPos.y, rawPos.z - (size + 100))
val tilted = rotateAroundX(Math.toRadians(tiltAngle), centered)
val final3D = Vector3D(tilted.x, tilted.y, tilted.z + (size + 100))
val projected = toWorld(toPerspective(normalisePoint(final3D)))
val scaleFactor = size / final3D.z
val apparentRadius = planet.radius * scaleFactor * 1.4
if (planet.name == "Jagannath Brahm") {
// --- 1. Jagannath Cosmic Glow (Brahm Aura) ---
val auraOuter = Picture.circle(apparentRadius * 2.2)
auraOuter.setFillColor(Color(255, 140, 0, 80))
auraOuter.setPenColor(noColor)
auraOuter.setPosition(projected.x, projected.y)
draw(auraOuter)
val auraInner = Picture.circle(apparentRadius * 1.5)
auraInner.setFillColor(Color(255, 215, 0, 140))
auraInner.setPenColor(noColor)
auraInner.setPosition(projected.x, projected.y)
draw(auraInner)
// --- 2. Central Brahm Core ---
val core = Picture.circle(apparentRadius)
core.setFillColor(Color(255, 255, 220))
core.setPenColor(Color(255, 69, 0))
core.setPenThickness(3)
core.setPosition(projected.x, projected.y)
draw(core)
// --- 3. Sacred OM Symbol inside Brahm ---
val omText = Picture.text("?", (apparentRadius * 1.1).toInt)
omText.setPenColor(Color(180, 0, 0))
omText.setPosition(projected.x - (apparentRadius * 0.4), projected.y - (apparentRadius * 0.4))
draw(omText)
// --- Label ---
val label = Picture.text("?? ??????? (??????)", 13)
label.setPenColor(Color(255, 223, 0))
label.setPosition(projected.x - 50, projected.y - apparentRadius - 22)
draw(label)
} else {
// Render Regular Planets
val planetPic = Picture.circle(apparentRadius)
planetPic.setFillColor(planet.color)
planetPic.setPenColor(noColor)
planetPic.setPosition(projected.x, projected.y)
draw(planetPic)
// Saturn's Ring
if (planet.name == "Saturn") {
val ring = Picture.ellipse(apparentRadius * 2.3, apparentRadius * 0.7)
ring.setPenColor(Color(220, 190, 140))
ring.setPenThickness(2)
ring.setPosition(projected.x, projected.y)
draw(ring)
}
// Planet Label
val namePic = Picture.text(planet.name, 11)
namePic.setPenColor(Color(200, 200, 255))
namePic.setPosition(projected.x - (planet.name.length * 3), projected.y - apparentRadius - 15)
draw(namePic)
}
}
// Animation Loop
animateWithState(0.0) { angle =>
erasePictures()
// Draw Static Cosmic Background
drawStars()
val viewTilt = 25.0
// Draw Orbits
solarSystem.tail.foreach { p =>
drawOrbit(p.orbitRadius, viewTilt)
}
// Sorting Z-axis for perspective overlap
val sortedPlanets = solarSystem.map { p =>
val rad = Math.toRadians(angle * p.speed)
val rawPos = if (p.orbitRadius == 0) Vector3D(0, 0, size + 100)
else Vector3D(p.orbitRadius * Math.cos(rad), 0, p.orbitRadius * Math.sin(rad) + size + 100)
val centered = Vector3D(rawPos.x, rawPos.y, rawPos.z - (size + 100))
val tilted = rotateAroundX(Math.toRadians(viewTilt), centered)
val finalZ = tilted.z + (size + 100)
(p, finalZ)
}.sortBy(_._2).reverse
// Render Cosmic Universe Objects
sortedPlanets.foreach { case (p, _) =>
renderPlanet(p, angle, viewTilt)
}
angle + 0.5
}