Assign entities random RGB colors
This commit is contained in:
parent
ee1ba2e87d
commit
72e29dbd33
3 changed files with 16 additions and 5 deletions
|
|
@ -104,12 +104,18 @@ pub fn spawnAtEdge(rng: *std.Random) Entity {
|
|||
const vx = (dx / 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 .{
|
||||
.x = x,
|
||||
.y = y,
|
||||
.vx = vx,
|
||||
.vy = vy,
|
||||
.color = 0x00FFFF, // cyan
|
||||
.color = color,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ fn createCircleTexture() ?rl.Texture2D {
|
|||
@divTrunc(TEXTURE_SIZE, 2),
|
||||
@divTrunc(TEXTURE_SIZE, 2),
|
||||
ENTITY_RADIUS,
|
||||
CYAN,
|
||||
rl.Color{ .r = 255, .g = 255, .b = 255, .a = 255 }, // white, tinted per-entity
|
||||
);
|
||||
rl.endTextureMode();
|
||||
|
||||
|
|
@ -183,9 +183,14 @@ pub fn main() !void {
|
|||
|
||||
rl.gl.rlSetTexture(circle_texture.id);
|
||||
rl.gl.rlBegin(rl.gl.rl_quads);
|
||||
rl.gl.rlColor4ub(255, 255, 255, 255); // white tint
|
||||
|
||||
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 y1 = entity.y - half;
|
||||
const x2 = entity.x + half;
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ const sandbox = @import("sandbox.zig");
|
|||
// config - tweak these
|
||||
// =============================================================================
|
||||
|
||||
pub const font_size: f32 = 14;
|
||||
pub const small_font_size: f32 = 12;
|
||||
pub const font_size: f32 = 16;
|
||||
pub const small_font_size: f32 = 16;
|
||||
pub const line_height: f32 = 20;
|
||||
pub const small_line_height: f32 = 18;
|
||||
pub const padding: f32 = 10;
|
||||
|
|
|
|||
Loading…
Reference in a new issue