Jump to content

Sierpinski triangle/Graphical: Difference between revisions

+ D entry
(+ D entry)
Line 156:
return 0;
}</lang>
 
=={{header|D}}==
The output image is the same as the Go version. This requires the module from the Grayscale image Task.
{{trans|Go}}
<lang d>import grayscale_image;
 
void main() {
enum order = 8,
margin = 10,
width = 2 ^^ order;
 
auto im = new Image!Gray(width + 2 * margin, width + 2 * margin);
im.clear(Gray.white);
 
foreach (y; 0 .. width)
foreach (x; 0 .. width)
if ((x & y) == 0)
im[x + margin, y + margin] = Gray.black;
im.savePGM("sierpinski.pgm");
}</lang>
 
Cookies help us deliver our services. By using our services, you agree to our use of cookies.