-
Notifications
You must be signed in to change notification settings - Fork 1
/
010_stroke_trapezoid.zig
33 lines (25 loc) · 1.04 KB
/
010_stroke_trapezoid.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
// SPDX-License-Identifier: 0BSD
// Copyright © 2024 Chris Marchesi
//! Case: Renders and strokes a trapezoid on a 300x300 surface.
const mem = @import("std").mem;
const z2d = @import("z2d");
pub const filename = "010_stroke_trapezoid";
pub fn render(alloc: mem.Allocator, aa_mode: z2d.options.AntiAliasMode) !z2d.Surface {
const width = 300;
const height = 300;
var sfc = try z2d.Surface.init(.image_surface_rgb, alloc, width, height);
var context = try z2d.Context.init(alloc, &sfc);
defer context.deinit();
context.setSource(.{ .rgb = .{ .r = 0xFF, .g = 0xFF, .b = 0xFF } });
context.setAntiAliasingMode(aa_mode);
const margin_top = 89;
const margin_bottom = 50;
const margin_y = 100;
try context.moveTo(0 + margin_top, 0 + margin_y);
try context.lineTo(width - margin_top - 1, 0 + margin_y);
try context.lineTo(width - margin_bottom - 1, height - margin_y - 1);
try context.lineTo(0 + margin_bottom, height - margin_y - 1);
try context.close();
try context.stroke();
return sfc;
}