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

Rotating circles #39

Open
soegaard opened this issue Jul 2, 2021 · 1 comment
Open

Rotating circles #39

soegaard opened this issue Jul 2, 2021 · 1 comment

Comments

@soegaard
Copy link
Member

soegaard commented Jul 2, 2021

The program below draws a rotating circle drawn with black outline and white interior on a gray background.
The circle has has center in the rotation center, so the expected result is a static image.
However the smoothing settings 'unsmoothed and 'aligned reveals a problem.
Using 'unsmoothed the outline pulses (the thickness varies).
Using 'aligned one sees the brush color "bleed" through the outline.

#lang racket/base
(require racket/gui)

(define width  640)
(define height 360)

(define angle 0.0) ; the rotation angle

; A frame containing a single canvas with a timer that continously calls draw.
(define top-frame  #f)
(define top-canvas #f)
(define top-timer  #f)

(define dc #f) ; drawing context of the canvas

(define red-pen
  (new pen%	 	 	 	 
       [color  "red"]	 	 	 	 
       [width  4]
       [style  'solid]
       [cap    'round]
       [join   'round]
       [stipple #f]))

(define black-pen
  (new pen%	 	 	 	 
       [color  "black"]
       [width  1]
       [style  'solid]
       [cap    'round]
       [join   'round]
       [stipple #f]))

(define white-pen
  (new pen%	 	 	 	 
       [color  "white"]	 	 	 	 
       [width  1]
       [style  'solid]
       [cap    'round]
       [join   'round]
       [stipple #f]))

(define white-brush (new brush% [color "black"]))



(define (draw)
  (define old-transformation #f)
  (when dc
    (send dc set-background "darkgray")
    (send dc clear)
    ; (send dc set-smoothing 'smoothed)   ; looks ok
    (send dc set-smoothing 'unsmoothed)   ; outline pulses
    ; (send dc set-smoothing 'aligned)    ; outline is slightly off
     
    (send dc set-pen white-pen)
    (send dc set-text-foreground "white")
        
    (set! old-transformation (send dc get-transformation))
    (send dc translate 440.5 180.5)
    (send dc rotate angle)

    (send dc set-brush white-brush)
    (send dc draw-ellipse -50 -50 100 100)
    (send dc set-transformation old-transformation)
    (set! angle (+ angle 0.025))))


(define my-frame%
  (class frame%
    (define/augment (on-close)
      (when top-timer
        (send top-timer stop)))
    (super-new)))


(define my-canvas%
  (class canvas%
    (define/override (on-paint)   ; repaint (exposed or resized)
      (define dc (send this get-dc))
      (send this suspend-flush)
      (handle-on-paint dc)
      (send this resume-flush))
    (super-new)))


(define (start-gui)
  (define frame  (new my-frame%
                      [label "sketch"]))
  (set! top-frame frame)  
  (define canvas (new my-canvas%
                      [parent     frame]
                      [min-width  width]
                      [min-height height]))
  (set! top-canvas canvas)
  (set! dc (send top-canvas get-dc))

  (define timer (new timer%
                     [notify-callback handle-on-timer]
                     [interval (inexact->exact (floor (/ 1000 30)))])) ; milliseconds
  (set! top-timer timer)
  
  (send frame show #t))

(define (handle-on-paint dc)  
  (when dc 
    (draw)))

(define (handle-on-timer)
  (send top-canvas on-paint))

(start-gui)

@soegaard
Copy link
Member Author

soegaard commented Jul 3, 2021

Wrt to "pulsing" or "danching": I am slowly coming to the realization that animation and alignment doesn't mix that well - and it answer might is "don't use alignment with animation".

However, that then leaves a problem with the smoothing settings. The only smoothing setting
without antialias has alignment enabled. So a fourth smoothing setting would be nice to have:
without antialias and without alignment.

I'll keep this issue open, since the bleeding issue is unrelated to the above discussion.

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

1 participant