From 0645c5308226ea2166b84b35be1ce36402c2f390 Mon Sep 17 00:00:00 2001 From: Jeremy Reimer Date: Tue, 27 Feb 2024 23:01:21 +0000 Subject: [PATCH] Added image display to Rockets Experimental page --- rockets-experimental.lsp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/rockets-experimental.lsp b/rockets-experimental.lsp index 437d2af..0c4881b 100755 --- a/rockets-experimental.lsp +++ b/rockets-experimental.lsp @@ -29,6 +29,30 @@ (displayln "") ) +(define (draw-image x y imagename width height tiled) + (setq imagenum (+ imagenum 1)) + (displayln " const img" imagenum " = new Image();") + (displayln " img" imagenum ".onload = () => {") + (if tiled (begin + (let ((numx (/ canvas-width width)) + (numy (/ canvas-height height))) + (displayln " for (let i = 0; i < " numy "; i++) {") + (displayln " for (let j = 0; j < " numx "; j++) {") + (displayln " ctx.drawImage(img" imagenum ", j * " width ", i * " height ", " width ", " height ");") + (displayln " }") + (displayln " }") + (displayln " };")) + ) + (begin + (display " ctx.drawImage(img" imagenum ", " x ", " y ) + (if (or width height) (display ", " width ", " height)) + (displayln ");") + (displayln " };") + ) + ) + (displayln " img" imagenum".src = \"" imagename "\";"); +) + (define (draw-rectangle x y width height filled) (if filled (displayln " ctx.fillRect(" x ", " y ", " width ", " height ");") @@ -64,12 +88,18 @@ ;(displayln "

Debug stuff here...

") ; this stuff is subject to change! +(setq imagenum 0) + (setq canvas-width 800) (setq canvas-height 600) (setq canvas-id "test1") (init-canvas canvas-id canvas-width canvas-height) (draw-rectangle 25 25 300 100) (draw-text 50 75 "Hello, World!" "serif" 48 false) +(draw-image 0 0 "images/poweredby.png" 100 20 true) +(draw-image 50 175 "images/sun_halloween.jpg" 200 200) +(draw-image 450 175 "images/poweredby.png") +(draw-image 500 175 "images/poweredby.png" 400 100) (close-canvas) (displayln "

STUFF GOES HERE...

")