Code Sketch


Casino Royale based on Mouse click
By: Soham Dabral
Category: Programming
// This program uses image download.png, which is available at:
//https://drive.google.com/drive/folders/1vwnFu5JBQpdhNkrewq27w943sQuE3Wtw
// Download the above image and put it in your Downloads folder 
//as well as download the music from above link and put it in your Music folder
// before running this code

cleari()
clearOutput()
setBackground(white)
toggleFullScreenCanvas()

def lgclr = cm.linearGradient(0, 120, ColorMaker.hsl(0, 0.00, 0.61), 0, 0, ColorMaker.hsl(0, 0.00, 0.07), false)
def picCircle = Picture.circle(5)
def lines = Picture.rectangle(100, 600)
def square = Picture.rectangle(100, 100)
def hueProp(s: Seq[Double]) = s(0)

def msg(s: Seq[Double]) = {
    picCol(
        penColor(cm.black) * trans(-50, -100) -> text,
        trans(-225, -30) -> step1,
        trans(-225, -30) -> step2,
        trans(-225, -30) -> step3,
        trans(-105, -30) * penColor(cm.hsl(hueProp(s), 1, 0.5)) -> goodLuck
    )
}

def numberx(s: Seq[Double]) = {
    numbers
}

def light(s: Seq[Double]) = {
    trans(-50, -46) * fillColor(cm.hsl(hueProp(s), 1, 0.5)) -> bulbsAndSquares
}

def randomNumber1 = {
    setPenFont(Font("Arial Bold", 50))
    random(0, 10)
}

def randomNumber2 = {
    setPenFont(Font("Arial Bold", 50))
    random(0, 10)
}

def randomNumber3 = {
    setPenFont(Font("Arial Bold", 50))
    random(0, 10)
}

def text = Picture {
    setPenFont(Font("Arial Black", 20))
    write("Rules")
}

def step2 = Picture {
    setPenFont(Font("Algerian", 20))
    setPenColor(ColorMaker.hsl(51, 0.98, 0.34))
    write("Step2 ")
    right()
    hop(70)
    left()
    setPenColor(ColorMaker.hsl(206, 1.00, 0.28))
    setPenFont(Font("Arial", 20))
    write("- Then click on the Casino Royale logo above.")
}

def step1 = Picture {
    setPenFont(Font("Algerian", 20))
    setPenColor(cm.deepPink)
    write("Step1 ")
    right()
    hop(70)
    left()
    setPenColor(ColorMaker.hsl(206, 1.00, 0.28))
    setPenFont(Font("Arial", 20))
    write("- Think of a number between 000 to 999.")
}

def step3 = Picture {
    setPenFont(Font("Algerian", 20))
    setPenColor(cm.deepSkyBlue)
    write("Step3 ")
    right()
    hop(70)
    left()
    setPenColor(ColorMaker.hsl(206, 1.00, 0.28))
    setPenFont(Font("Arial", 20))
    write("- If the number you think comes on the screen you win otherwise you lose.")
}

def goodLuck = Picture {
    setPenFont(Font("Algerian", 40))
    write("Good Luck!!!")
}

def circles(n: Int, size: Double): Picture = {

    if (n == 1) {
        fillColor(green) * penColor(noColor) -> picCircle
    }

    else {
        picStack(
            fillColor(green) * penColor(noColor) -> picCircle,
            fillColor(green) * penColor(noColor) * trans(size - 5, 0) -> circles(n - 1, size)
        )
    }
}

def bulbs(n: Int, size: Double): Picture = {

    if (n == 1) {
        fillColor(green) * penColor(noColor) -> picCircle
    }

    else {
        picStack(
            fillColor(green) * penColor(noColor) -> picCircle,
            fillColor(green) * penColor(noColor) * trans(0, size - 75) -> bulbs(n - 1, size)
        )
    }
}

val startButton = Picture.image("~/Downloads/download.png")
val casinoRoyales = trans(-140, 55) -> Picture.image("~/Downloads/download.png")
val num = Transition(5, Seq(), Seq(), easing.Linear, numberx, false)
val lights = Transition(3, Seq(0), Seq(360), easing.Linear, light, false)
val gL = Transition(3, Seq(0), Seq(360), easing.Linear, msg, false)

def trisq = penThickness(6) * penColor(cm.darkBlue) -> picStack(
    fillColor(lgclr) * trans(-100, 0) -> square,
    fillColor(lgclr) -> square,
    fillColor(lgclr) * trans(100, 0) -> square
)

def bulbsAndSquares = picStack(
    trans(-90, -10) -> circles(12, 30),
    trans(-90, 100) -> circles(12, 30),
    trans(-100, -5) -> bulbs(5, 100),
    trans(100, -5) -> bulbs(5, 100),
    trans(0, -5) -> bulbs(5, 100),
    trans(200, -5) -> bulbs(5, 100)
)

def numbers = picStack(
    penColor(white) * trans(-20, 40) -> Picture.text(randomNumber1, 70),
    penColor(white) * trans(-120, 40) -> Picture.text(randomNumber2, 70),
    penColor(white) * trans(80, 40) -> Picture.text(randomNumber3, 70)
)

def trilines = fillColor(black) * penColor(noColor) -> picStack(
    trans(-150, -650) -> lines,
    trans(-50, -650) -> lines,
    trans(50, -650) -> lines
)

drawCentered(startButton)
run(gL.repeatedForever)
playMp3("~/Music/Undertale.mp3")

startButton.onMouseClick { (x, y) =>
    cleari()
    setBackground(white)
    drawCentered(trisq)
    draw(casinoRoyales)
    run(gL.repeatedForever)
    run(num)
    run(lights.repeatedForever)
}