Assign entities random RGB colors

This commit is contained in:
Jared Tyler Miller 2025-12-15 00:14:02 -05:00 committed by Jared Miller
parent ee1ba2e87d
commit 72e29dbd33
3 changed files with 16 additions and 5 deletions

View file

@ -104,12 +104,18 @@ pub fn spawnAtEdge(rng: *std.Random) Entity {
const vx = (dx / dist) * ENTITY_SPEED; const vx = (dx / dist) * ENTITY_SPEED;
const vy = (dy / dist) * ENTITY_SPEED; const vy = (dy / dist) * ENTITY_SPEED;
// random RGB color
const r = rng.int(u8);
const g = rng.int(u8);
const b = rng.int(u8);
const color: u32 = (@as(u32, r) << 16) | (@as(u32, g) << 8) | @as(u32, b);
return .{ return .{
.x = x, .x = x,
.y = y, .y = y,
.vx = vx, .vx = vx,
.vy = vy, .vy = vy,
.color = 0x00FFFF, // cyan .color = color,
}; };
} }

View file

@ -117,7 +117,7 @@ fn createCircleTexture() ?rl.Texture2D {
@divTrunc(TEXTURE_SIZE, 2), @divTrunc(TEXTURE_SIZE, 2),
@divTrunc(TEXTURE_SIZE, 2), @divTrunc(TEXTURE_SIZE, 2),
ENTITY_RADIUS, ENTITY_RADIUS,
CYAN, rl.Color{ .r = 255, .g = 255, .b = 255, .a = 255 }, // white, tinted per-entity
); );
rl.endTextureMode(); rl.endTextureMode();
@ -183,9 +183,14 @@ pub fn main() !void {
rl.gl.rlSetTexture(circle_texture.id); rl.gl.rlSetTexture(circle_texture.id);
rl.gl.rlBegin(rl.gl.rl_quads); rl.gl.rlBegin(rl.gl.rl_quads);
rl.gl.rlColor4ub(255, 255, 255, 255); // white tint
for (entities.items[0..entities.count]) |entity| { for (entities.items[0..entities.count]) |entity| {
// extract RGB from entity color (0xRRGGBB)
const r: u8 = @truncate(entity.color >> 16);
const g: u8 = @truncate(entity.color >> 8);
const b: u8 = @truncate(entity.color);
rl.gl.rlColor4ub(r, g, b, 255);
const x1 = entity.x - half; const x1 = entity.x - half;
const y1 = entity.y - half; const y1 = entity.y - half;
const x2 = entity.x + half; const x2 = entity.x + half;

View file

@ -8,8 +8,8 @@ const sandbox = @import("sandbox.zig");
// config - tweak these // config - tweak these
// ============================================================================= // =============================================================================
pub const font_size: f32 = 14; pub const font_size: f32 = 16;
pub const small_font_size: f32 = 12; pub const small_font_size: f32 = 16;
pub const line_height: f32 = 20; pub const line_height: f32 = 20;
pub const small_line_height: f32 = 18; pub const small_line_height: f32 = 18;
pub const padding: f32 = 10; pub const padding: f32 = 10;