1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
pub const Color = packed struct(u32) {
const Self = @This();
blue: u8,
green: u8,
red: u8,
_padding: u8 = 0x0,
pub fn mix(self: *const Self, other: *const Self, factor: f64) Self {
const inverse = 1 - factor;
return Self {
.red = @intFromFloat(
@as(f64, @floatFromInt(self.red)) * inverse + @as(f64, @floatFromInt(other.red)) * factor
),
.green = @intFromFloat(
@as(f64, @floatFromInt(self.green)) * inverse + @as(f64, @floatFromInt(other.green)) * factor
),
.blue = @intFromFloat(
@as(f64, @floatFromInt(self.blue)) * inverse + @as(f64, @floatFromInt(other.blue)) * factor
),
};
}
};
|