Code Sketch


ganit mirta by shlok thakur
By: Mhalsakant School
Category: Programming
/*
====================================================================
                    GANIT MITRA
             KOJO MATHEMATICS LEARNING APP
====================================================================

FLOW:

START
  ?
ENTER NAME
  ?
CHOOSE STANDARD
  ?
CHOOSE DIFFICULTY
  ?
CHOOSE QUESTION
  ?
READY
  ?
DASHBOARD
  ??? SIMPLE ENGLISH
  ??? FORMULA
  ??? STEP BY STEP
  ??? MARATHI
  ??? FULL ENGLISH
  ??? 2D ANIMATION
          ?
     LESSON COMPLETE

IMPORTANT:
- No readLine()
- Mouse buttons only
- MathSolution has exactly 10 fields
- Every MathSolution has exactly 10 arguments
====================================================================
*/


// ================================================================
// 1. DATA CLASSES
// ================================================================

case class Student(
  name: String,
  grade: Int
)

case class MathSolution(
  question: String,
  topic: String,
  formula: String,
  answer: String,
  steps: List[String],
  simpleEnglish: List[String],
  english: List[String],
  marathi: List[String],
  animationTitle: String,
  animationSteps: List[String]
)


// ================================================================
// 2. COLORS
// ================================================================

val bg = cm.rgb(12, 20, 45)
val bg2 = cm.rgb(20, 30, 60)

val blue = cm.rgb(40, 120, 220)
val cyan = cm.rgb(70, 200, 245)

val green = cm.rgb(40, 170, 100)
val purple = cm.rgb(125, 80, 200)
val orange = cm.rgb(230, 125, 45)
val pink = cm.rgb(200, 70, 150)

val yellow = cm.rgb(255, 215, 0)
val white = cm.rgb(250, 250, 250)
val gray = cm.rgb(80, 90, 110)

val card = cm.rgb(30, 47, 78)
val darkGreen = cm.rgb(20, 70, 55)
val red = cm.rgb(190, 55, 55)


// ================================================================
// 3. APP VARIABLES
// ================================================================

var currentStudent =
  Student("Student", 8)

var enteredName =
  ""

var selectedGrade =
  8

var selectedDifficulty =
  "DIFFICULT"

var currentQuestion =
  "(x+5)^2"


// ================================================================
// 4. NORMALIZE
// ================================================================

def normalizeQuestion(q: String): String = {

  q.trim
    .replace(" ", "")
    .replace("?", "-")
    .replace("�", "^2")
    .replace("�", "^3")
}


// ================================================================
// 5. MATH ENGINE
// ================================================================

def solveMath(q0: String): MathSolution = {

  val q =
    normalizeQuestion(q0)


  // ============================================================
  // EASY 1
  // ============================================================

  if (q == "(x+5)^2") {

    MathSolution(
      "(x + 5)^2",
      "Square of Sum",
      "(A + B)^2 = A^2 + 2AB + B^2",
      "x^2 + 10x + 25",

      List(
        "Step 1: Identify the formula.",
        "(A + B)^2 = A^2 + 2AB + B^2.",
        "Step 2: A = x.",
        "Step 3: B = 5.",
        "Step 4: Substitute.",
        "(x + 5)^2 = x^2 + 2(x)(5) + 5^2.",
        "Step 5: 2(x)(5) = 10x.",
        "Step 6: 5^2 = 25.",
        "Final answer: x^2 + 10x + 25."
      ),

      List(
        "This is a square of a sum.",
        "Take A = x.",
        "Take B = 5.",
        "Use the square identity.",
        "The middle term is 10x.",
        "The last term is 25."
      ),

      List(
        "Use the identity for the square of a sum.",
        "Let A = x and B = 5.",
        "Substitute both values.",
        "Calculate the middle term.",
        "Calculate the final square.",
        "The result is x^2 + 10x + 25."
      ),

      List(
        "?? Square of Sum ?? ?????? ???.",
        "A = x ??? B = 5 ????.",
        "??????????? ?????? ????.",
        "???? term 10x ???.",
        "5 ?? square 25 ???.",
        "????? x^2 + 10x + 25."
      ),

      "SQUARE OF SUM",

      List(
        "(x + 5)^2",
        "A = x",
        "B = 5",
        "Apply square identity",
        "Calculate x^2",
        "Calculate 2(x)(5)",
        "Calculate 5^2",
        "x^2 + 10x + 25",
        "ANSWER COMPLETE!"
      )
    )
  }


  // ============================================================
  // EASY 2
  // ============================================================

  else if (q == "(x-5)^2") {

    MathSolution(
      "(x - 5)^2",
      "Square of Difference",
      "(A - B)^2 = A^2 - 2AB + B^2",
      "x^2 - 10x + 25",

      List(
        "Step 1: Identify the formula.",
        "(A - B)^2 = A^2 - 2AB + B^2.",
        "Step 2: A = x.",
        "Step 3: B = 5.",
        "Step 4: Substitute.",
        "(x - 5)^2 = x^2 - 2(x)(5) + 5^2.",
        "Step 5: 2(x)(5) = 10x.",
        "Step 6: 5^2 = 25.",
        "Final answer: x^2 - 10x + 25."
      ),

      List(
        "This is a square of a difference.",
        "Take A = x.",
        "Take B = 5.",
        "Use the square difference identity.",
        "The middle term is negative.",
        "The last term is 25."
      ),

      List(
        "Use the square of difference identity.",
        "Let A = x and B = 5.",
        "Substitute the values.",
        "Calculate the middle term.",
        "Calculate the last square.",
        "The result is x^2 - 10x + 25."
      ),

      List(
        "?? Square of Difference ?? ?????? ???.",
        "A = x ??? B = 5 ????.",
        "????? ?????.",
        "???? term negative ???.",
        "?????? term 25 ???.",
        "????? x^2 - 10x + 25."
      ),

      "SQUARE OF DIFFERENCE",

      List(
        "(x - 5)^2",
        "A = x",
        "B = 5",
        "Apply square difference",
        "Calculate x^2",
        "Calculate -2(x)(5)",
        "Calculate 5^2",
        "x^2 - 10x + 25",
        "ANSWER COMPLETE!"
      )
    )
  }


  // ============================================================
  // MEDIUM 1
  // ============================================================

  else if (q == "(2m-5)^3") {

    MathSolution(
      "(2m - 5)^3",
      "Cube of Difference",
      "(A - B)^3 = A^3 - 3A^2B + 3AB^2 - B^3",
      "8m^3 - 60m^2 + 150m - 125",

      List(
        "Step 1: Use the cube of difference identity.",
        "(A - B)^3 = A^3 - 3A^2B + 3AB^2 - B^3.",
        "Step 2: A = 2m.",
        "Step 3: B = 5.",
        "Step 4: Substitute.",
        "(2m - 5)^3 = (2m)^3 - 3(2m)^2(5) + 3(2m)(5)^2 - 5^3.",
        "Step 5: (2m)^3 = 8m^3.",
        "Step 6: 3(2m)^2(5) = 60m^2.",
        "Step 7: 3(2m)(5)^2 = 150m.",
        "Step 8: 5^3 = 125.",
        "Final answer: 8m^3 - 60m^2 + 150m - 125."
      ),

      List(
        "The bracket has power 3.",
        "So use the cube of difference formula.",
        "A = 2m.",
        "B = 5.",
        "Put them into the formula.",
        "Calculate all four terms.",
        "Then write the answer."
      ),

      List(
        "Use the cube of difference identity.",
        "Let A = 2m and B = 5.",
        "Substitute them into the identity.",
        "Calculate each term carefully.",
        "Combine the four terms.",
        "The answer is 8m^3 - 60m^2 + 150m - 125."
      ),

      List(
        "?? Cube of Difference ?? ?????? ???.",
        "A = 2m ??? B = 5 ????.",
        "??????????? ?????? ????.",
        "???????? term ???? ???.",
        "???? terms ????? ???.",
        "????? 8m^3 - 60m^2 + 150m - 125."
      ),

      "CUBE OF DIFFERENCE",

      List(
        "(2m - 5)^3",
        "A = 2m",
        "B = 5",
        "Apply cube identity",
        "(2m)^3 = 8m^3",
        "Calculate middle terms",
        "Last term = 125",
        "8m^3 - 60m^2 + 150m - 125",
        "ANSWER COMPLETE!"
      )
    )
  }


  // ============================================================
  // DIFFICULT 1
  // ============================================================

  else if (q == "24a^3+81b^3") {

    MathSolution(
      "24a^3 + 81b^3",
      "Sum of Cubes",
      "A^3 + B^3 = (A + B)(A^2 - AB + B^2)",
      "3(2a + 3b)(4a^2 - 6ab + 9b^2)",

      List(
        "Step 1: Start with 24a^3 + 81b^3.",
        "Step 2: Take 3 common.",
        "24a^3 + 81b^3 = 3(8a^3 + 27b^3).",
        "Step 3: 8a^3 = (2a)^3.",
        "Step 4: 27b^3 = (3b)^3.",
        "Step 5: Use A^3 + B^3.",
        "Step 6: A = 2a and B = 3b.",
        "Step 7: Apply the identity.",
        "3[(2a)^3 + (3b)^3].",
        "Step 8: Factorize.",
        "3(2a + 3b)(4a^2 - 6ab + 9b^2).",
        "Final answer: 3(2a + 3b)(4a^2 - 6ab + 9b^2)."
      ),

      List(
        "First take 3 common.",
        "Now we get 8a^3 + 27b^3.",
        "Both terms are cubes.",
        "8a^3 is (2a)^3.",
        "27b^3 is (3b)^3.",
        "Use the sum of cubes formula.",
        "Take A = 2a and B = 3b.",
        "Then simplify the factors."
      ),

      List(
        "Factor out 3 first.",
        "Rewrite both terms as cubes.",
        "Apply the sum of cubes identity.",
        "Let A = 2a and B = 3b.",
        "Substitute into the identity.",
        "Simplify all three factors.",
        "The final factorized expression is",
        "3(2a + 3b)(4a^2 - 6ab + 9b^2)."
      ),

      List(
        "?? Sum of Cubes ?? ?????? ???.",
        "????????? 3 common ????.",
        "8a^3 = (2a)^3.",
        "27b^3 = (3b)^3.",
        "Sum of Cubes ?? ????? ?????.",
        "A = 2a ??? B = 3b ????.",
        "???? terms simplify ???.",
        "????? 3(2a + 3b)(4a^2 - 6ab + 9b^2)."
      ),

      "SUM OF CUBES",

      List(
        "24a^3 + 81b^3",
        "Take 3 common",
        "3(8a^3 + 27b^3)",
        "Convert into cubes",
        "3[(2a)^3 + (3b)^3]",
        "Apply A^3 + B^3",
        "3(2a + 3b)",
        "4a^2 - 6ab + 9b^2",
        "ANSWER COMPLETE!"
      )
    )
  }


  // ============================================================
  // DIFFICULT 2
  // ============================================================

  else if (q == "8x^3+27y^3") {

    MathSolution(
      "8x^3 + 27y^3",
      "Sum of Cubes",
      "A^3 + B^3 = (A + B)(A^2 - AB + B^2)",
      "(2x + 3y)(4x^2 - 6xy + 9y^2)",

      List(
        "Step 1: Observe 8x^3 + 27y^3.",
        "Step 2: Write 8x^3 as (2x)^3.",
        "Step 3: Write 27y^3 as (3y)^3.",
        "Step 4: This is a sum of cubes.",
        "Step 5: Use A^3 + B^3.",
        "Step 6: A = 2x.",
        "Step 7: B = 3y.",
        "Step 8: Substitute.",
        "Step 9: Simplify the second factor.",
        "Final answer: (2x + 3y)(4x^2 - 6xy + 9y^2)."
      ),

      List(
        "Both terms are perfect cubes.",
        "8x^3 is (2x)^3.",
        "27y^3 is (3y)^3.",
        "Use the sum of cubes formula.",
        "Take A = 2x and B = 3y.",
        "Now simplify."
      ),

      List(
        "Recognize the sum of two cubes.",
        "Rewrite each term as a cube.",
        "Apply the standard identity.",
        "Substitute A = 2x and B = 3y.",
        "Simplify the quadratic factor.",
        "The answer is (2x + 3y)(4x^2 - 6xy + 9y^2)."
      ),

      List(
        "?? ??? cubes ?? ????? ???.",
        "8x^3 = (2x)^3.",
        "27y^3 = (3y)^3.",
        "Sum of Cubes ?? ????? ?????.",
        "A = 2x ??? B = 3y.",
        "????? ?????."
      ),

      "SUM OF CUBES",

      List(
        "8x^3 + 27y^3",
        "(2x)^3 + (3y)^3",
        "A = 2x",
        "B = 3y",
        "Apply sum of cubes",
        "2x + 3y",
        "4x^2 - 6xy + 9y^2",
        "Final factorization",
        "ANSWER COMPLETE!"
      )
    )
  }


  // ============================================================
  // DIFFICULT 3
  // ============================================================

  else if (q == "125p^3-64q^3") {

    MathSolution(
      "125p^3 - 64q^3",
      "Difference of Cubes",
      "A^3 - B^3 = (A - B)(A^2 + AB + B^2)",
      "(5p - 4q)(25p^2 + 20pq + 16q^2)",

      List(
        "Step 1: Start with 125p^3 - 64q^3.",
        "Step 2: 125p^3 = (5p)^3.",
        "Step 3: 64q^3 = (4q)^3.",
        "Step 4: This is a difference of cubes.",
        "Step 5: Use A^3 - B^3.",
        "Step 6: A = 5p.",
        "Step 7: B = 4q.",
        "Step 8: Substitute.",
        "(5p - 4q)((5p)^2 + (5p)(4q) + (4q)^2).",
        "Step 9: Simplify.",
        "Final answer: (5p - 4q)(25p^2 + 20pq + 16q^2)."
      ),

      List(
        "Both terms are perfect cubes.",
        "125p^3 is (5p)^3.",
        "64q^3 is (4q)^3.",
        "Because there is a minus sign, use difference of cubes.",
        "A = 5p and B = 4q.",
        "Substitute and simplify."
      ),

      List(
        "Recognize the difference of two cubes.",
        "Rewrite both terms as cubes.",
        "Apply A^3 - B^3.",
        "Let A = 5p and B = 4q.",
        "Calculate A^2, AB and B^2.",
        "Combine the factors.",
        "The final answer is (5p - 4q)(25p^2 + 20pq + 16q^2)."
      ),

      List(
        "?? Difference of Cubes ?? ?????? ???.",
        "125p^3 = (5p)^3.",
        "64q^3 = (4q)^3.",
        "Difference of Cubes ?? ????? ?????.",
        "A = 5p ??? B = 4q.",
        "A^2, AB ??? B^2 ????.",
        "????? factorization ?????."
      ),

      "DIFFERENCE OF CUBES",

      List(
        "125p^3 - 64q^3",
        "(5p)^3 - (4q)^3",
        "A = 5p",
        "B = 4q",
        "Apply difference of cubes",
        "5p - 4q",
        "25p^2 + 20pq + 16q^2",
        "Final factorization",
        "ANSWER COMPLETE!"
      )
    )
  }


  // ============================================================
  // DIFFICULT 4
  // ============================================================

  else if (q == "x^2+10x+25") {

    MathSolution(
      "x^2 + 10x + 25",
      "Perfect Square",
      "A^2 + 2AB + B^2 = (A + B)^2",
      "(x + 5)^2",

      List(
        "Step 1: Observe x^2 + 10x + 25.",
        "Step 2: x^2 = x^2.",
        "Step 3: 25 = 5^2.",
        "Step 4: Check the middle term.",
        "2(x)(5) = 10x.",
        "Step 5: Therefore it matches A^2 + 2AB + B^2.",
        "Step 6: A = x and B = 5.",
        "Step 7: Write as a perfect square.",
        "Final answer: (x + 5)^2."
      ),

      List(
        "This is a perfect square trinomial.",
        "The first term is x^2.",
        "The last term is 25.",
        "The middle term is 10x.",
        "10x equals 2 times x times 5.",
        "So the answer is (x + 5)^2."
      ),

      List(
        "Check whether the expression is a perfect square.",
        "Take the square root of the first and last terms.",
        "Check the middle term.",
        "The required middle term is 2(x)(5) = 10x.",
        "Therefore the expression is a perfect square.",
        "Final result: (x + 5)^2."
      ),

      List(
        "?? Perfect Square Trinomial ???.",
        "????? term x^2 ???.",
        "?????? term 25 ???.",
        "???? term 10x ???.",
        "2(x)(5) = 10x.",
        "?????? ????? (x + 5)^2."
      ),

      "PERFECT SQUARE",

      List(
        "x^2 + 10x + 25",
        "Check first square",
        "Check last square",
        "Check middle term",
        "2(x)(5) = 10x",
        "Pattern matched",
        "Write the square",
        "(x + 5)^2",
        "ANSWER COMPLETE!"
      )
    )
  }


  // ============================================================
  // UNKNOWN
  // ============================================================

  else {

    MathSolution(
      q0,
      "Learning Mode",
      "Choose a supported formula",
      "Select an example",

      List(
        "Please select a supported question.",
        "Use the question menu to choose an example."
      ),

      List(
        "Choose a question from the menu.",
        "GANIT MITRA will explain it step by step."
      ),

      List(
        "Select a supported mathematics example."
      ),

      List(
        "????? ?????? ?????? ?????."
      ),

      "LEARNING MODE",

      List(
        "Choose a question",
        "Read the formula",
        "Follow the steps",
        "Learn the answer"
      )
    )
  }
}


// ================================================================
// 6. CURRENT SOLUTION
// ================================================================

def solution: MathSolution =
  solveMath(currentQuestion)


// ================================================================
// 7. TEXT
// ================================================================

def txt(
  s: String,
  x: Double,
  y: Double,
  c: Color,
  scaleValue: Double
): Picture = {

  val p =
    Picture.text(s)

  p.setPenColor(c)
  p.setPosition(x, y)

  if (scaleValue != 1.0) {
    p.scale(scaleValue)
  }

  p
}


// ================================================================
// 8. LINES
// ================================================================

def lines(
  data: List[String],
  x: Double,
  y: Double,
  gap: Double,
  c: Color,
  size: Double
): Unit = {

  var yy = y

  data.foreach { s =>

    draw(
      txt(
        s,
        x,
        yy,
        c,
        size
      )
    )

    yy = yy - gap
  }
}


// ================================================================
// 9. BUTTON
// ================================================================

def button(
  label: String,
  x: Double,
  y: Double,
  w: Double,
  h: Double,
  c: Color
): Picture = {

  val b =
    Picture.rectangle(w, h)

  b.setFillColor(c)
  b.setPenColor(white)
  b.setPenThickness(2)
  b.setPosition(x, y)

  draw(b)

  val t =
    Picture.text(label)

  t.setPenColor(white)

  t.setPosition(
    x + 12,
    y + (h / 2) - 5
  )

  draw(t)

  b
}


// ================================================================
// 10. HEADER
// ================================================================

def header(
  title: String,
  background: Color
): Unit = {

  cleari()
  setBackground(background)

  draw(
    txt(
      "GANIT MITRA",
      -145,
      255,
      yellow,
      1.2
    )
  )

  draw(
    txt(
      title,
      -150,
      220,
      white,
      0.68
    )
  )

  draw(
    txt(
      currentStudent.name +
      " | Class " +
      currentStudent.grade,
      -110,
      190,
      cyan,
      0.58
    )
  )
}


// ================================================================
// 11. DASHBOARD BUTTON
// ================================================================

def home(): Unit = {

  val b =
    button(
      "DASHBOARD",
      -80,
      -260,
      160,
      42,
      gray
    )

  b.onMouseClick { (x, y) =>
    showDashboard()
  }
}


// ================================================================
// 12. WELCOME
// ================================================================

def showWelcome(): Unit = {

  cleari()
  setBackground(bg)

  draw(
    txt(
      "GANIT MITRA",
      -140,
      200,
      yellow,
      1.5
    )
  )

  draw(
    txt(
      "MATHEMATICS LEARNING APP",
      -145,
      160,
      cyan,
      0.72
    )
  )

  draw(
    txt(
      "Name ? Standard ? Difficulty ? Solution",
      -175,
      120,
      white,
      0.58
    )
  )


  val panel =
    Picture.rectangle(520, 150)

  panel.setFillColor(card)
  panel.setPenColor(blue)
  panel.setPenThickness(3)
  panel.setPosition(-260, -30)

  draw(panel)


  draw(
    txt(
      "LEARN MATHEMATICS STEP BY STEP",
      -145,
      50,
      yellow,
      0.7
    )
  )

  draw(
    txt(
      "First enter your name.",
      -110,
      10,
      white,
      0.58
    )
  )

  draw(
    txt(
      "Then choose standard and difficulty.",
      -135,
      -20,
      white,
      0.58
    )
  )


  val start =
    button(
      "START",
      -90,
      -140,
      180,
      55,
      green
    )

  start.onMouseClick { (x, y) =>
    showName()
  }
}


// ================================================================
// 13. NAME SCREEN
// ================================================================

def showName(): Unit = {

  header(
    "STEP 1 - ENTER YOUR NAME",
    bg
  )


  draw(
    txt(
      "Click letters to enter your name",
      -135,
      135,
      yellow,
      0.68
    )
  )


  val nameBox =
    Picture.rectangle(500, 55)

  nameBox.setFillColor(card)
  nameBox.setPenColor(cyan)
  nameBox.setPenThickness(2)
  nameBox.setPosition(-250, 70)

  draw(nameBox)


  val displayName =
    if (enteredName == "")
      "YOUR NAME"
    else
      enteredName


  draw(
    txt(
      displayName,
      -100,
      87,
      white,
      0.72
    )
  )


  // --------------------------------------------------------------
  // LETTER BUTTONS
  // --------------------------------------------------------------

  val letters =
    List(
      ("A", -270, 15),
      ("B", -205, 15),
      ("C", -140, 15),
      ("D", -75, 15),
      ("E", -10, 15),
      ("F", 55, 15),
      ("G", 120, 15),
      ("H", 185, 15),

      ("I", -270, -45),
      ("J", -205, -45),
      ("K", -140, -45),
      ("L", -75, -45),
      ("M", -10, -45),
      ("N", 55, -45),
      ("O", 120, -45),
      ("P", 185, -45),

      ("Q", -270, -105),
      ("R", -205, -105),
      ("S", -140, -105),
      ("T", -75, -105),
      ("U", -10, -105),
      ("V", 55, -105),
      ("W", 120, -105),
      ("X", 185, -105)
    )


  letters.foreach {
    case (letter, x, y) =>

      val b =
        button(
          letter,
          x,
          y,
          50,
          42,
          blue
        )

      b.onMouseClick { (mx, my) =>
        if (enteredName.length < 12) {
          enteredName =
            enteredName + letter
        }

        showName()
      }
  }


  val clear =
    button(
      "CLEAR",
      -250,
      -175,
      130,
      45,
      red
    )

  clear.onMouseClick { (x, y) =>
    enteredName = ""
    showName()
  }


  val back =
    button(
      "BACK",
      -100,
      -175,
      130,
      45,
      gray
    )

  back.onMouseClick { (x, y) =>
    showWelcome()
  }


  val next =
    button(
      "NEXT",
      50,
      -175,
      130,
      45,
      green
    )

  next.onMouseClick { (x, y) =>

    if (enteredName != "") {
      currentStudent =
        Student(
          enteredName,
          selectedGrade
        )

      showStandard()
    }
  }


  val y =
    button(
      "Y",
      250,
      15,
      50,
      42,
      purple
    )

  y.onMouseClick { (x, y) =>
    if (enteredName.length < 12)
      enteredName = enteredName + "Y"

    showName()
  }


  val z =
    button(
      "Z",
      250,
      -45,
      50,
      42,
      purple
    )

  z.onMouseClick { (x, y) =>
    if (enteredName.length < 12)
      enteredName = enteredName + "Z"

    showName()
  }
}


// ================================================================
// 14. STANDARD SCREEN
// ================================================================

def showStandard(): Unit = {

  header(
    "STEP 2 - CHOOSE STANDARD",
    bg
  )


  draw(
    txt(
      "Hello " + enteredName + "!",
      -80,
      130,
      yellow,
      0.8
    )
  )


  draw(
    txt(
      "Which standard are you studying?",
      -130,
      95,
      white,
      0.62
    )
  )


  val c6 =
    button(
      "CLASS 6",
      -270,
      30,
      160,
      55,
      green
    )

  c6.onMouseClick { (x, y) =>
    selectedGrade = 6
    currentStudent = Student(enteredName, 6)
    showDifficulty()
  }


  val c7 =
    button(
      "CLASS 7",
      -80,
      30,
      160,
      55,
      blue
    )

  c7.onMouseClick { (x, y) =>
    selectedGrade = 7
    currentStudent = Student(enteredName, 7)
    showDifficulty()
  }


  val c8 =
    button(
      "CLASS 8",
      110,
      30,
      160,
      55,
      purple
    )

  c8.onMouseClick { (x, y) =>
    selectedGrade = 8
    currentStudent = Student(enteredName, 8)
    showDifficulty()
  }


  val c9 =
    button(
      "CLASS 9",
      -80,
      -45,
      160,
      55,
      orange
    )

  c9.onMouseClick { (x, y) =>
    selectedGrade = 9
    currentStudent = Student(enteredName, 9)
    showDifficulty()
  }


  val back =
    button(
      "BACK",
      -80,
      -130,
      160,
      45,
      gray
    )

  back.onMouseClick { (x, y) =>
    showName()
  }
}


// ================================================================
// 15. DIFFICULTY SCREEN
// ================================================================

def showDifficulty(): Unit = {

  header(
    "STEP 3 - CHOOSE DIFFICULTY",
    bg
  )


  draw(
    txt(
      "Choose the level of question",
      -125,
      125,
      yellow,
      0.72
    )
  )


  val easy =
    button(
      "EASY",
      -270,
      35,
      160,
      60,
      green
    )

  easy.onMouseClick { (x, y) =>
    selectedDifficulty = "EASY"
    showExamples()
  }


  val medium =
    button(
      "MEDIUM",
      -80,
      35,
      160,
      60,
      blue
    )

  medium.onMouseClick { (x, y) =>
    selectedDifficulty = "MEDIUM"
    showExamples()
  }


  val difficult =
    button(
      "DIFFICULT",
      110,
      35,
      160,
      60,
      red
    )

  difficult.onMouseClick { (x, y) =>
    selectedDifficulty = "DIFFICULT"
    showExamples()
  }


  draw(
    txt(
      "For challenging practice choose DIFFICULT.",
      -160,
      -60,
      cyan,
      0.58
    )
  )


  val back =
    button(
      "BACK",
      -80,
      -130,
      160,
      45,
      gray
    )

  back.onMouseClick { (x, y) =>
    showStandard()
  }
}


// ================================================================
// 16. EXAMPLES
// ================================================================

def showExamples(): Unit = {

  header(
    "STEP 4 - CHOOSE QUESTION",
    bg
  )


  draw(
    txt(
      selectedDifficulty + " QUESTIONS",
      -105,
      130,
      yellow,
      0.72
    )
  )


  if (selectedDifficulty == "EASY") {

    val q1 =
      button(
        "(x + 5)^2",
        -250,
        40,
        200,
        55,
        green
      )

    q1.onMouseClick { (x, y) =>
      currentQuestion = "(x+5)^2"
      showReady()
    }


    val q2 =
      button(
        "(x - 5)^2",
        50,
        40,
        200,
        55,
        green
      )

    q2.onMouseClick { (x, y) =>
      currentQuestion = "(x-5)^2"
      showReady()
    }
  }


  else if (selectedDifficulty == "MEDIUM") {

    val q1 =
      button(
        "(2m - 5)^3",
        -250,
        40,
        220,
        55,
        blue
      )

    q1.onMouseClick { (x, y) =>
      currentQuestion = "(2m-5)^3"
      showReady()
    }


    val q2 =
      button(
        "x^2 + 10x + 25",
        30,
        40,
        250,
        55,
        blue
      )

    q2.onMouseClick { (x, y) =>
      currentQuestion = "x^2+10x+25"
      showReady()
    }
  }


  else {

    draw(
      txt(
        "CHALLENGE MODE",
        -100,
        90,
        red,
        0.65
      )
    )


    val q1 =
      button(
        "24a^3 + 81b^3",
        -270,
        30,
        250,
        55,
        red
      )

    q1.onMouseClick { (x, y) =>
      currentQuestion = "24a^3+81b^3"
      showReady()
    }


    val q2 =
      button(
        "8x^3 + 27y^3",
        20,
        30,
        250,
        55,
        red
      )

    q2.onMouseClick { (x, y) =>
      currentQuestion = "8x^3+27y^3"
      showReady()
    }


    val q3 =
      button(
        "125p^3 - 64q^3",
        -270,
        -50,
        250,
        55,
        orange
      )

    q3.onMouseClick { (x, y) =>
      currentQuestion = "125p^3-64q^3"
      showReady()
    }


    val q4 =
      button(
        "x^2 + 10x + 25",
        20,
        -50,
        250,
        55,
        orange
      )

    q4.onMouseClick { (x, y) =>
      currentQuestion = "x^2+10x+25"
      showReady()
    }
  }


  val back =
    button(
      "BACK",
      -80,
      -140,
      160,
      45,
      gray
    )

  back.onMouseClick { (x, y) =>
    showDifficulty()
  }
}


// ================================================================
// 17. READY
// ================================================================

def showReady(): Unit = {

  cleari()
  setBackground(bg2)


  draw(
    txt(
      "READY?",
      -65,
      190,
      yellow,
      1.2
    )
  )


  draw(
    txt(
      currentStudent.name +
      " | Class " +
      currentStudent.grade,
      -120,
      145,
      cyan,
      0.62
    )
  )


  draw(
    txt(
      selectedDifficulty + " QUESTION",
      -100,
      110,
      orange,
      0.6
    )
  )


  val box =
    Picture.rectangle(520, 130)

  box.setFillColor(card)
  box.setPenColor(cyan)
  box.setPenThickness(3)
  box.setPosition(-260, -20)

  draw(box)


  draw(
    txt(
      "YOUR QUESTION",
      -75,
      45,
      yellow,
      0.65
    )
  )


  draw(
    txt(
      solution.question,
      -150,
      -5,
      white,
      0.9
    )
  )


  val solve =
    button(
      "SOLVE NOW",
      -115,
      -130,
      230,
      55,
      green
    )

  solve.onMouseClick { (x, y) =>
    showDashboard()
  }
}


// ================================================================
// 18. DASHBOARD
// ================================================================

def showDashboard(): Unit = {

  cleari()
  setBackground(bg)


  draw(
    txt(
      "GANIT MITRA",
      -115,
      245,
      yellow,
      1.2
    )
  )


  draw(
    txt(
      "Hello " + currentStudent.name,
      -90,
      210,
      white,
      0.72
    )
  )


  draw(
    txt(
      "Class " +
      currentStudent.grade +
      " | " +
      selectedDifficulty,
      -100,
      180,
      cyan,
      0.58
    )
  )


  val qbox =
    Picture.rectangle(600, 115)

  qbox.setFillColor(card)
  qbox.setPenColor(blue)
  qbox.setPenThickness(3)
  qbox.setPosition(-300, 55)

  draw(qbox)


  draw(
    txt(
      "QUESTION",
      -55,
      120,
      yellow,
      0.65
    )
  )


  draw(
    txt(
      solution.question,
      -145,
      80,
      white,
      0.82
    )
  )


  draw(
    txt(
      solution.topic,
      -100,
      57,
      cyan,
      0.55
    )
  )


  // ROW 1

  val b1 =
    button(
      "SIMPLE ENGLISH",
      -300,
      -20,
      190,
      50,
      green
    )

  b1.onMouseClick { (x, y) =>
    showSimple()
  }


  val b2 =
    button(
      "FORMULA",
      -95,
      -20,
      190,
      50,
      blue
    )

  b2.onMouseClick { (x, y) =>
    showFormula()
  }


  val b3 =
    button(
      "STEP BY STEP",
      110,
      -20,
      190,
      50,
      purple
    )

  b3.onMouseClick { (x, y) =>
    showSteps()
  }


  // ROW 2

  val b4 =
    button(
      "2D ANIMATION",
      -200,
      -90,
      190,
      50,
      orange
    )

  b4.onMouseClick { (x, y) =>
    showAnimation(0)
  }


  val b5 =
    button(
      "MARATHI",
      10,
      -90,
      190,
      50,
      pink
    )

  b5.onMouseClick { (x, y) =>
    showMarathi()
  }


  val b6 =
    button(
      "FULL ENGLISH",
      -95,
      -160,
      190,
      50,
      cyan
    )

  b6.onMouseClick { (x, y) =>
    showEnglish()
  }


  draw(
    txt(
      "FINAL ANSWER",
      -60,
      -215,
      yellow,
      0.65
    )
  )


  draw(
    txt(
      solution.answer,
      -170,
      -245,
      white,
      0.65
    )
  )
}


// ================================================================
// 19. SIMPLE ENGLISH
// ================================================================

def showSimple(): Unit = {

  header(
    "SIMPLE ENGLISH",
    darkGreen
  )


  draw(
    txt(
      "EASY EXPLANATION",
      -100,
      130,
      yellow,
      0.75
    )
  )


  lines(
    solution.simpleEnglish,
    -270,
    90,
    35,
    white,
    0.58
  )


  home()
}


// ================================================================
// 20. FORMULA
// ================================================================

def showFormula(): Unit = {

  header(
    "FORMULA",
    cm.rgb(25, 50, 90)
  )


  draw(
    txt(
      solution.topic,
      -90,
      125,
      yellow,
      0.75
    )
  )


  val f =
    Picture.rectangle(580, 90)

  f.setFillColor(card)
  f.setPenColor(cyan)
  f.setPenThickness(2)
  f.setPosition(-290, 20)

  draw(f)


  draw(
    txt(
      solution.formula,
      -245,
      52,
      white,
      0.68
    )
  )


  lines(
    List(
      "1. Identify the pattern.",
      "2. Identify A and B.",
      "3. Substitute.",
      "4. Simplify.",
      "5. Write the answer."
    ),
    -180,
    -30,
    35,
    cyan,
    0.65
  )


  home()
}


// ================================================================
// 21. STEP BY STEP
// ================================================================

def showSteps(): Unit = {

  header(
    "STEP-BY-STEP SOLUTION",
    cm.rgb(65, 42, 25)
  )


  lines(
    solution.steps,
    -275,
    130,
    27,
    white,
    0.47
  )


  home()
}


// ================================================================
// 22. MARATHI
// ================================================================

def showMarathi(): Unit = {

  header(
    "MARATHI EXPLANATION",
    cm.rgb(70, 35, 65)
  )


  draw(
    txt(
      "?????????? ????? ?????",
      -115,
      130,
      yellow,
      0.75
    )
  )


  lines(
    solution.marathi,
    -260,
    90,
    38,
    white,
    0.60
  )


  home()
}


// ================================================================
// 23. FULL ENGLISH
// ================================================================

def showEnglish(): Unit = {

  header(
    "FULL ENGLISH",
    cm.rgb(30, 40, 80)
  )


  draw(
    txt(
      "COMPLETE EXPLANATION",
      -115,
      130,
      yellow,
      0.72
    )
  )


  lines(
    solution.english,
    -270,
    90,
    38,
    white,
    0.58
  )


  home()
}


// ================================================================
// 24. 2D ANIMATION
// ================================================================

def showAnimation(n: Int): Unit = {

  cleari()
  setBackground(cm.rgb(15, 25, 55))


  draw(
    txt(
      "GANIT MITRA",
      -110,
      245,
      yellow,
      1.15
    )
  )


  draw(
    txt(
      solution.animationTitle,
      -135,
      210,
      white,
      0.7
    )
  )


  val box =
    Picture.rectangle(600, 230)

  box.setFillColor(card)
  box.setPenColor(cyan)
  box.setPenThickness(3)
  box.setPosition(-300, -50)

  draw(box)


  draw(
    txt(
      "STEP " +
      (n + 1) +
      " / " +
      solution.animationSteps.length,
      -60,
      135,
      yellow,
      0.7
    )
  )


  draw(
    txt(
      solution.animationSteps(n),
      -175,
      20,
      white,
      0.9
    )
  )


  // LEFT BALL

  val leftBall =
    Picture.circle(30)

  leftBall.setFillColor(blue)
  leftBall.setPenColor(white)
  leftBall.setPosition(-170, -20)

  draw(leftBall)


  // RIGHT BALL

  val rightBall =
    Picture.circle(30)

  rightBall.setFillColor(green)
  rightBall.setPenColor(white)
  rightBall.setPosition(110, -20)

  draw(rightBall)


  // PROGRESS

  val total =
    solution.animationSteps.length

  val progressWidth =
    500.0 *
    (n + 1).toDouble /
    total.toDouble


  val progress =
    Picture.rectangle(
      progressWidth,
      14
    )

  progress.setFillColor(green)
  progress.setPenColor(green)
  progress.setPosition(-250, -80)

  draw(progress)


  // PREVIOUS

  if (n > 0) {

    val previous =
      button(
        "PREVIOUS",
        -270,
        -170,
        170,
        50,
        gray
      )

    previous.onMouseClick { (x, y) =>
      showAnimation(n - 1)
    }
  }


  // NEXT

  if (
    n <
    solution.animationSteps.length - 1
  ) {

    val next =
      button(
        "NEXT",
        100,
        -170,
        170,
        50,
        blue
      )

    next.onMouseClick { (x, y) =>
      showAnimation(n + 1)
    }

  } else {

    val finish =
      button(
        "FINISH",
        100,
        -170,
        170,
        50,
        green
      )

    finish.onMouseClick { (x, y) =>
      showFinal()
    }
  }


  val dash =
    button(
      "DASHBOARD",
      -85,
      -240,
      170,
      42,
      purple
    )

  dash.onMouseClick { (x, y) =>
    showDashboard()
  }
}


// ================================================================
// 25. FINAL SCREEN
// ================================================================

def showFinal(): Unit = {

  cleari()
  setBackground(darkGreen)


  draw(
    txt(
      "LESSON COMPLETE!",
      -125,
      190,
      yellow,
      1.0
    )
  )


  draw(
    txt(
      "Excellent work, " +
      currentStudent.name,
      -130,
      150,
      white,
      0.75
    )
  )


  draw(
    txt(
      "QUESTION",
      -55,
      90,
      cyan,
      0.65
    )
  )


  draw(
    txt(
      solution.question,
      -150,
      55,
      white,
      0.82
    )
  )


  val answerBox =
    Picture.rectangle(600, 100)

  answerBox.setFillColor(card)
  answerBox.setPenColor(yellow)
  answerBox.setPenThickness(3)
  answerBox.setPosition(-300, -60)

  draw(answerBox)


  draw(
    txt(
      "FINAL ANSWER",
      -65,
      0,
      yellow,
      0.7
    )
  )


  draw(
    txt(
      solution.answer,
      -180,
      -35,
      white,
      0.70
    )
  )


  val again =
    button(
      "LEARN AGAIN",
      -210,
      -150,
      180,
      50,
      blue
    )

  again.onMouseClick { (x, y) =>
    showDifficulty()
  }


  val dashboard =
    button(
      "DASHBOARD",
      30,
      -150,
      180,
      50,
      purple
    )

  dashboard.onMouseClick { (x, y) =>
    showDashboard()
  }
}


// ================================================================
// 26. START APPLICATION
// ================================================================

showWelcome()