-
Notifications
You must be signed in to change notification settings - Fork 0
/
029_stroke_lines_round_caps_tolerance.zig
50 lines (40 loc) · 1.33 KB
/
029_stroke_lines_round_caps_tolerance.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// SPDX-License-Identifier: 0BSD
// Copyright © 2024 Chris Marchesi
//! Case: Renders multiple lines, round-capped at varying levels of tolerance.
const debug = @import("std").debug;
const mem = @import("std").mem;
const z2d = @import("z2d");
pub const filename = "029_stroke_lines_round_caps_tolerance";
pub fn render(alloc: mem.Allocator, aa_mode: z2d.options.AntiAliasMode) !z2d.Surface {
const width = 300;
const height = 300;
const sfc = try z2d.Surface.init(.image_surface_rgb, alloc, width, height);
var context: z2d.Context = .{
.surface = sfc,
.pattern = .{
.opaque_pattern = .{
.pixel = .{ .rgb = .{ .r = 0xFF, .g = 0xFF, .b = 0xFF } }, // White on black
},
},
.line_cap_mode = .round,
.line_join_mode = .round,
.line_width = 30,
.anti_aliasing_mode = aa_mode,
};
var path = z2d.Path.init(alloc);
defer path.deinit();
try path.moveTo(30, 50);
try path.lineTo(270, 50);
try context.stroke(alloc, path);
context.tolerance = 3;
path.reset();
try path.moveTo(30, 150);
try path.lineTo(270, 150);
try context.stroke(alloc, path);
context.tolerance = 10;
path.reset();
try path.moveTo(30, 250);
try path.lineTo(270, 250);
try context.stroke(alloc, path);
return sfc;
}