Skip to content

Commit

Permalink
Added image display to Rockets Experimental page
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyReimer committed Feb 27, 2024
1 parent a0cde91 commit 0645c53
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions rockets-experimental.lsp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,30 @@
(displayln "</script>")
)

(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 ");")
Expand Down Expand Up @@ -64,12 +88,18 @@
;(displayln "<p>Debug stuff here...</p>")
; 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 "<p>STUFF GOES HERE...</p>")
Expand Down

0 comments on commit 0645c53

Please sign in to comment.