RosettaCodeData/Task/Greyscale-bars-Display/Zkl/greyscale-bars-display.zkl
2017-09-25 22:28:19 +02:00

13 lines
503 B
Text

img:=PPM(640,480);
foreach q in ([0..3]){ //quarter of screen
n:=(8).shiftLeft(q); //number of bars
w:=640/n; //width of bar (pixels)
foreach b in ([0..n-1]){ //for each bar...
c:=(255.0/(n-1).toFloat() * (if(q.isOdd) n-1-b else b)).toInt();
c:=c.shiftLeft(16) + c.shiftLeft(8) + c; //RGB color = gray
foreach y in ([(3-q)*120 .. (3-q+1)*120-1]){ // flip image vertically
img.line(w*b,y, w*(b+1)-1,y, c);
}
}
}
img.write(File("foo.ppm","wb"));