Code Sketch
Bavesh art ,,,???
Category: Programming
// --- FLYING ISRO ROCKET LANDING ON MOON (WITHOUT TANKS) ---
cleari()
originBottomLeft()
val gravity = Vector2D(0, -0.08)
var waveAngle = 0.0
var chakraRotation = 0.0
// ????? ???????? ??????????? (Rocket Flight Variables)
val moonX = (cwidth / 2.0) + 120.0
val moonY = cheight - 160.0
var rocketX = (cwidth / 2.0) - 180.0
var rocketY = -50.0 // ????? ?????? ???? ????
var isLanded = false
// ?. ?????? ?????? ?????
val tricolorPalette = Array(
cm.rgb(255, 153, 51), // ?????
cm.rgb(255, 255, 255), // ??????
cm.rgb(18, 136, 7) // ?????
)
class Particle(x0: Double, y0: Double, col: Color, seed: Boolean) {
var location = Vector2D(x0, y0)
private var velocity =
if (seed) Vector2D(0, random(5, 11))
else randomExplosionVector
private var acceleration = Vector2D(0, 0)
var lifespan = 255.0
private var exploded = false
def randomExplosionVector: Vector2D = {
val rv1 = Vector2D(randomNormalDouble, randomNormalDouble)
val r1 = randomDouble(2, 4)
rv1 * r1
}
def applyForce(force: Vector2D) {
acceleration += force
}
def shouldExplode: Boolean = !exploded && lifespan <= 0
def checkExplode() {
if (seed && velocity.y < 0) {
lifespan = 0
}
}
def isDead: Boolean = {
if (seed) exploded else lifespan <= 0
}
def explode() {
exploded = true
}
def step() {
velocity += acceleration
location += velocity
if (!seed) {
lifespan -= 5
velocity *= 0.95
}
acceleration *= 0
checkExplode()
}
def view(canvas: CanvasDraw) {
canvas.stroke(col)
if (seed) {
canvas.strokeWeight(4)
} else {
canvas.strokeWeight(2)
}
canvas.point(location.x, location.y)
}
}
class Firework() {
private val fireworkColor = tricolorPalette(random(tricolorPalette.length))
private val firework = new Particle(random(cwidth), 0, fireworkColor, true)
private val particles = ArrayBuffer.empty[Particle]
def done: Boolean = {
firework.isDead && particles.isEmpty
}
def step() {
particles.filterInPlace(p => !p.isDead)
if (!firework.isDead) {
firework.applyForce(gravity)
firework.step()
if (firework.shouldExplode) {
repeat(80) {
particles.append(
new Particle(firework.location.x, firework.location.y, fireworkColor, false)
)
}
firework.explode()
}
}
repeatFor(particles) { p =>
p.applyForce(gravity)
p.step()
}
}
def view(canvas: CanvasDraw) {
firework.view(canvas)
repeatFor(particles) { p =>
p.view(canvas)
}
}
}
val fireworks = ArrayBuffer.empty[Firework]
def updateState() {
fireworks.filterInPlace(f => !f.done)
if (randomDouble(1) < 0.08) {
fireworks.append(new Firework())
}
repeatFor(fireworks) { f =>
f.step()
}
waveAngle += 0.08
chakraRotation += 0.05
// ????? ??? ??? ???????? ???????
if (!isLanded) {
if (rocketY < moonY + 45) {
rocketY += 3.0 // ?? ????
rocketX += 1.8 // ?????????? ?????? ????? ????
} else {
isLanded = true
}
}
}
// ?. ? ????? (MOON WITH CRATERS)
def drawMoon(canvas: CanvasDraw) {
canvas.fill(210, 215, 220)
canvas.stroke(170, 175, 180)
canvas.strokeWeight(2)
canvas.ellipse(moonX, moonY, 150, 150)
// ?????
canvas.fill(170, 175, 180)
canvas.noStroke()
canvas.ellipse(moonX - 30, moonY + 20, 22, 18)
canvas.ellipse(moonX + 25, moonY - 15, 30, 25)
canvas.ellipse(moonX - 10, moonY - 35, 18, 14)
}
// ?. ? ?????? ISRO ????? (FLYING ISRO ROCKET)
def drawFlyingRocket(canvas: CanvasDraw) {
val rx = rocketX
val ry = rocketY
// ???????? ??? ??? ?? (Fire & Smoke while flying)
if (!isLanded) {
canvas.fill(200, 200, 200, 150)
canvas.noStroke()
canvas.ellipse(rx - 10, ry - 35, random(15, 22), random(15, 22))
canvas.ellipse(rx - 20, ry - 55, random(20, 30), random(20, 30))
canvas.fill(255, 69, 0)
canvas.ellipse(rx, ry - 20, 14, 28)
canvas.fill(255, 215, 0)
canvas.ellipse(rx, ry - 14, 8, 18)
}
// ????? ???? (Rocket Body)
canvas.fill(240, 240, 240)
canvas.stroke(120, 120, 120)
canvas.strokeWeight(1)
canvas.rect(rx - 12, ry - 10, 24, 45)
// ??? (Nose Cone)
canvas.fill(255, 153, 51) // ????? ????
canvas.line(rx - 12, ry + 35, rx, ry + 52)
canvas.line(rx + 12, ry + 35, rx, ry + 52)
// ISRO ????
canvas.fill(0, 51, 102)
canvas.text("ISRO", rx - 10, ry + 10)
// ???/??? (Fins/Legs)
canvas.fill(18, 136, 7) // ????? ???
canvas.rect(rx - 18, ry - 10, 6, 18)
canvas.rect(rx + 12, ry - 10, 6, 18)
}
// ?. ?? ???????? ??????? ??????
def drawWavingTricolorFlag(canvas: CanvasDraw) {
val fw = 110.0
val fh = 20.0
val fx = moonX - 10.0
val fy = moonY + 65.0
canvas.stroke(220, 220, 220)
canvas.strokeWeight(4)
canvas.line(fx, fy + fh * 3, fx, fy - 25)
val stepSize = 3.0
var x = 0.0
while (x < fw) {
val yOffset = math.sin(waveAngle + (x * 0.04)) * 6.0
canvas.stroke(255, 153, 51)
canvas.strokeWeight(stepSize + 1)
canvas.line(fx + x, fy + fh * 2 + yOffset, fx + x, fy + fh * 3 + yOffset)
canvas.stroke(255, 255, 255)
canvas.line(fx + x, fy + fh + yOffset, fx + x, fy + fh * 2 + yOffset)
canvas.stroke(18, 136, 7)
canvas.line(fx + x, fy + yOffset, fx + x, fy + fh + yOffset)
x += stepSize
}
val chakraX = fx + fw / 2.0
val chakraY = fy + fh + (fh / 2.0) + (math.sin(waveAngle + ((fw / 2.0) * 0.04)) * 6.0)
val radius = 8.0
canvas.stroke(0, 0, 128)
canvas.strokeWeight(2)
canvas.noFill()
canvas.ellipse(chakraX, chakraY, radius * 2, radius * 2)
canvas.strokeWeight(1)
for (i <- 0 until 24) {
val angle = chakraRotation + (i * (2 * math.Pi / 24))
val xEnd = chakraX + math.cos(angle) * radius
val yEnd = chakraY + math.sin(angle) * radius
canvas.line(chakraX, chakraY, xEnd, yEnd)
}
}
// ?. ? ???? "INDIAN ISRO" ????? ????? (BIG TITLE)
def drawBigISROTitle(canvas: CanvasDraw) {
val startX = 25.0
val startY = cheight - 50.0
// INDIAN - ????? ???
canvas.fill(255, 153, 51)
canvas.text("INDIAN", startX, startY)
// ISRO - ???? ?????? ?????
canvas.fill(255, 255, 255)
canvas.text("ISRO", startX, startY - 35.0)
// MISSION MOON - ????? ???
canvas.fill(18, 136, 7)
canvas.text("MISSION MOON", startX, startY - 70.0)
}
def viewState(canvas: CanvasDraw) {
// ????????? ??? ???????????
canvas.fill(5, 5, 20, 50)
canvas.noStroke()
canvas.rect(0, 0, cwidth, cheight)
// ?. ?????? ?????
repeatFor(fireworks) { f =>
f.view(canvas)
}
// ?. ????? (Moon)
drawMoon(canvas)
// ?. ?????? ? ??? ?????? ISRO ?????
drawFlyingRocket(canvas)
// ?. ?????????? ??????? ??????
drawWavingTricolorFlag(canvas)
// ?. ???? INDIAN ISRO ?????
drawBigISROTitle(canvas)
}
animateWithCanvasDraw { canvas =>
updateState()
viewState(canvas)
}