// ============================================================
// GENERAL KNOWLEDGE (GK) TEST APP (1ST TO 8TH STANDARD) BY BIXUU
// ============================================================
cleari()
originBottomLeft()
// ============================================================
// APP STATES & VARIABLES
// ============================================================
var screen = 0 // 0: Welcome, 1: Standard Selection, 2: Quiz, 3: Final Result
var selectedStandard = ""
var currentQuestion = 0
var score = 0
// 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(220, 240, 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)))
}
// Sample Questions Database for Standards (4 Options each)
def getQuestionText(std: String, qIndex: Int): String = {
std match {
case "1st Standard" =>
qIndex match {
case 0 => "How many days are there in a week?"
case 1 => "Which animal is known as the king of the jungle?"
case 2 => "How many colors are there in a rainbow?"
case _ => "What is the color of milk?"
}
case "2nd Standard" =>
qIndex match {
case 0 => "Which planet is known as the Red Planet?"
case 1 => "How many months are there in a year?"
case 2 => "Which is our national bird?"
case _ => "How many fingers do you have in one hand?"
}
case "3rd Standard" =>
qIndex match {
case 0 => "What is the capital of India?"
case 1 => "Which organ pumps blood in our body?"
case 2 => "Which is the largest animal on Earth?"
case _ => "In which season do we use woollen clothes?"
}
case "4th Standard" =>
qIndex match {
case 0 => "Who wrote the Indian National Anthem?"
case 1 => "Which is the longest river in the world?"
case 2 => "How many continents are there on Earth?"
case _ => "Which gas do plants take in from the air?"
}
case "5th Standard" =>
qIndex match {
case 0 => "Which is the highest mountain peak in the world?"
case 1 => "Who is known as the Missile Man of India?"
case 2 => "What is the freezing point of water?"
case _ => "Which Indian state has a long coastline?"
}
case "6th Standard" =>
qIndex match {
case 0 => "Which planet is closest to the Sun?"
case 1 => "What is the chemical symbol for water?"
case 2 => "Who discovered gravity?"
case _ => "Which is the smallest continent by area?"
}
case "7th Standard" =>
qIndex match {
case 0 => "What is the speed of light in vacuum?"
case 1 => "Which gas is most abundant in Earth's atmosphere?"
case 2 => "Who was the first President of India?"
case _ => "Which vitamin do we get from sunlight?"
}
case _ => // 8th Standard
qIndex match {
case 0 => "What is the SI unit of force?"
case 1 => "Which blood cells fight infections in our body?"
case 2 => "Who formulated the laws of motion?"
case _ => "What is the powerhouse of the cell?"
}
}
}
def getOptions(std: String, qIndex: Int): Array[String] = {
std match {
case "1st Standard" =>
qIndex match {
case 0 => Array("5", "7", "10", "12")
case 1 => Array("Elephant", "Lion", "Tiger", "Monkey")
case 2 => Array("5", "6", "7", "8")
case _ => Array("Red", "Blue", "White", "Green")
}
case "2nd Standard" =>
qIndex match {
case 0 => Array("Earth", "Mars", "Venus", "Jupiter")
case 1 => Array("10", "12", "6", "30")
case 2 => Array("Sparrow", "Peacock", "Crow", "Pigeon")
case _ => Array("4", "5", "6", "10")
}
case "3rd Standard" =>
qIndex match {
case 0 => Array("Mumbai", "New Delhi", "Kolkata", "Chennai")
case 1 => Array("Lungs", "Heart", "Brain", "Kidney")
case 2 => Array("Elephant", "Blue Whale", "Giraffe", "Shark")
case _ => Array("Summer", "Winter", "Rainy", "Spring")
}
case "4th Standard" =>
qIndex match {
case 0 => Array("Mahatma Gandhi", "Rabindranath Tagore", "Bankim Chandra", "J.L. Nehru")
case 1 => Array("Amazon", "Nile", "Ganga", "Yamuna")
case 2 => Array("5", "6", "7", "8")
case _ => Array("Oxygen", "Carbon Dioxide", "Nitrogen", "Hydrogen")
}
case "5th Standard" =>
qIndex match {
case 0 => Array("K2", "Mount Everest", "Kangchenjunga", "Makalu")
case 1 => Array("A.P.J. Abdul Kalam", "Homi Bhabha", "C.V. Raman", "Vikram Sarabhai")
case 2 => Array("0�C", "100�C", "50�C", "-10�C")
case _ => Array("Gujarat", "Goa", "Maharashtra", "Kerala")
}
case "6th Standard" =>
qIndex match {
case 0 => Array("Mercury", "Venus", "Earth", "Mars")
case 1 => Array("CO2", "H2O", "O2", "NaCl")
case 2 => Array("Albert Einstein", "Isaac Newton", "Galileo", "Thomas Edison")
case _ => Array("Europe", "Australia", "Antarctica", "South America")
}
case "7th Standard" =>
qIndex match {
case 0 => Array("3x10^8 m/s", "330 m/s", "5000 m/s", "1500 m/s")
case 1 => Array("Oxygen", "Nitrogen", "Carbon Dioxide", "Argon")
case 2 => Array("Dr. Rajendra Prasad", "Dr. S. Radhakrishnan", "J.L. Nehru", "Sardar Patel")
case _ => Array("Vitamin A", "Vitamin B", "Vitamin C", "Vitamin D")
}
case _ => // 8th Standard
qIndex match {
case 0 => Array("Joule", "Newton", "Watt", "Pascal")
case 1 => Array("RBC", "WBC", "Platelets", "Plasma")
case 2 => Array("Isaac Newton", "Albert Einstein", "Nikola Tesla", "Galileo")
case _ => Array("Nucleus", "Mitochondria", "Ribosome", "Cytoplasm")
}
}
}
def getCorrectAnswerIndex(std: String, qIndex: Int): Int = {
std match {
case "1st Standard" => qIndex match { case 0 => 1; case 1 => 1; case 2 => 2; case _ => 2 }
case "2nd Standard" => qIndex match { case 0 => 1; case 1 => 1; case 2 => 1; case _ => 1 }
case "3rd Standard" => qIndex match { case 0 => 1; case 1 => 1; case 2 => 1; case _ => 1 }
case "4th Standard" => qIndex match { case 0 => 1; case 1 => 1; case 2 => 2; case _ => 1 }
case "5th Standard" => qIndex match { case 0 => 1; case 1 => 0; case 2 => 0; case _ => 0 }
case "6th Standard" => qIndex match { case 0 => 0; case 1 => 1; case 2 => 1; case _ => 1 }
case "7th Standard" => qIndex match { case 0 => 0; case 1 => 1; case 2 => 0; case _ => 3 }
case _ => qIndex match { case 0 => 1; case 1 => 1; case 2 => 0; case _ => 1 }
}
}
// ============================================================
// SCREEN 0: WELCOME LETTER SCREEN
// ============================================================
def drawLetterScreen(canvas: CanvasDraw) {
canvas.background(20, 35, 55)
repeatFor(stars) { s => s.view(canvas) }
// Letter Card
canvas.fill(255, 252, 245)
canvas.stroke(0, 160, 255)
canvas.strokeWeight(4)
canvas.rect(cwidth/2 - 250, cheight/2 - 190, 500, 380)
// Title
canvas.fill(0, 102, 204)
canvas.text("BIXUU'S GENERAL KNOWLEDGE TEST", cwidth/2 - 170, cheight/2 + 150)
// Letter Body
canvas.fill(40, 40, 40)
canvas.text("Dear Student,", cwidth/2 - 220, cheight/2 + 110)
canvas.text("Welcome! Test your General Knowledge from 1st to", cwidth/2 - 220, cheight/2 + 80)
canvas.text("8th standard. Choose your standard, click directly", cwidth/2 - 220, cheight/2 + 55)
canvas.text("on the options to answer, score points, and win!", cwidth/2 - 220, cheight/2 + 30)
canvas.fill(0, 120, 0)
canvas.text("Click below to start your GK test.", cwidth/2 - 220, cheight/2 - 10)
// Button: Start Test
canvas.fill(255, 102, 0)
canvas.noStroke()
canvas.rect(cwidth/2 - 150, cheight/2 - 110, 300, 50)
canvas.fill(255, 255, 255)
canvas.text("START GK TEST", cwidth/2 - 65, cheight/2 - 80)
}
// ============================================================
// SCREEN 1: SELECT STANDARD (1st to 8th Standard - 8 Options)
// ============================================================
def drawStandardSelectionScreen(canvas: CanvasDraw) {
canvas.background(30, 20, 45)
repeatFor(stars) { s => s.view(canvas) }
canvas.fill(255, 215, 0)
canvas.text("SELECT YOUR STANDARD (1st TO 8th)", cwidth/2 - 145, cheight - 30)
val standards = Array(
"1st Standard", "2nd Standard",
"3rd Standard", "4th Standard",
"5th Standard", "6th Standard",
"7th Standard", "8th Standard"
)
for (i <- 0 until 8) {
val col = i % 2
val row = i / 2
val bx = if (col == 0) cwidth/2 - 220 else cwidth/2 + 20
val by = (cheight/2 + 115) - (row * 60)
// Option Card Box
canvas.fill(255, 248, 220)
canvas.stroke(212, 175, 55)
canvas.strokeWeight(2)
canvas.rect(bx, by, 200, 48)
// Text inside box
canvas.fill(80, 0, 0)
canvas.noStroke()
canvas.text(standards(i), bx + 45, by + 28)
}
// "GO TO LAST" Button at the 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: QUIZ SCREEN (QUESTIONS & DIRECT TEXT OPTIONS)
// ============================================================
def drawQuizScreen(canvas: CanvasDraw) {
canvas.background(15, 25, 35)
repeatFor(stars) { s => s.view(canvas) }
// Header showing standard and score
canvas.fill(255, 215, 0)
canvas.text(selectedStandard + " | Score: " + score, cwidth/2 - 80, cheight - 35)
// Content Box for Question & Direct Text Options
canvas.fill(245, 245, 220)
canvas.stroke(200, 150, 50)
canvas.strokeWeight(3)
canvas.rect(cwidth/2 - 245, cheight/2 - 165, 490, 310)
canvas.fill(30, 30, 30)
canvas.noStroke()
// Question Number & Text
canvas.text("Question " + (currentQuestion + 1) + " of 4", cwidth/2 - 230, cheight/2 + 115)
canvas.text(getQuestionText(selectedStandard, currentQuestion), cwidth/2 - 230, cheight/2 + 85)
// Display 4 Options directly as text in Golden/Dark color (No blue boxes)
val opts = getOptions(selectedStandard, currentQuestion)
for (i <- 0 until 4) {
val oy = (cheight/2 + 35) - (i * 45)
canvas.fill(139, 69, 19) // Rich golden-brown/dark text color
canvas.noStroke()
canvas.text("(" + (i + 1) + ") " + opts(i), cwidth/2 - 230, oy)
}
// Back to standards button
canvas.fill(150, 50, 50)
canvas.rect(cwidth/2 - 130, 15, 260, 35)
canvas.fill(255, 255, 255)
canvas.text("ABORT TEST & BACK", cwidth/2 - 75, 30)
}
// ============================================================
// SCREEN 3: FINAL SCORE & CONGRATULATIONS SCREEN
// ============================================================
def drawFinalScreen(canvas: CanvasDraw) {
canvas.background(25, 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("CONGRATULATIONS!", cwidth/2 - 90, cheight/2 + 95)
canvas.fill(40, 40, 40)
canvas.text("Your Total Points: " + score + " / 40", cwidth/2 - 80, cheight/2 + 60)
canvas.text("Study hard, keep learning, and grow big!", cwidth/2 - 140, cheight/2 + 30)
canvas.fill(0, 100, 150)
canvas.text("bixuu will keep making different types", cwidth/2 - 140, cheight/2 - 10)
canvas.text("of games for you!", cwidth/2 - 70, cheight/2 - 30)
// Restart Button
canvas.fill(120, 50, 180)
canvas.noStroke()
canvas.rect(cwidth/2 - 120, 20, 240, 40)
canvas.fill(255, 255, 255)
canvas.text("RESTART TEST", cwidth/2 - 50, 38)
}
// ============================================================
// CLICK HANDLER
// ============================================================
def handleClick(x: Double, y: Double) {
if (screen == 0) {
// Click "START GK TEST"
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 Standard (1st to 8th)
val standards = Array(
"1st Standard", "2nd Standard",
"3rd Standard", "4th Standard",
"5th Standard", "6th Standard",
"7th Standard", "8th Standard"
)
for (i <- 0 until 8) {
val col = i % 2
val row = i / 2
val bx = if (col == 0) cwidth/2 - 220 else cwidth/2 + 20
val by = (cheight/2 + 115) - (row * 60)
if (x >= bx && x <= bx + 200 && y >= by && y <= by + 48) {
selectedStandard = standards(i)
currentQuestion = 0
score = 0
screen = 2
}
}
}
}
else if (screen == 2) {
// Click Abort Test
if (x >= cwidth/2 - 130 && x <= cwidth/2 + 130 && y >= 15 && y <= 50) {
screen = 1
} else {
// Check click on direct text options lines
for (i <- 0 until 4) {
val oy = (cheight/2 + 35) - (i * 45)
// Clickable area matching each option line text region
if (x >= cwidth/2 - 240 && x <= cwidth/2 + 240 && y >= oy - 15 && y <= oy + 10) {
val correctIdx = getCorrectAnswerIndex(selectedStandard, currentQuestion)
if (i == correctIdx) {
score += 10
}
currentQuestion += 1
if (currentQuestion >= 4) {
screen = 3
}
}
}
}
}
else if (screen == 3) {
// Click "RESTART TEST"
if (x >= cwidth/2 - 120 && x <= cwidth/2 + 120 && y >= 20 && y <= 60) {
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) {
drawStandardSelectionScreen(canvas)
} else if (screen == 2) {
drawQuizScreen(canvas)
} else if (screen == 3) {
drawFinalScreen(canvas)
}
}