summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralaric <alaric@netmythos.org>2024-03-29 19:43:15 -0700
committeralaric <alaric@netmythos.org>2024-03-29 19:43:15 -0700
commita9f46fb682935d9637d4466dbb22aad2475859b7 (patch)
tree364e7b2c9cbe548116775364e22d8446fce5ec0f
parent4a79ad802ffcd37dab3a461fb5423ce2d8b4c116 (diff)
downloadcolordots-a9f46fb682935d9637d4466dbb22aad2475859b7.tar.gz
colordots-a9f46fb682935d9637d4466dbb22aad2475859b7.zip
Add colors
-rw-r--r--src/wasm_ttd.zig26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/wasm_ttd.zig b/src/wasm_ttd.zig
index 374986f..03d5941 100644
--- a/src/wasm_ttd.zig
+++ b/src/wasm_ttd.zig
@@ -149,8 +149,10 @@ pub fn pow(comptime T: type, base: T, exp: T) T {
const Star = struct {
dist: f32,
+ pdist: f32,
angle: f32,
initial_len: f32,
+ col: Color,
};
const max_dist = 100;
@@ -182,6 +184,12 @@ export fn init() void {
s.angle = lerp(0, 2 * pi, rng.randFloat(f32));
s.initial_len = lerp(0, height / 2, rng.randFloat(f32));
s.dist = max_dist;
+ s.pdist = max_dist;
+ s.col = .{
+ .r = rng.randFloat(f32),
+ .g = rng.randFloat(f32),
+ .b = rng.randFloat(f32),
+ };
}
//const msg = "Welcome to TBD";
//consoleLog(msg.ptr, msg.len);
@@ -337,17 +345,25 @@ export fn update(elapsed_time: f32) void {
const width = getScreenWidth();
const height = getScreenHeight();
for (stars[0..sub_count]) |*s| {
+ s.pdist = s.dist;
s.dist -= speed;
+ const plen = lerp(1000, s.initial_len, s.pdist / max_dist);
+ const psx = (@cos(s.angle) * plen) + width * 0.5;
+ const psy = (@sin(s.angle) * plen) + height * 0.5;
+
const len = lerp(1000, s.initial_len, s.dist / max_dist);
const sx = (@cos(s.angle) * len) + width * 0.5;
const sy = (@sin(s.angle) * len) + height * 0.5;
const scale = lerp(8, 0, s.dist / max_dist);
- drawCircle(.{ sx, sy }, scale, Color.white);
+
+ drawLine(&.{ .{ psx, psy }, .{ sx, sy } }, s.col);
+ drawCircle(.{ sx, sy }, scale, s.col);
if (sx < 0 or sx > 1280 or sy < 0 or sy > height) {
s.angle = lerp(0, 2 * pi, rng.randFloat(f32));
s.initial_len = lerp(0, 360, rng.randFloat(f32));
s.dist = max_dist;
+ s.pdist = max_dist;
}
}
}
@@ -433,6 +449,14 @@ const TriangleGroup = struct {
}
};
+fn drawLine(points: *const [2][2]f32, col: Color) void {
+ setDrawColor(col);
+ webgl.uniformMatrix3fv(mat_uniform_location, &Mat3.identity.data);
+ webgl.bufferData(.array_buffer, @ptrCast(points), 4, .dynamic_draw);
+
+ webgl.drawArrays(.lines, 0, 2);
+}
+
fn drawTri(points: *const [3][2]f32) void {
//webgl.useProgram(prog);
//webgl.uniform1i(tex_uniform_location, 0);