Code Sketch


yadnesh shahare
By: Mhalsakant School
Category: Art
// --- 5-Second Timer, Extra Large Pop-up Tiranga Flag with Further Lowered Ashoka Chakra & Fireworks in Kojo ---
cleari() 
setBackgroundH(orange, green)
setPenColor(white)
setBackground(Color(10, 15, 25))

var started = false
var triggerFrame = 0.0
val durationFrames = 150.0 // 5 seconds countdown duration (30 fps * 5)

animateWithState(0.0) { frame =>
  erasePictures()

  val w = canvasBounds.width
  val h = canvasBounds.height

  // Clean background without any extra lines
  val bg = Picture.rectangle(w, h)
  bg.setFillColor(Color(10, 15, 25))
  draw(bg)

  // Mouse trigger for 5-second timer (moves up)
  val mPos = mousePosition
  if (!started && mPos.y > 0) {
    started = true
    triggerFrame = frame
  }

  val elapsed = if (started) frame - triggerFrame else 0.0
  val secondsLeft = Math.max(0.0, 5.0 - (elapsed / 30.0))
  val finished = elapsed >= durationFrames

  if (!started) {
    val prompt = Picture.text("Move Mouse Up to Start 5s Timer! ??", 18)
    prompt.setPenColor(Color(255, 255, 255))
    prompt.setPosition(0, 0)
    draw(prompt)
  } else if (!finished) {
    // Show countdown timer while flag is hidden
    val timerTxt = Picture.text(f"Timer: $secondsLeft%.1f s", 26)
    timerTxt.setPenColor(Color(255, 153, 51))
    timerTxt.setPosition(0, 0)
    draw(timerTxt)
  } else {
    // --- AFTER 5 SECONDS: EXTRA LARGE FLAG POP-UP, FURTHER LOWERED NAVY BLUE CHAKRA, FIREWORKS & TEXT ---

    val flagWidth = 380.0
    val flagHeight = 210.0
    val startX = -flagWidth / 2.0
    val flagCenterY = 0.0 // Perfectly centered on screen (madhomad)
    val stripH = flagHeight / 3.0

    val bandColors = Seq(Color(255, 103, 31), Color(255, 255, 255), Color(19, 136, 8))

    def drawBand(color: Color, index: Int): Unit = {
      val bandTopY = flagCenterY + stripH - (index * stripH)
      val bandBotY = bandTopY - stripH

      val pic = Picture.fromVertexShape { p =>
        p.beginShape()
        val steps = 15
        for (i <- 0 to steps) {
          val r = i.toDouble / steps
          val x = startX + (flagWidth * r)
          val y = bandTopY + Math.sin(r * Math.PI * 2.0 + frame * 0.18) * 10.0
          p.vertex(x, y)
        }
        for (i <- steps to 0 by -1) {
          val r = i.toDouble / steps
          val x = startX + (flagWidth * r)
          val y = bandBotY + Math.sin(r * Math.PI * 2.0 + frame * 0.18) * 10.0
          p.vertex(x, y)
        }
        p.endShape()
      }
      pic.setFillColor(color)
      draw(pic)
    }

    // Draw Saffron band (Top)
    drawBand(bandColors(0), 0)
    
    // Draw White band (Middle)
    drawBand(bandColors(1), 1)
    
    // Draw Green band (Bottom)
    drawBand(bandColors(2), 2)

    // Ashoka Chakra with Navy Blue Color moved further down (- 30.0)
    val whiteBandCenterY = flagCenterY
    val chakraRatio = 0.5
    val chakraX = startX + (flagWidth * chakraRatio)
    val chakraY = whiteBandCenterY + Math.sin(chakraRatio * Math.PI * 2.0 + frame * 0.18) * 10.0 - 30.0
    
    val chakra = Picture.circle(18) 
    chakra.setPenColor(Color(0, 0, 128)) // Navy Blue Color for Ashoka Chakra
    chakra.setPenThickness(2.5)
    chakra.setPosition(chakraX, chakraY)
    draw(chakra)

    // Fireworks bursting around the flag
    val fwAge = (elapsed - durationFrames) % 90.0
    val fx = 0.0
    val fy = 130.0
    
    val fwRadius = fwAge * 4.0
    val fwAlpha = Math.max(0, (255.0 * (1.0 - (fwAge / 90.0))).toInt)
    
    val fw1 = Picture.circle(fwRadius)
    fw1.setPenColor(Color(255, 103, 31, fwAlpha))
    fw1.setPenThickness(3)
    fw1.setPosition(fx, fy)
    draw(fw1)

    val fw2 = Picture.circle(fwRadius * 0.8)
    fw2.setPenColor(Color(255, 255, 255, fwAlpha))
    fw2.setPenThickness(2)
    fw2.setPosition(fx - 160, fy - 20)
    draw(fw2)

    val fw3 = Picture.circle(fwRadius * 0.9)
    fw3.setPenColor(Color(50, 255, 50, fwAlpha))
    fw3.setPenThickness(2)
    fw3.setPosition(fx + 160, fy - 20)
    draw(fw3)

    // HAPPY INDEPENDENCE DAY Text at the top center
    val title = Picture.text("HAPPY INDEPENDENCE DAY! ??", 46)
    title.setPenColor(Color(255, 153, 51))
    title.setPosition(0, h / 2.0 - 50.0)
    draw(title)
  }

  frame + 1.0
}