diff options
| author | Cliff Click <cliffc@acm.org> | 2026-08-10 11:11:18 -0700 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2026-11-15 11:20:40 -0800 |
| commit | 658289861e8d971cd9e449e66a749c9c2d65f623 (patch) | |
| tree | 209a32ef7fab1d27222121bc8b53a968ff4b6796 /docs/chapter31/examples/Graphics.smp | |
| parent | 77ae05305a5653a2353709564705819f201e587f (diff) | |
| download | Simple-658289861e8d971cd9e449e66a749c9c2d65f623.tar.gz Simple-658289861e8d971cd9e449e66a749c9c2d65f623.zip | |
Chapter 31: Software Drawing, Time, and Graphical Gameslinear
Co-authored-by: Hsiang-Ying Fu <66062782+fuhsnn@users.noreply.github.com>
Co-authored-by: fuhsnn <66062782+fuhsnn@users.noreply.github.com>
Co-authored-by: Symious <14933944+symious@users.noreply.github.com>
Co-authored-by: Jun Kawasaki <jun784@gmail.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Diffstat (limited to 'docs/chapter31/examples/Graphics.smp')
| -rw-r--r-- | docs/chapter31/examples/Graphics.smp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/docs/chapter31/examples/Graphics.smp b/docs/chapter31/examples/Graphics.smp new file mode 100644 index 00000000..1878e97d --- /dev/null +++ b/docs/chapter31/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; +}; |
