Sierpinski triangle/Graphical: Difference between revisions

m
→‎{{header|Sidef}}: modified the code to work with the latest version of Sidef
m (→‎{{header|zkl}}: added image)
m (→‎{{header|Sidef}}: modified the code to work with the latest version of Sidef)
Line 1,287:
 
=={{header|Sidef}}==
Creates a PNG image.
<lang ruby>func sierpinski_triangle(n) -> Array {
var triangle = ['*'];
Line 1,311 ⟶ 1,312:
 
self.range.each { |i|
range(i * scale), ..^ (i * scale + scale) -> .each { |j|
var row = self[i];
img.moveTo(0, j);
loop {
if ((var sp = row.sub!count(/^(\s+)/);) $1.len?> 0) {
row.substr!(sp);
img.fgcolor(bgcolor);
img.line(scale * $1.lensp);
} elsif (row.sub!(/^(\S+)/); $1.len?) {
elsif ((var nsp = row.count(/^\S+/)) > 0) {
row.substr!(nsp);
img.fgcolor(fgcolor);
img.line(scale * $1.lennsp);
} else { break }
else {
break;
}
}
}
};
 
return img.png;
2,747

edits