Repository navigation
Expand file tree
/
Copy path035_arc_command.zig
More file actions
61 lines (53 loc) · 1.89 KB
/
Copy path035_arc_command.zig
File metadata and controls
61 lines (53 loc) · 1.89 KB
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
51
52
53
54
55
56
57
58
59
60
61
// SPDX-License-Identifier: W3C-20150513
//! Case: Renders arcs with native commands.
//!
//! The pie diagram demonstration has been taken from the SVG spec. It includes
//! material copied from or derived from
//! https://www.w3.org/TR/SVG11/paths.html#PathDataEllipticalArcCommands.
//! Copyright © 2011 World Wide Web Consortium.
//! https://www.w3.org/copyright/software-license-2023/
const std = @import("std");
const z2d = @import("z2d");
pub const filename = "035_arc_command";
pub fn render(io: std.Io, alloc: std.mem.Allocator, aa_mode: z2d.options.AntiAliasMode) !z2d.Surface {
const width = 400;
const height = 400;
var sfc = try z2d.Surface.initPixel(
.{ .rgb = .{ .r = 0xFF, .g = 0xFF, .b = 0xFF } }, // White
alloc,
width,
height,
);
var context = z2d.Context.init(io, alloc, &sfc);
defer context.deinit();
context.setSourceToPixel(.{ .rgb = .{ .r = 0xFF, .g = 0x00, .b = 0x00 } });
context.setAntiAliasingMode(aa_mode);
context.setLineWidth(5);
try context.moveTo(200, 200);
try context.arcNegative(200, 200, 150, std.math.pi, std.math.pi * 1.5);
try context.closePath();
try context.fill();
context.pattern = .{
.opaque_pattern = .{
.pixel = .{ .rgb = .{ .r = 0x00, .g = 0x00, .b = 0xFF } }, // Blue for stroke
},
};
try context.stroke();
context.resetPath();
try context.moveTo(175, 175);
try context.arc(175, 175, 150, std.math.pi, std.math.pi * 1.5);
try context.closePath();
context.pattern = .{
.opaque_pattern = .{
.pixel = .{ .rgb = .{ .r = 0xFF, .g = 0xFF, .b = 0x00 } }, // Yellow for fill
},
};
try context.fill();
context.pattern = .{
.opaque_pattern = .{
.pixel = .{ .rgb = .{ .r = 0x00, .g = 0x00, .b = 0xFF } }, // Blue for stroke
},
};
try context.stroke();
return sfc;
}