Home / Coracle / Drawings / Ports / Snow
Ported to Coracle from www.dwitter.net/d/26605
import coracle.Colour
import coracle.Drawing
import coracle.Math.map
import kotlin.math.cos
import kotlin.math.pow
/*
Adapted from https://www.dwitter.net/d/26605
*/
class SnowDrawing: Drawing() {
val count = 800
val bg = Colour(0x1d1d1d)
val white = Colour(0xffffff)
override fun setup() {
size(700, 500)
noStroke()
}
override fun draw() {
background(bg)
val t = frame/100.0
repeat(count){ i ->
val x = ((i.toFloat().pow(3)) % 32) - 16 + cos(i + t * 2.0)
val y = ((((i.toFloat().pow(3)) % 23) + t * 2) % 13) - 9
val z = i/180.0
val alpha2 = map(i.toFloat(), 0f, count.toFloat(), 1f, 0.3f)
fill(white, alpha2)
val r = map(i.toFloat(), 0f, count.toFloat(), 15f, 1f).toInt()
val wX = (width/2) + 100 * (x/z)
val wY = (height/1.5) + 200 * (y/z)
if (wX >= r && wX <= width + r && wY >= -r && wY <= height + r) {
circle(wX, wY, r)
}
}
}
}