Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to display bitmap in a loop? #30

Open
drakbar opened this issue Nov 20, 2020 · 1 comment
Open

Is it possible to display bitmap in a loop? #30

drakbar opened this issue Nov 20, 2020 · 1 comment

Comments

@drakbar
Copy link

drakbar commented Nov 20, 2020

I am drawing bitmaps to the output like so

#lang racket

(require racket/draw)  

(define imageWidth 64)
(define imageHeight 64)

(define target (make-bitmap imageWidth imageHeight)) 
(define dc (new bitmap-dc% [bitmap target]))

(define (set-frame dc color)
  (send dc set-pen "black" 2 'solid)
  (send dc set-brush color 'solid)
)

(define (display-frame dc)
  (send dc draw-rectangle 0 0 imageWidth imageHeight)
  target
)

(set-frame dc (make-color 255 255 255))
(display-frame dc)

(set-frame dc (make-color 255 0 0))
(display-frame dc)

(set-frame dc (make-color 0 255 0))
(display-frame dc)

(set-frame dc (make-color 0 0 255))
(display-frame dc)

image

However if I try to loop and send the bitmap to the output like so I don't see anything

#lang racket

(require racket/draw)  

(define imageWidth 64)
(define imageHeight 64)

(define target (make-bitmap imageWidth imageHeight)) 
(define dc (new bitmap-dc% [bitmap target]))

(define (set-frame dc color)
  (send dc set-pen "black" 2 'solid)
  (send dc set-brush color 'solid)
)

(define (display-frame dc)
  (send dc draw-rectangle 0 0 imageWidth imageHeight)
  target
)

(for ([x (in-range 4)])
    (set-frame dc (make-color 255 0 0))
    (display-frame dc)
)

image

I am not sure why its not working, but I am sure I am just making some noobie mistake.

@gus-massa
Copy link
Contributor

The result of display-frame is a bitmap% object. The results of each top expression have an implicit println, so the first example,

(println (set-frame dc (make-color 255 255 255))) ; --> (println (void)) doen't show anything
(println (display-frame dc)) ; --> shows a square

The expressions inside for or any other construction don't have the implicit println. So in the second example

(for ([x (in-range 4)])
    (set-frame dc (make-color 255 0 0)) ; --> not shown
    (display-frame dc); --> not shown
) ; --> the result of for is (void), so --> (println (void)) doen't show anything

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants