Last active
May 17, 2025 11:28
-
-
Save Hammer2900/ccb22090f74d5ce49e3b446ffca382d5 to your computer and use it in GitHub Desktop.
rain drops lobster
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std | |
import vec | |
import color | |
import gl | |
// Window settings | |
let SCREEN_WIDTH = 700.0 | |
let SCREEN_HEIGHT = 700.0 | |
let WINDOW_TITLE = "Rain" | |
// Colors (Lobster uses 0.0-1.0 for color components) | |
let BACKGROUND_COLOR = float4 { 25.0/255.0, 35.0/255.0, 55.0/255.0, 1.0 } | |
let RAIN_BASE_COLOR_RGB = float3 { 200.0/255.0, 200.0/255.0, 220.0/255.0 } | |
// Rain parameters | |
let MIN_DROPS = 50 | |
let MAX_DROPS = 100 | |
let MIN_DROP_LENGTH = 10.0 | |
let MAX_DROP_LENGTH = 20.0 | |
let MIN_DROP_SPEED = 100.0 | |
let MAX_DROP_SPEED = 300.0 | |
let MIN_ALPHA = 128.0 / 255.0 // 50% opacity | |
let MAX_ALPHA = 178.0 / 255.0 // 70% opacity | |
class Drop: | |
x:float = rnd_float() * SCREEN_WIDTH | |
y:float = rnd_float() * -SCREEN_HEIGHT | |
length:float = rnd_float() * (MAX_DROP_LENGTH - MIN_DROP_LENGTH) + MIN_DROP_LENGTH | |
speed:float = rnd_float() * (MAX_DROP_SPEED - MIN_DROP_SPEED) + MIN_DROP_SPEED | |
color_with_alpha:float4 = float4 { RAIN_BASE_COLOR_RGB.x, RAIN_BASE_COLOR_RGB.y, RAIN_BASE_COLOR_RGB.z, rnd_float() * (MAX_ALPHA - MIN_ALPHA) + MIN_ALPHA } | |
def init_drop(): | |
x = rnd_float() * SCREEN_WIDTH | |
y = rnd_float() * -SCREEN_HEIGHT | |
length = rnd_float() * (MAX_DROP_LENGTH - MIN_DROP_LENGTH) + MIN_DROP_LENGTH | |
speed = rnd_float() * (MAX_DROP_SPEED - MIN_DROP_SPEED) + MIN_DROP_SPEED | |
color_with_alpha = float4 { RAIN_BASE_COLOR_RGB.x, RAIN_BASE_COLOR_RGB.y, RAIN_BASE_COLOR_RGB.z, rnd_float() * (MAX_ALPHA - MIN_ALPHA) + MIN_ALPHA } | |
def update(delta_time:float): | |
y += speed * delta_time | |
if y > SCREEN_HEIGHT: | |
init_drop() | |
def draw(): | |
gl.color(color_with_alpha) | |
gl.line(float2 { x, y }, float2 { x, y + length }, 1.0) | |
def main(): | |
fatal(gl.window(WINDOW_TITLE, int(SCREEN_WIDTH), int(SCREEN_HEIGHT))) | |
gl.set_target_delta_time(1.0 / 60.0) | |
let num_drops = rnd(MAX_DROPS - MIN_DROPS + 1) + MIN_DROPS | |
var drops:[Drop] = [] | |
for(num_drops): | |
drops.push(Drop {}) | |
while gl.frame() and gl.button("escape") != 1: | |
let delta_time = gl.delta_time() | |
for(drops) drop: | |
drop.update(delta_time) | |
gl.clear(BACKGROUND_COLOR) | |
for(drops) drop: | |
drop.draw() | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment