Code Sketch


Bixuu02
By: Mhalsakant School
Category: Programming
// ============================================================
// ALL INDIAN FESTIVALS GUIDE APP BY BIXUU
// ============================================================

cleari()
originBottomLeft()

// ============================================================
// APP STATES & VARIABLES
// ============================================================
var screen = 0 // 0: Welcome Letter, 1: Festivals List, 2: Festival Details
var selectedFestival = ""

// Background Star Animation Class
class Star(val x: Double, val y: Double, val size: Double) {
    var phase = randomDouble(6.28)
    def step() { phase += 0.04 }
    def view(canvas: CanvasDraw) {
        val brightness = 150 + (math.sin(phase) * 80).toInt
        canvas.noStroke()
        canvas.fill(255, 240, 200, brightness)
        canvas.ellipse(x, y, size, size)
    }
}

val stars = ArrayBuffer.empty[Star]
for (i <- 0 until 50) {
    stars.append(new Star(randomDouble(cwidth), randomDouble(cheight), 1.0 + randomDouble(2.5)))
}

// ============================================================
// FESTIVALS LIST
// ============================================================
val festivalsList = Array(
    "Diwali",
    "Holi",
    "Eid-ul-Fitr",
    "Christmas",
    "Ganesh Chaturthi",
    "Navratri & Dussehra",
    "Republic Day",
    "Independence Day"
)

// ============================================================
// FESTIVAL DETAILS LOOKUP (Food, Celebration, Activities, School Holiday)
// ============================================================
def getFestivalDetails(festName: String): Array[String] = {
    festName match {
        case "Diwali" => Array(
            "What We Make: Sweets (Laddoo, Barfi), Namakpara, Diyas",
            "What We Celebrate: Return of Lord Rama to Ayodhya",
            "What We Do: Burst Crackers, Worship Goddess Lakshmi, Light Diyas",
            "School Holiday: Yes, Public Holiday (Diwali Break)"
        )
        case "Holi" => Array(
            "What We Make: Gujiya, Thandai, Malpua",
            "What We Celebrate: Victory of good over evil, arrival of spring",
            "What We Do: Play with Colors (Gulal), Water Balloons, Dance",
            "School Holiday: Yes, Public Holiday"
        )
        case "Eid-ul-Fitr" => Array(
            "What We Make: Sheer Khurma, Biryani, Sewai",
            "What We Celebrate: End of Ramadan fasting month",
            "What We Do: Offer Special Prayers, Wear New Clothes, Give Eidi",
            "School Holiday: Yes, Gazetted Holiday"
        )
        case "Christmas" => Array(
            "What We Make: Plum Cake, Cookies, Roasted Turkey",
            "What We Celebrate: Birth of Jesus Christ",
            "What We Do: Decorate Christmas Trees, Sing Carols, Exchange Gifts",
            "School Holiday: Yes, Dec 25 Winter Holiday"
        )
        case "Ganesh Chaturthi" => Array(
            "What We Make: Modak, Puran Poli, Coconut Rice",
            "What We Celebrate: Birth of Lord Ganesha",
            "What We Do: Bring Ganpati Idol, Sing Bhajans, Visarjan Procession",
            "School Holiday: Yes, Regional Holiday (Especially in Maharashtra)"
        )
        case "Navratri & Dussehra" => Array(
            "What We Make: Sabudana Khichdi, Kheer, Puri-Halwa",
            "What We Celebrate: Goddess Durga's victory / Rama defeating Ravana",
            "What We Do: Perform Garba/Dandiya, Burn Effigy of Ravana",
            "School Holiday: Yes, Dussehra Public Holiday"
        )
        case "Republic Day" => Array(
            "What We Make: Tricolor Sweets, Snacks, Special Breakfast",
            "What We Celebrate: Constitution of India coming into force (1950)",
            "What We Do: Flag Hoisting, Parade Watching, Patriotic Singing",
            "School Holiday: Yes, National Holiday (Jan 26)"
        )
        case _ => Array(
            "What We Make: Tricolor Flag snacks, Patriotic theme sweets",
            "What We Celebrate: India gaining independence from British rule (1947)",
            "What We Do: Flag Hoisting ceremony, Kite flying, Cultural events",
            "School Holiday: Yes, National Holiday (Aug 15)"
        )
    }
}

// ============================================================
// SCREENS UI LOGIC
// ============================================================
def drawWelcomeScreen(canvas: CanvasDraw) {
    canvas.background(25, 15, 35)
    repeatFor(stars) { s => s.view(canvas) }

    canvas.fill(255, 252, 245)
    canvas.stroke(255, 180, 0)
    canvas.strokeWeight(4)
    canvas.rect(cwidth/2 - 250, cheight/2 - 190, 500, 380)

    canvas.fill(200, 100, 0)
    canvas.text("ALL INDIAN FESTIVALS GUIDE APP", cwidth/2 - 145, cheight/2 + 150)

    canvas.fill(40, 40, 40)
    canvas.text("Hello Festival Lover,", cwidth/2 - 220, cheight/2 + 110)
    canvas.text("Explore Indian festivals like Diwali, Holi,", cwidth/2 - 220, cheight/2 + 80)
    canvas.text("Eid, Christmas, Ganesh Chaturthi & more.", cwidth/2 - 220, cheight/2 + 55)
    canvas.text("Check special foods, traditions & school holidays.", cwidth/2 - 220, cheight/2 + 30)
    
    canvas.fill(0, 120, 0)
    canvas.text("Click below to start exploring festivals.", cwidth/2 - 220, cheight/2 - 10)

    canvas.fill(255, 140, 0)
    canvas.noStroke()
    canvas.rect(cwidth/2 - 150, cheight/2 - 110, 300, 50)
    canvas.fill(255, 255, 255)
    canvas.text("EXPLORE FESTIVALS", cwidth/2 - 85, cheight/2 - 80)
}

def drawFestivalsListScreen(canvas: CanvasDraw) {
    canvas.background(15, 25, 40)
    repeatFor(stars) { s => s.view(canvas) }

    canvas.fill(255, 215, 0)
    canvas.text("SELECT A FESTIVAL TO VIEW DETAILS", cwidth/2 - 145, cheight - 30)

    for (i <- 0 until festivalsList.length) {
        val col = i % 2
        val row = i / 2
        
        val bx = if (col == 0) cwidth/2 - 235 else cwidth/2 + 10
        val by = (cheight/2 + 130) - (row * 52)
        
        canvas.fill(160, 80, 20)
        canvas.stroke(255, 215, 0)
        canvas.strokeWeight(2)
        canvas.rect(bx, by, 225, 42)

        canvas.fill(255, 255, 255)
        canvas.noStroke()
        canvas.text((i + 1) + ". " + festivalsList(i), bx + 10, by + 26)
    }

    canvas.fill(100, 100, 100)
    canvas.noStroke()
    canvas.rect(cwidth/2 - 80, 12, 160, 28)
    canvas.fill(255, 255, 255)
    canvas.text("BACK TO HOME", cwidth/2 - 45, 28)
}

def drawFestivalDetailsScreen(canvas: CanvasDraw) {
    canvas.background(25, 15, 35)
    repeatFor(stars) { s => s.view(canvas) }

    canvas.fill(255, 215, 0)
    canvas.text("FESTIVAL PROFILE: " + selectedFestival, cwidth/2 - 140, cheight - 35)

    canvas.fill(250, 248, 235)
    canvas.stroke(255, 140, 0)
    canvas.strokeWeight(3)
    canvas.rect(cwidth/2 - 240, cheight/2 - 140, 480, 260)

    canvas.fill(30, 30, 30)
    canvas.noStroke()

    val details = getFestivalDetails(selectedFestival)
    for (i <- 0 until details.length) {
        val dy = (cheight/2 + 65) - (i * 38)
        canvas.fill(150, 50, 0)
        canvas.text("- " + details(i), cwidth/2 - 210, dy)
    }

    canvas.fill(0, 120, 150)
    canvas.rect(cwidth/2 - 110, 15, 220, 32)
    canvas.fill(255, 255, 255)
    canvas.text("BACK TO LIST", cwidth/2 - 45, 31)
}

// ============================================================
// CLICK HANDLER LOGIC
// ============================================================
def handleClick(x: Double, y: Double) {
    if (screen == 0) {
        if (x >= cwidth/2 - 150 && x <= cwidth/2 + 150 && y >= cheight/2 - 110 && y <= cheight/2 - 60) {
            screen = 1
        }
    } 
    else if (screen == 1) {
        if (x >= cwidth/2 - 80 && x <= cwidth/2 + 80 && y >= 12 && y <= 42) {
            screen = 0
        } else {
            for (i <- 0 until festivalsList.length) {
                val col = i % 2
                val row = i / 2
                val bx = if (col == 0) cwidth/2 - 235 else cwidth/2 + 10
                val by = (cheight/2 + 130) - (row * 52)
                
                if (x >= bx && x <= bx + 225 && y >= by && y <= by + 42) {
                    selectedFestival = festivalsList(i)
                    screen = 2
                }
            }
        }
    }
    else if (screen == 2) {
        if (x >= cwidth/2 - 110 && x <= cwidth/2 + 110 && y >= 15 && y <= 47) {
            screen = 1
        }
    }
}

onMouseClick { (x, y) => handleClick(x, y) }

// ============================================================
// MAIN ANIMATION LOOP
// ============================================================
animateWithCanvasDraw { canvas =>
    repeatFor(stars) { s => s.step() }

    if (screen == 0) drawWelcomeScreen(canvas)
    else if (screen == 1) drawFestivalsListScreen(canvas)
    else if (screen == 2) drawFestivalDetailsScreen(canvas)
}