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

2htdp/image raises error #61

Closed
DarrenN opened this issue Aug 25, 2019 · 1 comment
Closed

2htdp/image raises error #61

DarrenN opened this issue Aug 25, 2019 · 1 comment

Comments

@DarrenN
Copy link

DarrenN commented Aug 25, 2019

Background

Exception raised:

syntax->list: contract violation
  expected: syntax?
  given: '(#<syntax:/home/pasterack/racket73/collects/racket/private/reqprov.rkt:415:56 (#%require 2htdp/image)> #<syntax:/home/pasterack/racket73/collects/racket/private/reqprov.rkt:415:56 (#%require lang/posn)>)

Stack trace:

syntax->list at:
  <unknown location>
<unknown procedure> at:
  line 261, column 28, in file /home/pasterack/racket73/collects/racket/private/more-scheme.rkt
partition at:
  line 555, column 0, in file /home/pasterack/racket73/collects/racket/list.rkt
temp45 at:
  line 125, column 4, in file /home/pasterack/pasterack/pasterack.rkt
process-paste22 at:
  line 468, column 0, in file /home/pasterack/pasterack/pasterack.rkt
<unknown procedure> at:
  line 360, column 33, in file /home/pasterack/racket73/collects/racket/contract/private/arrow-higher-order.rkt
<unknown procedure> at:
  line 360, column 33, in file /home/pasterack/racket73/collects/racket/contract/private/arrow-higher-order.rkt

Code which triggers exception:

#lang racket

(require 2htdp/image
         lang/posn)

(define COLOR-ON "white")
(define COLOR-OFF "black")

(define hex-on (regular-polygon 60 6 "solid" COLOR-ON))
(define hex-off (regular-polygon 60 6 "solid" COLOR-OFF))

(define half-on (place-image/align (rotate 30 hex-on)
                   0 60 "center" "center"
                   (rectangle 52 120 "outline" "transparent")))

(define half-off (place-image/align (rotate 30 hex-off)
                   0 60 "center" "center"
                   (rectangle 52 120 "outline" "transparent")))

(define split-hex (beside (rotate 180 half-on) half-off))

(define hex-options
  (append
   (list (rotate 90 hex-on))
   (for/list ([i (in-range 6)])
    (rotate (* i 60) split-hex))))

(define (make-row n)
  (for/fold ([scene (rectangle (* 104 n) 120 "outline" "transparent")])
            ([i (in-range n)])
    (place-image (list-ref hex-options (random (length hex-options)))
                 (+ (* i 104) (/ 104 2)) 60
                 scene)))

(define (make-rows w n)
  (for/list ([i (in-range n)])
    (make-row w)))


(define (scene-width rows)
  (- (image-width (car rows)) (image-width split-hex)))

(define (scene-height rows)
  (* (length rows) (/ (image-height split-hex) 2)))

(define (stack-rows rows)
  (define-values (sum image)
    (for/fold ([sum 0]
             [scene (rectangle (scene-width rows)
                               (scene-height rows)
                               "outline" "transparent")])
            ([row rows])
    (values
     (add1 sum)
     (place-image row
                  (- (/ (image-width scene) 2) (if (even? sum) 0 (image-width half-on)))
                  (* sum (/ (image-height split-hex) 1.33333))
                  scene))))
  image)


(stack-rows (make-rows 10 20))

The above code runs and renders fine in Racket / Dr. Racket 7.2

@stchang
Copy link
Owner

stchang commented Aug 2, 2021

fixed in 5794e11 thanks
http://pasterack.org/pastes/11302

@stchang stchang closed this as completed Aug 2, 2021
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