Code Sketch


Bixuu02
By: Mhalsakant School
Category: Programming
// ============================================================
// CARS, BUSINESS & ENGINEERING TIPS SYSTEM (BY BIXUU)
// ============================================================

cleari()
originBottomLeft()

// ============================================================
// APP STATES & VARIABLES
// ============================================================
var screen = 0
var selectedCategory = ""

// Animation Variables for background glowing stars
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, 230, 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)))
}

// ============================================================
// SCREEN 0: WELCOME LETTER SCREEN (CARS & BUSINESS GUIDE)
// ============================================================
def drawLetterScreen(canvas: CanvasDraw) {
    canvas.background(15, 25, 45)
    repeatFor(stars) { s => s.view(canvas) }

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

    // Title
    canvas.fill(0, 102, 204)
    canvas.text("CARS, BUSINESS & ENGINEERING GUIDE", cwidth/2 - 175, cheight/2 + 150)

    // Letter Body
    canvas.fill(40, 40, 40)
    canvas.text("Dear User,", cwidth/2 - 220, cheight/2 + 110)
    canvas.text("Welcome! Explore top Car Brands with prices & looks,", cwidth/2 - 220, cheight/2 + 80)
    canvas.text("expert Business Ideas, and essential Engineering tips", cwidth/2 - 220, cheight/2 + 55)
    canvas.text("to build your future and achieve success.", cwidth/2 - 220, cheight/2 + 30)
    
    canvas.fill(0, 120, 0)
    canvas.text("Click below to explore all categories.", cwidth/2 - 220, cheight/2 - 10)

    // Button: Explore All Options
    canvas.fill(255, 102, 0)
    canvas.noStroke()
    canvas.rect(cwidth/2 - 150, cheight/2 - 110, 300, 50)
    canvas.fill(255, 255, 255)
    canvas.text("EXPLORE CARS & BUSINESS IDEAS", cwidth/2 - 130, cheight/2 - 80)
}

// ============================================================
// SCREEN 1: SELECTION SCREEN (CARS & BUSINESS OPTIONS)
// ============================================================
def drawSelectionScreen(canvas: CanvasDraw) {
    canvas.background(25, 15, 35)
    repeatFor(stars) { s => s.view(canvas) }

    canvas.fill(255, 215, 0)
    canvas.text("CHOOSE A CATEGORY TO EXPLORE", cwidth/2 - 135, cheight - 30)

    // Categories: Car Brands & Business/Engineering Topics (6 Options)
    val options = Array(
        "Luxury Cars (Prices & Looks)", 
        "Electric Cars (EV Revolution)", 
        "SUV & Off-road Cars", 
        "Startup Business Ideas", 
        "Tech & Engineering Tips", 
        "Financial & Investment Tips"
    )
    
    for (i <- 0 until 6) {
        val col = i % 2
        val row = i / 2
        
        val bx = if (col == 0) cwidth/2 - 220 else cwidth/2 + 20
        val by = (cheight/2 + 90) - (row * 65)
        
        // Option Card Box
        canvas.fill(245, 245, 220)
        canvas.stroke(212, 175, 55)
        canvas.strokeWeight(2)
        canvas.rect(bx, by, 200, 52)

        // Text inside box
        canvas.fill(50, 0, 0)
        canvas.noStroke()
        // Simple text formatting per line
        canvas.text(options(i), bx + 10, by + 30)
    }

    // "GO TO LAST" Button at top
    canvas.fill(180, 50, 50)
    canvas.noStroke()
    canvas.rect(cwidth/2 - 100, 15, 200, 32)
    canvas.fill(255, 255, 255)
    canvas.text("GO TO LAST", cwidth/2 - 40, 33)
}

// ============================================================
// SCREEN 2: DETAILS SCREEN (PRICES, LOOKS & TIPS)
// ============================================================
def drawDetailsScreen(canvas: CanvasDraw) {
    canvas.background(15, 25, 35)
    repeatFor(stars) { s => s.view(canvas) }

    // Header showing selected category
    canvas.fill(255, 215, 0)
    canvas.text(selectedCategory, cwidth/2 - (selectedCategory.length * 4), cheight - 35)

    // Content Box
    canvas.fill(250, 248, 235)
    canvas.stroke(0, 120, 200)
    canvas.strokeWeight(3)
    canvas.rect(cwidth/2 - 245, cheight/2 - 165, 490, 310)

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

    // Display info based on selection
    if (selectedCategory == "Luxury Cars (Prices & Looks)") {
        canvas.text("Top Brands: Mercedes, BMW, Audi, Porsche", cwidth/2 - 230, cheight/2 + 115)
        canvas.text("Looks: Sleek aerodynamics, premium leather interiors", cwidth/2 - 230, cheight/2 + 95)
        canvas.text("Price Range: Rs. 60 Lakhs to Rs. 3 Crores+", cwidth/2 - 230, cheight/2 + 75)
        canvas.text("Key Tip:", cwidth/2 - 230, cheight/2 + 45)
        canvas.text("\"Luxury cars offer ultimate comfort, high safety specs,\"", cwidth/2 - 230, cheight/2 + 20)
        canvas.text("\"and cutting-edge driver assistance technology.\"", cwidth/2 - 230, cheight/2 - 0)
    } 
    else if (selectedCategory == "Electric Cars (EV Revolution)") {
        canvas.text("Top Brands: Tesla, Tata EV, Hyundai Ioniq, BMW i4", cwidth/2 - 230, cheight/2 + 115)
        canvas.text("Looks: Futuristic futuristic grill-less design, LED matrix", cwidth/2 - 230, cheight/2 + 95)
        canvas.text("Price Range: Rs. 12 Lakhs to Rs. 1.5 Crores", cwidth/2 - 230, cheight/2 + 75)
        canvas.text("Key Tip:", cwidth/2 - 230, cheight/2 + 45)
        canvas.text("\"Zero tailpipe emissions, low running cost per km,\"", cwidth/2 - 230, cheight/2 + 20)
        canvas.text("\"and instant torque make EVs the future of transport.\"", cwidth/2 - 230, cheight/2 - 0)
    }
    else if (selectedCategory == "SUV & Off-road Cars") {
        canvas.text("Top Brands: Toyota Fortuner, Thar, Land Rover, Jeep", cwidth/2 - 230, cheight/2 + 115)
        canvas.text("Looks: Muscular body, high ground clearance, bold grille", cwidth/2 - 230, cheight/2 + 95)
        canvas.text("Price Range: Rs. 15 Lakhs to Rs. 2.5 Crores", cwidth/2 - 230, cheight/2 + 75)
        canvas.text("Key Tip:", cwidth/2 - 230, cheight/2 + 45)
        canvas.text("\"Built for rough terrains, heavy load capacity,\"", cwidth/2 - 230, cheight/2 + 20)
        canvas.text("\"and superior road presence in all weather conditions.\"", cwidth/2 - 230, cheight/2 - 0)
    }
    else if (selectedCategory == "Startup Business Ideas") {
        canvas.text("Top Sectors: EdTech, AI Automation, E-Commerce, D2C", cwidth/2 - 230, cheight/2 + 115)
        canvas.text("Investment: Low initial capital with scalable models", cwidth/2 - 230, cheight/2 + 95)
        canvas.text("Target: Solve real-world consumer problems efficiently", cwidth/2 - 230, cheight/2 + 75)
        canvas.text("Business Tip:", cwidth/2 - 230, cheight/2 + 45)
        canvas.text("\"Focus on product-market fit before heavy scaling.\"", cwidth/2 - 230, cheight/2 + 20)
        canvas.text("\"Consistency, customer retention are key to profits.\"", cwidth/2 - 230, cheight/2 - 0)
    }
    else if (selectedCategory == "Tech & Engineering Tips") {
        canvas.text("Core Domains: Software, Robotics, Mechanical Design", cwidth/2 - 230, cheight/2 + 115)
        canvas.text("Skillset: Python, CAD modeling, Problem solving", cwidth/2 - 230, cheight/2 + 95)
        canvas.text("Approach: Build practical projects from scratch", cwidth/2 - 230, cheight/2 + 75)
        canvas.text("Engineering Tip:", cwidth/2 - 230, cheight/2 + 45)
        canvas.text("\"Always understand the fundamental physics or logic\"", cwidth/2 - 230, cheight/2 + 20)
        canvas.text("\"behind every system before optimizing it.\"", cwidth/2 - 230, cheight/2 - 0)
    }
    else if (selectedCategory == "Financial & Investment Tips") {
        canvas.text("Sectors: Mutual Funds, Stocks, Real Estate, Gold", cwidth/2 - 230, cheight/2 + 115)
        canvas.text("Strategy: Compound interest and long-term holding", cwidth/2 - 230, cheight/2 + 95)
        canvas.text("Rule: Never put all eggs in one basket (Diversify)", cwidth/2 - 230, cheight/2 + 75)
        canvas.text("Financial Tip:", cwidth/2 - 230, cheight/2 + 45)
        canvas.text("\"Save first, spend what is left after savings.\"", cwidth/2 - 230, cheight/2 + 20)
        canvas.text("\"Start investing early to build solid wealth.\"", cwidth/2 - 230, cheight/2 - 0)
    }

    // Bottom Navigation: Back to selection
    canvas.fill(0, 130, 100)
    canvas.rect(cwidth/2 - 140, 15, 280, 35)
    canvas.fill(255, 255, 255)
    canvas.text("BACK TO CATEGORIES", cwidth/2 - 80, 30)
}

// ============================================================
// SCREEN 3: FINAL DEDICATION SCREEN (BIXUU MESSAGE)
// ============================================================
def drawFinalScreen(canvas: CanvasDraw) {
    canvas.background(20, 10, 35)
    repeatFor(stars) { s => s.view(canvas) }

    // Message Card
    canvas.fill(255, 245, 230)
    canvas.stroke(255, 215, 0)
    canvas.strokeWeight(4)
    canvas.rect(cwidth/2 - 240, cheight/2 - 140, 480, 280)

    canvas.fill(200, 30, 30)
    canvas.text("THANK YOU FOR EXPLORING!", cwidth/2 - 130, cheight/2 + 95)

    canvas.fill(40, 40, 40)
    canvas.text("bixuu will keep making best and new", cwidth/2 - 210, cheight/2 + 45)
    canvas.text("codes for you!", cwidth/2 - 210, cheight/2 + 20)

    canvas.fill(0, 100, 150)
    canvas.text("Keep learning and building amazing things!", cwidth/2 - 210, cheight/2 - 15)

    // Back to Home Button
    canvas.fill(120, 50, 180)
    canvas.noStroke()
    canvas.rect(cwidth/2 - 120, 20, 240, 38)
    canvas.fill(255, 255, 255)
    canvas.text("RESTART APP", cwidth/2 - 50, 33)
}

// ============================================================
// CLICK HANDLER
// ============================================================
def handleClick(x: Double, y: Double) {
    if (screen == 0) {
        // Click "EXPLORE CARS & BUSINESS IDEAS"
        if (x >= cwidth/2 - 150 && x <= cwidth/2 + 150 && y >= cheight/2 - 110 && y <= cheight/2 - 60) {
            screen = 1
        }
    } 
    else if (screen == 1) {
        // Check click on "GO TO LAST" Button
        if (x >= cwidth/2 - 100 && x <= cwidth/2 + 100 && y >= 15 && y <= 47) {
            screen = 3
        } else {
            // Select one of the 6 Categories
            val options = Array(
                "Luxury Cars (Prices & Looks)", 
                "Electric Cars (EV Revolution)", 
                "SUV & Off-road Cars", 
                "Startup Business Ideas", 
                "Tech & Engineering Tips", 
                "Financial & Investment Tips"
            )
            for (i <- 0 until 6) {
                val col = i % 2
                val row = i / 2
                val bx = if (col == 0) cwidth/2 - 220 else cwidth/2 + 20
                val by = (cheight/2 + 90) - (row * 65)
                
                if (x >= bx && x <= bx + 200 && y >= by && y <= by + 52) {
                    selectedCategory = options(i)
                    screen = 2
                }
            }
        }
    } 
    else if (screen == 2) {
        // Click "BACK TO CATEGORIES"
        if (x >= cwidth/2 - 140 && x <= cwidth/2 + 140 && y >= 15 && y <= 50) {
            screen = 1
        }
    }
    else if (screen == 3) {
        // Click "RESTART APP"
        if (x >= cwidth/2 - 120 && x <= cwidth/2 + 120 && y >= 20 && y <= 58) {
            screen = 0
        }
    }
}

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

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

    if (screen == 0) {
        drawLetterScreen(canvas)
    } else if (screen == 1) {
        drawSelectionScreen(canvas)
    } else if (screen == 2) {
        drawDetailsScreen(canvas)
    } else if (screen == 3) {
        drawFinalScreen(canvas)
    }
}