D vs Zig
Julian Fondren
julian.fondren at gmail.com
Mon Dec 8 03:53:08 UTC 2025
On Saturday, 6 December 2025 at 23:47:40 UTC, monkyyy wrote:
> I put allot into this:
> https://crazymonkyyy.github.io/writings/gif.html I didnt see a
> return, your free to post it to hakernews to see what happens.
The breakdown's good. Quick visualizations like this are seasonal
with Advent of Code, and also are a fun part of Raytracing in One
Weekend.
This doesn't work as a script but is similar:
```d
import std;
const width = 255, height = 255;
void main() {
enum s = "magick -size 255x255 -depth 8 rgb:- output.gif";
auto convert = pipeProcess(s.split.array, Redirect.stdin);
foreach (ubyte time; 0 .. 255) {
foreach (ubyte y; 0 .. height) {
foreach (ubyte x; 0 .. width) {
ubyte r = time;
ubyte g = y;
ubyte b = x;
ubyte[3] pixel = [r, g, b];
convert.stdin.rawWrite(pixel);
}
}
}
convert.stdin.close;
convert.pid.wait;
spawnProcess(["xdg-open", "output.gif"]);
}
```
This one does work as a script, pulls in a D library, and caches
compilation, but I wasn't able to get it a gif out of it:
```d
#! /usr/bin/env dub
/++ dub.sdl:
configuration "release" {
targetType "executable"
dependency "gamut" version="~>3.3.5"
}
+/
enum width = 255, height = 254;
import std;
import gamut;
void main() {
ubyte[3][] pixels = new ubyte[3][width * height];
foreach (ubyte y; 0 .. height) {
foreach (ubyte x; 0 .. width) {
ubyte r = 1;
ubyte g = y;
ubyte b = x;
pixels[y * width + x] = [r, g, b];
}
}
Image image;
image.createLayeredView(&pixels[0][0], width, height, layers:
1,
PixelType.rgb8, pitchInBytes: 3 * width,
layerOffsetBytes: width * height * 3);
enforce(!image.isError);
image.saveToFile("output.png");
spawnProcess(["xdg-open", "output.png"]);
}
```
More information about the Digitalmars-d
mailing list