Code Sketch
Polar Bear
Category: Art
// polar bear - using pic.thatsXX transforms
// works with Kojo 2.9.18 and later
// This program uses image PB1.png, which is available at:
// https://drive.google.com/file/d/1mqSthvmWl7nE8WidgU9YKaPHFsx3nEvQ/view
// Download the above image and put it in your Downloads folder
// before running the code
def mountain(n: Int) = Picture {
beginShape()
curveVertexRt(-300, 0)
curveVertexRt(-300, 0)
curveVertexRt(n, 100)
curveVertexRt(n, 0)
curveVertexRt(n, 0)
endShape()
}
def mountains(n: Int, size: Double): Picture = {
if (n == 1) {
mountain(150)
.withFillColor(mountainclr)
.withPenColor(noColor)
}
else {
picStack(
mountain(120)
.withPenColor(noColor)
.withFillColor(mountainclr),
mountains(n - 1, size)
.thatsTranslated(200, 0)
)
}
}
cleari()
val assetsDir = "~/Downloads"
val bg = Picture.image(s"$assetsDir/PB1.png")
val PB1 = trans(-1000 + 190, -550) * scale(2) -> bg
val sky = cm.linearGradient(0, 100, ColorMaker.hsl(201, 0.59, 0.94), 0, 200, ColorMaker.hsl(240, 1.00, 0.78), false)
val sunclr = cm.radialGradient(0, 0, cm.white, 70, ColorMaker.hsl(240, 1.00, 0.78), false)
val sunclr2 = cm.radialGradient(0, 0, cm.white, 70, ColorMaker.hsl(194, 0.43, 0.71), false)
val mountainclr = cm.linearGradient(-55, 40, ColorMaker.hsl(120, 0.22, 0.89), 0, 0, ColorMaker.hsl(120, 0.06, 0.52), false)
val pic = picStack(
Picture.rectangle(850, 380)
.thatsTranslated(-300, -380)
.withPenColor(noColor)
.withFillColor(ColorMaker.hsl(194, 0.43, 0.71)),
Picture.rectangle(850, 380)
.thatsTranslated(-300, 0)
.withPenColor(noColor)
.withFillColor(sky),
mountains(3, 10)
.thatsTranslated(0, -4)
.withPenColor(noColor)
.withPenThickness(0)
.withBlurring(30)
.withFading(110)
.withFlippedY,
Picture.circle(75)
.withPenColor(noColor)
.thatsTranslated(0, 239)
.withFillColor(sunclr2)
.withFading(220)
.withFlippedY,
Picture.circle(75)
.withPenColor(noColor)
.thatsTranslated(0, 270)
.withFillColor(sunclr),
mountains(3, 10),
PB1
)
drawCentered(pic)