Code Sketch
Bixuu02
// ============================================================
// MAHARASHTRA 6 DIVISIONS & 36 DISTRICTS GUIDE APP BY BIXUU
// ============================================================
cleari()
originBottomLeft()
// ============================================================
// APP STATES & VARIABLES
// ============================================================
var screen = 0 // 0: Welcome, 1: Divisions List, 2: Districts List, 3: District Details
var selectedDivision = ""
var selectedDistrict = ""
// 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(200, 220, 255, 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)))
}
// ============================================================
// 6 DIVISIONS OF MAHARASHTRA
// ============================================================
val divisionsList = Array(
"1. Konkan Division (7 Districts)",
"2. Pune Division (5 Districts)",
"3. Nashik Division (5 Districts)",
"4. Sambhajinagar Division (8 Districts)",
"5. Amravati Division (5 Districts)",
"6. Nagpur Division (6 Districts)"
)
// Mapping Division Titles for Logic
def getDivisionKey(index: Int): String = {
index match {
case 0 => "Konkan"
case 1 => "Pune"
case 2 => "Nashik"
case 3 => "Sambhajinagar"
case 4 => "Amravati"
case _ => "Nagpur"
}
}
// ============================================================
// DISTRICTS UNDER EACH DIVISION (Total 36 Districts)
// ============================================================
def getDistrictsForDivision(div: String): Array[String] = {
div match {
case "Konkan" => Array("Mumbai City", "Mumbai Suburban", "Thane", "Palghar", "Raigad", "Ratnagiri", "Sindhudurg")
case "Pune" => Array("Pune", "Satara", "Sangli", "Kolhapur", "Solapur")
case "Nashik" => Array("Nashik", "Ahilyanagar", "Dhule", "Nandurbar", "Jalgaon")
case "Sambhajinagar" => Array("Chhatrapati Sambhajinagar", "Jalna", "Beed", "Parbhani", "Hingoli", "Latur", "Nanded", "Dharashiv")
case "Amravati" => Array("Amravati", "Akola", "Buldhana", "Washim", "Y????? (Yavatmal)")
case _ => Array("Nagpur", "Wardha", "Bhandara", "Gondia", "Chandrapur", "Gadchiroli")
}
}
// ============================================================
// DISTRICT SPECIALTIES & FESTIVALS LOOKUP
// ============================================================
def getDistrictDetails(district: String): Array[String] = {
district match {
case "Pune" => Array(
"Specialty: Puneri Misal, Puran Poli & IT Hub",
"Famous Items: Shalu Sarees & Puneri Pagdi",
"Festivals Celebrated: Ganesh Chaturthi, Shiv Jayanti",
"Cultural Event: Pune International Film Festival"
)
case "Kolhapur" => Array(
"Specialty: Kolhapuri Chappal & Spicy Misal",
"Famous Items: Jaggery (Gul) & Kolhapuri Saaj",
"Festivals Celebrated: Mahalakshmi Kiranotsav, Navratri",
"Cultural Event: Jyotiba Fair & Shahu Maharaj Jayanti"
)
case "Nagpur" => Array(
"Specialty: Juicy Oranges (Santra) & Tarri Poha",
"Famous Items: Orange Barfi & Cotton Fabrics",
"Festivals Celebrated: Dhamm Chakra Pravartan Din, Pola",
"Cultural Event: Nagpur Orange Festival"
)
case "Nashik" => Array(
"Specialty: World-Class Grapes & Wine Capital",
"Famous Items: Fresh Vegetables & Godavari Snan",
"Festivals Celebrated: Kumbh Mela, Makar Sankranti",
"Cultural Event: Grape Harvesting Festival"
)
case "Mumbai City" => Array(
"Specialty: Vada Pav, Street Food & Bollywood",
"Famous Items: Gateway of India, Fashion & Textiles",
"Festivals Celebrated: Ganesh Chaturthi, Gudi Padwa",
"Cultural Event: Kala Ghoda Arts Festival"
)
case _ => Array(
"Specialty: Local Agricultural Produce & Crafts",
"Famous Items: Traditional Handlooms & Sweets",
"Festivals Celebrated: Pola, Diwali, Ganesh Chaturthi",
"Cultural Event: Regional Folk Dances & Fairs"
)
}
}
// ============================================================
// SCREENS UI LOGIC
// ============================================================
def drawWelcomeScreen(canvas: CanvasDraw) {
canvas.background(15, 25, 40)
repeatFor(stars) { s => s.view(canvas) }
canvas.fill(255, 252, 245)
canvas.stroke(0, 150, 255)
canvas.strokeWeight(4)
canvas.rect(cwidth/2 - 250, cheight/2 - 190, 500, 380)
canvas.fill(0, 102, 204)
canvas.text("MAHARASHTRA 6 DIVISIONS & 36 DISTRICTS", cwidth/2 - 165, cheight/2 + 150)
canvas.fill(40, 40, 40)
canvas.text("Hello Explorer,", cwidth/2 - 220, cheight/2 + 110)
canvas.text("Explore all 6 administrative divisions and", cwidth/2 - 220, cheight/2 + 80)
canvas.text("all 36 districts of Maharashtra state.", cwidth/2 - 220, cheight/2 + 55)
canvas.text("Check specialties, famous items & festivals.", cwidth/2 - 220, cheight/2 + 30)
canvas.fill(0, 120, 0)
canvas.text("Click below to start exploring divisions.", cwidth/2 - 220, cheight/2 - 10)
canvas.fill(0, 120, 204)
canvas.noStroke()
canvas.rect(cwidth/2 - 150, cheight/2 - 110, 300, 50)
canvas.fill(255, 255, 255)
canvas.text("EXPLORE DIVISIONS", cwidth/2 - 80, cheight/2 - 80)
}
def drawDivisionsListScreen(canvas: CanvasDraw) {
canvas.background(15, 25, 40)
repeatFor(stars) { s => s.view(canvas) }
canvas.fill(255, 215, 0)
canvas.text("SELECT A DIVISION (TOTAL 6 DIVISIONS)", cwidth/2 - 145, cheight - 30)
for (i <- 0 until divisionsList.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 + 100) - (row * 52)
canvas.fill(20, 100, 140)
canvas.stroke(255, 215, 0)
canvas.strokeWeight(2)
canvas.rect(bx, by, 225, 42)
canvas.fill(255, 255, 255)
canvas.noStroke()
canvas.text(divisionsList(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 drawDistrictsListScreen(canvas: CanvasDraw) {
canvas.background(15, 25, 40)
repeatFor(stars) { s => s.view(canvas) }
canvas.fill(255, 215, 0)
canvas.text("DISTRICTS IN " + selectedDivision.toUpperCase() + " DIVISION", cwidth/2 - 160, cheight - 30)
val currentDistricts = getDistrictsForDivision(selectedDivision)
for (i <- 0 until currentDistricts.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 * 48)
canvas.fill(40, 120, 100)
canvas.stroke(255, 215, 0)
canvas.strokeWeight(2)
canvas.rect(bx, by, 225, 38)
canvas.fill(255, 255, 255)
canvas.noStroke()
canvas.text((i + 1) + ". " + currentDistricts(i), bx + 10, by + 24)
}
canvas.fill(100, 100, 100)
canvas.noStroke()
canvas.rect(cwidth/2 - 90, 12, 180, 28)
canvas.fill(255, 255, 255)
canvas.text("BACK TO DIVISIONS", cwidth/2 - 65, 28)
}
def drawDistrictDetailsScreen(canvas: CanvasDraw) {
canvas.background(25, 15, 35)
repeatFor(stars) { s => s.view(canvas) }
canvas.fill(255, 215, 0)
canvas.text("DISTRICT PROFILE: " + selectedDistrict, cwidth/2 - 140, cheight - 35)
canvas.fill(250, 248, 235)
canvas.stroke(0, 150, 255)
canvas.strokeWeight(3)
canvas.rect(cwidth/2 - 240, cheight/2 - 140, 480, 260)
canvas.fill(30, 30, 30)
canvas.noStroke()
val details = getDistrictDetails(selectedDistrict)
for (i <- 0 until details.length) {
val dy = (cheight/2 + 65) - (i * 38)
canvas.fill(0, 90, 150)
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 DISTRICTS", cwidth/2 - 75, 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 divisionsList.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 + 100) - (row * 52)
if (x >= bx && x <= bx + 225 && y >= by && y <= by + 42) {
selectedDivision = getDivisionKey(i)
screen = 2
}
}
}
}
else if (screen == 2) {
if (x >= cwidth/2 - 90 && x <= cwidth/2 + 90 && y >= 12 && y <= 40) {
screen = 1
} else {
val currentDistricts = getDistrictsForDivision(selectedDivision)
for (i <- 0 until currentDistricts.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 * 48)
if (x >= bx && x <= bx + 225 && y >= by && y <= by + 38) {
selectedDistrict = currentDistricts(i)
screen = 3
}
}
}
}
else if (screen == 3) {
if (x >= cwidth/2 - 110 && x <= cwidth/2 + 110 && y >= 15 && y <= 47) {
screen = 2
}
}
}
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) drawDivisionsListScreen(canvas)
else if (screen == 2) drawDistrictsListScreen(canvas)
else if (screen == 3) drawDistrictDetailsScreen(canvas)
}