Advertisement
ksoltan

colorpicker-graphics.rkt

Nov 10th, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 2.17 KB | None | 0 0
  1. #lang racket/gui
  2. (require racket/gui/base)
  3. (require "colorpicker.rkt")
  4. (define frame (new frame% [label "Web Safe Colors"]
  5.                    [width 686]
  6.                    [height 490]))
  7.  
  8. (define my-canvas%
  9.   (class canvas%
  10.     (super-new)))
  11.  
  12. (define (paint-hexagon canvas dc list-points list-colors)
  13.   (define color (make-object color%
  14.                      (* 51 (car list-colors))
  15.                      (* 51 (car (cdr list-colors)))
  16.                      (* 51 (car (cdr (cdr list-colors))))))
  17.  
  18.   (send dc set-pen (make-object pen% color 1 'solid))
  19.   (send dc set-brush (make-object brush% color 'solid))
  20.   (send dc draw-polygon list-points))
  21.  
  22. (define (paint canvas dc all-points x-orig y-orig radius)
  23.   (for-each
  24.    (lambda (point)
  25.      (define hex (car point))
  26.      (define color (car (cdr point)))
  27.      (define hexagonVertices
  28.        (get-hexagon-vertices radius (+ (car hex) x-orig)
  29.                              (+ y-orig (car (cdr hex)))))
  30.      (paint-hexagon canvas dc hexagonVertices color))
  31.    all-points))
  32.  
  33. (define (get-hexagon-vertices r x-orig y-orig)
  34.   (let
  35.       ((r2 (/ r 2))
  36.        (apothem (/ (* (sqrt 3) r) 2)))
  37.     (list (cons (+ r x-orig) y-orig)
  38.         (cons (+ (/ r 2) x-orig) (+ (/ (* (sqrt 3) r) -2) y-orig))
  39.         (cons (+ (/ r -2) x-orig) (+ (/ (* (sqrt 3) r) -2) y-orig))
  40.         (cons (- x-orig r) y-orig)
  41.         (cons (+ (/ r -2) x-orig) (+ (/ (* (sqrt 3) r) 2) y-orig))
  42.         (cons (+ (/ r 2) x-orig) (+ (/ (* (sqrt 3) r) 2) y-orig)))))
  43.  
  44. (define (paint-all-points canvas dc)
  45.   (define x-orig (/ (send frame get-width) 2))
  46.   (define y-orig (/ (send frame get-height) 2))
  47.   (define side (* 2 (min x-orig y-orig)))
  48.   (define LARGESIDE (/ side 4.5))
  49.   (define radius (sqrt LARGESIDE))
  50.   (define allLight (points-colors-listLight radius LARGESIDE))
  51.   (define allDark (points-colors-listDark radius LARGESIDE))
  52.   (define s (inexact->exact (round (* LARGESIDE (sqrt 3) 0.5))))
  53.   (paint canvas dc allLight (- x-orig s) y-orig radius)
  54.   (paint canvas dc allDark (+ s x-orig) y-orig radius)
  55.   (display x-orig)
  56.   (display y-orig)
  57.   (newline))
  58.  
  59. (new my-canvas% [parent frame]
  60.      [paint-callback paint-all-points])
  61.  
  62. (send frame show true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement