-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initiated migration to the new and improved API (check README)
- Loading branch information
1 parent
c9cbade
commit d9ddf3e
Showing
14 changed files
with
457 additions
and
353 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,43 @@ | ||
const std = @import("std"); | ||
|
||
pub fn build(b: *std.Build) void { | ||
const lib_version = std.SemanticVersion.parse("0.1.4") catch unreachable; | ||
const target = b.standardTargetOptions(.{}); | ||
const optimize = b.standardOptimizeOption(.{}); | ||
const target = b.standardTargetOptions(.{}); | ||
|
||
const lib = b.addStaticLibrary(.{ | ||
.name = "prism", | ||
.root_source_file = .{ .path = "src/prism.zig" }, | ||
.target = target, | ||
.optimize = optimize, | ||
.version = lib_version, | ||
_ = b.addModule("prism", .{ | ||
.source_file = .{ .path = "src/prism.zig" }, | ||
}); | ||
|
||
const lib_shared = b.addSharedLibrary(.{ | ||
const lib = b.addStaticLibrary(.{ | ||
.name = "prism", | ||
.root_source_file = .{ .path = "src/prism.zig" }, | ||
.target = target, | ||
.optimize = optimize, | ||
.version = lib_version, | ||
}); | ||
|
||
const prism_mod = b.createModule(.{ .source_file = .{ .path = "src/prism.zig" } }); | ||
|
||
const shades = b.addExecutable(.{ | ||
.name = "shades", | ||
.root_source_file = .{ .path = "src/shades.zig" }, | ||
.target = target, | ||
.optimize = optimize, | ||
}); | ||
|
||
const rainbow = b.addExecutable(.{ | ||
.name = "rainbow", | ||
.root_source_file = .{ .path = "src/rainbow.zig" }, | ||
.target = target, | ||
.optimize = optimize, | ||
}); | ||
rainbow.addModule("prism", prism_mod); | ||
shades.addModule("prism", prism_mod); | ||
|
||
b.installArtifact(lib); | ||
b.installArtifact(lib_shared); | ||
b.installArtifact(rainbow); | ||
b.installArtifact(shades); | ||
|
||
const test_step = b.step("test", "Run tests"); | ||
const main_tests = b.addTest(.{ | ||
.root_source_file = .{ .path = "src/tests.zig" }, | ||
.name = "prism-tests", | ||
.root_source_file = .{ .path = "src/prism.zig" }, | ||
.target = target, | ||
.optimize = optimize, | ||
}); | ||
|
||
const run_main_tests = b.addRunArtifact(main_tests); | ||
const test_step = b.step("test", "Run library tests"); | ||
test_step.dependOn(&run_main_tests.step); | ||
main_tests.linkLibrary(lib); | ||
test_step.dependOn(&b.addRunArtifact(main_tests).step); | ||
|
||
const examples = [_]*std.Build.Step.Compile{ | ||
b.addExecutable(.{ | ||
.name = "madness", | ||
.root_source_file = .{ .path = "src/examples/madness.zig" }, | ||
.target = target, | ||
.optimize = optimize, | ||
}), | ||
}; | ||
|
||
for (examples) |e| { | ||
e.addModule("prism", b.modules.get("prism").?); | ||
e.linkLibrary(lib); | ||
b.installArtifact(e); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.{ | ||
.name = "prism", | ||
.version = "0.2.0", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const std = @import("std"); | ||
const prism = @import("prism"); | ||
|
||
pub fn main() !void { | ||
var alloc = std.heap.ArenaAllocator.init(std.heap.page_allocator); | ||
defer alloc.deinit(); | ||
|
||
const args = try std.process.argsAlloc(alloc.allocator()); | ||
defer std.process.argsFree(alloc.allocator(), args); | ||
|
||
var stdout = std.io.getStdOut().writer(); | ||
var madness_text: []const u8 = "MADNESS!"; | ||
|
||
if (args.len > 1) { | ||
for (args[1..]) |arg| { | ||
madness_text = arg; | ||
} | ||
} | ||
|
||
var rng = std.rand.DefaultPrng.init(@as( | ||
u64, | ||
@truncate(@as(u128, @bitCast(std.time.nanoTimestamp()))), | ||
)); | ||
|
||
while (true) { | ||
const rgb = prism.RGB{ | ||
.r = rng.random().float(f64), | ||
.g = rng.random().float(f64), | ||
.b = rng.random().float(f64), | ||
}; | ||
const c = rgb.as8bitArray(); | ||
|
||
std.time.sleep(90 * std.time.ns_per_ms); | ||
try stdout.print( | ||
"\r\x1b[38;2;{d:.0};{d:.0};{d:.0}m{s}\x1b[0m", | ||
.{ c[0], c[1], c[2], madness_text }, | ||
); | ||
} | ||
_ = try stdout.write("\x1b[0m\n"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.