summaryrefslogtreecommitdiff
path: root/chapter33/docs/examples/Graphics.smp
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2026-12-04 14:08:57 -0800
committerCliff Click <cliffc@acm.org>2026-12-04 14:08:57 -0800
commitfd21b1a62f0fb1a0efd503769b2e5f3a81747af0 (patch)
tree76946e265ab2bba775c4124b5b07cb52706a9724 /chapter33/docs/examples/Graphics.smp
parent7be87ff4db692a392af1c68abe7752a1da55637f (diff)
downloadSimple-fd21b1a62f0fb1a0efd503769b2e5f3a81747af0.tar.gz
Simple-fd21b1a62f0fb1a0efd503769b2e5f3a81747af0.zip
Start chapter 33 again from the green chapter 32 baseline
Copy the completed chapter 32 snapshot into chapter33 and register the new Maven and IDE module. Update chapter paths and introductory documentation; retain the chapter 32 compiler behavior. Preserve the previous memory-management attempt on ch33_wip for selective follow-up changes. Validation: make -k -j8 tests passes with 819 JUnit test executions, including all four lattice shards and native/library integration. git diff --cached --check passes.
Diffstat (limited to 'chapter33/docs/examples/Graphics.smp')
-rw-r--r--chapter33/docs/examples/Graphics.smp26
1 files changed, 26 insertions, 0 deletions
diff --git a/chapter33/docs/examples/Graphics.smp b/chapter33/docs/examples/Graphics.smp
new file mode 100644
index 00000000..1878e97d
--- /dev/null
+++ b/chapter33/docs/examples/Graphics.smp
@@ -0,0 +1,26 @@
+// Optional graphics smoke test: pixels are drawn entirely in Simple.
+// Pass any argument for a short, self-closing test; otherwise close or press Esc.
+val main = { u8[~][] args ->
+ if( sys.gfx.open("Simple pixels",320,240) != sys.gfx.OK ) return 1;
+ val c = new sys.draw.Canvas(320,240);
+ int result = sys.gfx.OK;
+ bool dirty = true;
+ int frames = 0;
+ while( result == sys.gfx.OK ) {
+ if( c.resize(sys.gfx.width(),sys.gfx.height()) ) dirty = true;
+ if( dirty ) {
+ // The gradient fills the window, including non-4:3 shapes.
+ int dx = c.width > 1 ? c.width-1 : 1, dy = c.height > 1 ? c.height-1 : 1;
+ for( int y = 0; y < c.height; y++ )
+ for( int x = 0; x < c.width; x++ )
+ c.pixels[y*c.width+x] = (x*255/dx << 16) | (y*255/dy << 8) | 64;
+ result = sys.gfx.presentSize(c.pixels,c.width,c.height);
+ if( result != sys.gfx.OK ) break;
+ dirty = false;
+ }
+ result = sys.gfx.poll(true);
+ if( args# > 1 && ++frames == 5 ) break;
+ }
+ sys.gfx.close();
+ return result == sys.gfx.ERROR ? 1 : 0;
+};