Code Sketch


Online pooja
By: Soham Dabral
Category: Programming
// This program uses image om.png, bell.png, Rose.png and petal.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 Temple bell.mp3, Shiva.mp3 music from above link and put it in your Music folder
// before running this code

def shivLingaClr = cm.linearGradient(0, 0, cm.blue, 100, 0, cm.black, true)
def rectangleClr = cm.linearGradient(0, 100, cm.gray, 0, 0, cm.black, true)
def textClr = cm.linearGradient(0, 0, cm.red, 200, 0, ColorMaker.hsl(24, 0.99, 0.45), true)
def textClr2 = cm.linearGradient(0, 0, cm.red, 100, 0, blue, true)
def rectangle = trans(-90, -50) -> Picture.rectangle(300, 50).withFillColor(rectangleClr).withPenColor(noColor)
def msg = trans(-175, -200) * scale(1.2) -> Picture.text("Click on the above icons to start the Pooja.", 20).withPenColor(textClr)
def yProp(s: Seq[Double]) = s(0)
def scaleProp(s: Seq[Double]) = s(0)

val om = trans(-25, -200) * scale(0.7) -> Picture.image("~/Downloads/Om.png")
val bell = trans(320, -170) * scale(0.5) -> Picture.image("~/Downloads/Bell.png")
val bell2 = trans(-320, -170) * scale(0.5) -> Picture.image("~/Downloads/Bell.png")
val petals = Picture.image("~/Downloads/petal.png")
val rose = trans(-190, -200) * scale(0.3) -> Picture.image("~/Downloads/Rose.png")
val anim = Transition(4, Seq(500), Seq(-30), easing.Linear, petalAnimation, false)
val kf2 = KeyFrames(0 -> Seq(0.7), 50 -> Seq(0.5), 100 -> Seq(0.7))
val anim2 = Timeline(2, kf2, easing.QuadInOut, makeflame, true)

def shivlingaStructure = Picture {
    forward(200)
    right(180, 90)
    forward(200)
    right()
    forward(180)
}

def whiteLine = Picture {
    left()
    right(180, 10)
    forward(150)
    right(180, 10)
    forward(150)
}

def fullTemple = Picture {
    left()
    forward(700)
    right()
    forward(500)
    right()
    forward(1940)
    right()
    forward(500)
    right()
    forward(700)
    right()
    forward(100)
    left(90, 90)
    right()
    left(90, 90)
    right()
    left(180, 90)
    right()
    left(90, 90)
    right()
    left(90, 90)
    forward(100)
}

def petalAnimation(s: Seq[Double]) = {
    trans(0, yProp(s)) * scale(0.75) -> petals
}

def shivLinga = scale(0.65) * trans(-10, 0) -> picStack(
    fillColor(shivLingaClr) * penColor(noColor) -> shivlingaStructure,
    fillColor(white) * penColor(white) * scale(0.7) * trans(50, 250) -> whiteLine,
    fillColor(white) * penColor(white) * scale(0.7) * trans(50, 215) -> whiteLine,
    fillColor(white) * penColor(white) * scale(0.7) * trans(50, 180) -> whiteLine,
    fillColor(cm.red) * penColor(noColor) * trans(85, 155) -> Picture.circle(15)
)

def makeflame(s: Seq[Double]) = {
    trans(250, -125) * scale(scaleProp(s)) -> flame
}

val flame = Picture {
    setFillColor(cm.linearGradient(0, 0, cm.red, 0, 130, cm.yellow))
    setPenColor(noColor)
    setPenThickness(3)
    left(45)
    right(90, 100)
    right(90)
    right(90, 100)
}

val diya = trans(250, -125) * scale(0.5) -> Picture {
    setFillColor(cm.linearGradient(0, 10, cm.red, 0, -25, cm.brown))
    setPenThickness(2)
    setPenColor(cm.black)
    left(120)
    right(60, 100)
    right(180)
    right(30)
    left(120, 115)
    right(180)
    right(30)
    right(60, 100)
}

val temple = trans(-25, -40) -> picStack(
    penWidth(3) * penColor(textClr2) * fillColor(textClr2) * trans(-195, 10) -> fullTemple,
    penWidth(3) * penColor(textClr2) * trans(-195, 0) -> fullTemple,
    penWidth(3) * penColor(textClr2) * trans(-195, -10) -> fullTemple
)

cleari()
clearOutput()
setBackground(cm.silver)
toggleFullScreenCanvas()
draw(temple, shivLinga, rectangle, diya, rose, bell, bell2, om, msg)

rose.onMouseClick { (x, y) =>
    run(anim.repeatedForever)
}

diya.onMouseClick { (x, y) =>
    run(anim2.repeatedForever)
}

bell.onMouseClick { (x, y) =>
    playMp3("~/Music/Temple Bell.mp3")
}

bell2.onMouseClick { (x, y) =>
    playMp3("~/Music/Temple Bell.mp3")
}

om.onMouseClick { (x, y) =>
    playMp3("~/Music/Shiva.mp3")
}