Code Sketch
Hill Sunset
Category: Art
size(935, 645)
clear()
setSpeed(fast)
val cb = canvasBounds
initRandomGenerator(-376991280140970457L)
def backdropFill = cm.linearMultipleGradient(
0, 0, 0, cb.height,
Seq(0, 0.6, 0.7, 1),
Seq(
ColorMaker.hsl(50, 0.8, 0.1),
ColorMaker.hsl(60, 1, 0.50),
ColorMaker.hsl(30, 1, 0.50),
ColorMaker.hsl(215, 0.7, 0.50),
),
false
)
def backdrop = Picture.rectangle(cb.width, cb.height)
.withPenColor(noColor)
.withFillColor(backdropFill)
.thatsTranslated(-cb.width / 2, -cb.height / 2)
def mountains = Picture {
setPenColor(noColor)
repeatFor(0 to 3) { i =>
// each t is less than the one in the previous iteration
val t = math.pow(1 - i / 5.0, 2)
// each closer/newer hill is darker
val r0 = t * 0.20 + 0.05
val g0 = t * 0.16 + 0.03
val b0 = t * 0.10 + 0.02
val r = (r0 * 255).toInt
val g = (g0 * 255).toInt
val b = (b0 * 255).toInt
// there are more undulations in closer/newer hills
val height = 6 + i * 3
val x0 = cb.x
// each closer/newer hill is lower down
val y0 = cb.height / 2 - 200 - i * 60
setPosition(x0, y0)
setFillColor(cm.rgb(r, g, b).lighten(0.1))
var y = y0
// to smoothen out the hill undulations
var prevRandom = 0
for (x <- rangeTill(cb.x, cb.x + cb.width, 10)) {
val currRandom = random(-height, height)
y = y + currRandom * 0.5 + prevRandom * 0.5
prevRandom = currRandom
lineTo(x, y)
}
lineTo(cb.x + cb.width, y)
lineTo(cb.x + cb.width, cb.y)
lineTo(cb.x, cb.y)
lineTo(x0, y0)
}
}
def sunRadius = 60
def sunFill = cm.radialMultipleGradient(
0, 0, 60,
Seq(0, 0.4, 0.5, 1),
Seq(
ColorMaker.hsl(60, 1.00, 0.95),
ColorMaker.hsl(40, 1.00, 0.85),
ColorMaker.hsla(30, 1.00, 0.85, 0.2),
ColorMaker.hsla(30, 1.00, 0.80, 0.05)
)
)
def sun = Picture.circle(60)
.withPenColor(noColor)
.withFillColor(sunFill)
def drawing = picStack(
backdrop,
sun.thatsTranslated(cb.width / 6.3, cb.height / 7),
mountains
)
draw(drawing)