Bitmap/Write a PPM file: Difference between revisions

→‎{{header|Wren}}: Updated, about 90 times faster than before.
(→‎{{header|Wren}}: Updated, about 90 times faster than before.)
Line 2,527:
=={{header|Wren}}==
{{libheader|DOME}}
{{libheader|Wren-str}}
This takes a while to run as DOME needs to build up the file contents in string form before saving them to a PPM file. It is not currently possible to write files a line at a time.
<syntaxhighlight lang="ecmascriptwren">import "graphics" for Canvas, ImageData, Color
import "dome" for Window, Process
import "io" for FileSystem
import "./str" for Strs
 
class Bitmap {
Line 2,551 ⟶ 2,552:
init() {
// write bitmap to a PPM file
var ppm = ["P6\n%(_w) %(_h)\n255\n"]
for (y in 0..._h) {
for (x in 0..._w) {
var c = pget(x, y)
ppm = ppm + .add(String.fromByte(c.r))
ppm = ppm + .add(String.fromByte(c.g))
ppm = ppm + .add(String.fromByte(c.b))
}
}
FileSystem.save("output.ppm", Strs.concat(ppm))
Process.exit(0)
}
Line 2,574 ⟶ 2,575:
 
var Game = Bitmap.new("Bitmap - write to PPM file", 320, 320)</syntaxhighlight>
 
=={{header|XPL0}}==
<syntaxhighlight lang="xpl0">include c:\cxpl\codes; \intrinsic 'code' declarations
9,482

edits