Skip to content

Instantly share code, notes, and snippets.

@peterhellberg
Created November 15, 2023 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterhellberg/a5f36098c3c68c5b0a1370f101557c6e to your computer and use it in GitHub Desktop.
Save peterhellberg/a5f36098c3c68c5b0a1370f101557c6e to your computer and use it in GitHub Desktop.
tic: Pixel position and color using the mouse
const tic = @import("tic");
fn pp(c: u8) void {
var m: tic.MouseData = .{};
tic.mouse(&m);
if (m.left) {
const x = m.x - 1;
const y = m.y - 1;
const l = tic.printf("{}x{}", .{ x, y }, 0, 0, .{ .color = 0, .small_font = true });
const p = tic.getpix(x, y);
if (x < 206) {
_ = tic.printf("{}x{}", .{ x, y }, x + 7, y + 3, .{ .color = c, .small_font = true });
tic.rectb(x + 6, y + 9, l, 9, p - 1);
tic.rect(x + 7, y + 10, l - 2, 7, p);
_ = tic.printf("{}", .{p}, x + 8, y + 11, .{ .color = p - 1, .small_font = true });
} else {
_ = tic.printf("{}x{}", .{ x, y }, x - l + 1, y + 3, .{ .color = c, .small_font = true });
tic.rectb(x - l, y + 9, l, 9, p - 1);
tic.rect(x - l + 1, y + 10, l - 2, 7, p);
_ = tic.printf("{}", .{p}, x - l + 2, y + 11, .{ .color = p - 1, .small_font = true });
}
tic.rectb(x - 1, y - 1, 3, 3, c);
tic.tracef(" tic.pix({}, {}, {});", .{ m.x, m.y, p });
}
}
export fn TIC() void {
tic.cls(6);
if (tic.btn(4)) tic.exit();
pp(4);
}
@peterhellberg
Copy link
Author



Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment