使用big-bang和on-tick

时间:2013-01-21 17:31:04

标签: scheme racket

所以我正在尝试制作一个可以增加图像的程序" HI"用大爆炸。我把它放在画布的中心。我希望文本大小从1开始,并在大小达到80时停止增长。我已经添加了on-tick但它仍然不会从1开始并且增长。关于我做错了什么想法?

编辑 -

    (require 2htdp/image)
    (require 2htdp/universe)

    (define word "HELLO WORLD" )

    (define (draw-world world )
      (place-image (text word world  "olive")
                   240 210
                   (empty-scene 500 300)))


         (define (next t)
  (cond [(>= (draw-world t) 80) t]
        [else (+ t 1)]))

    (big-bang 1
              (on-tick add1)
              (to-draw draw-world)
              (stop-when zero?))

2 个答案:

答案 0 :(得分:1)

有一些事情。最重要的一个是draw-world 在那里绘制大小为11的文本。如果您改为绘制大小为world的文本,那么您的文本将与当前世界具有相同的大小。

(text word world "olive")

修复该错误后,您将立即发现下一件要修复的内容。

更新

(define (stop? a-world)
  (<= a-world 80))

答案 1 :(得分:0)

你可以这样做:

(require 2htdp/image)
(require 2htdp/universe)

(define WORD "HELLO WORLD" )

(define (main x)
  (big-bang x
          (on-tick next)        ; World -> World
          (to-draw draw-world)  ; World -> Image
          (stop-when stop?)))   ; World -> Boolean


; World -> World
; Gives the next world
(define (next world)
  (cond [(>= world 80) world]
        [else (+ world 1)]))

; World -> Image
; Draw the current world
(define (draw-world world )
  (place-image (text WORD world  "olive")
               240 210
               (empty-scene 500 300)))

; World -> Boolean
; Check if this is the last world
(define (stop? world)
  (= world 80))

(main 1)