Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7754043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:12:30+00:00 2026-06-01T12:12:30+00:00

I thought I’d try a simple GUI app using the world/universe mutation-free approach, but

  • 0

I thought I’d try a simple GUI app using the world/universe mutation-free approach,  but trying to implement the ‘world/universe’ program design myself.

I’ve got my little sketch below, but I quickly came to conclusion that while I could use the teachpack, I don’t know how to achieve the teachpack functionality myself.

I’m guessing I should use continuations, but that doesn’t seem to be the approach in the universe.rkt source.

I could always just stuff the program into the canvas class, (as earlier games like slidey and same seem to do), but I really want to get a handle on  how to implement the ‘world/universe’ style of program control.

;;;;----
#lang racket/gui

; simple drawing program
; mousedown starts recording a list of points
; mousechanged starts recording a new list
; paint callback paints the list of lists as lines.

(define diagramframe (new frame% [label "paint"] [width 300]
                                 [height 300] [x 1000][y 300]))

;(define lines '(((0 . 0) (0 . 300) (250 . 250) (150 . 176))))
(define lines '(((0 . 0) (0 . 300) (250 . 250) (150 . 176)) 
                ((10 . 4) (280 . 10))))

(define paintcanvas% 
  (class canvas%
    (init-field mouse-event-callback)
    (super-new)
    (define dc (send this get-dc))
    (define/override (on-event mouse-event)
      (mouse-event-callback mouse-event))))

(define (paint-cb c dc)  
  (for-each (λ (line) (send dc draw-lines line)) lines))

(define (me-cb mouse-event)
   (let ((x (send mouse-event get-x))
        (y (send mouse-event get-y)))
    (when (and (send mouse-event get-left-down)
               (send mouse-event moving?))
      (if (send mouse-event button-changed?)
          ; if true append as new list
          '()  
          ; if false append existing list
          '()))))

(define Paintcanvas (new paintcanvas% 
                         [parent diagramframe]
                         [paint-callback paint-cb]
                         [mouse-event-callback me-cb]))

(define (main world)
 (when world (main (??? world)))
  (send diagramframe show #t))
 
(main lines)

(send diagramframe show #t)

;;-----
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T12:12:32+00:00Added an answer on June 1, 2026 at 12:12 pm

    Here is how I would do it.

    Note that the GUI event loop acts as the program main.
    Use timer events to implement on-tick.

     #lang racket/gui
    
    ;;;
    ;;; WORLD
    ;;;
    
    (define-struct world (lines))
    (define the-world (make-world '((0 . 0) (0 . 300) (250 . 250) (150 . 176) (10 . 4) (280 . 10))))
    
    ;;;
    ;;; USER LAND
    ;;;
    
    (define (on-mouse-event world event)
      (if (and (send event get-left-down)
               (send event moving?)
               #; (send event button-changed?))
          (let ((x (send event get-x))
                (y (send event get-y)))
            (make-world (cons (cons x y) (world-lines world))))
          world))
    
    (define (on-paint world dc)  
      (send dc draw-lines 
            (map pair->point (world-lines world))))
    
    (define (pair->point p)
      (make-object point% (car p) (cdr p)))
    
    
    ;;;
    ;;; SYSTEM
    ;;;
    
    (define user:on-paint on-paint)
    
    (define diagramframe (new frame% [label "paint"] [width 300] [height 300] [x 1000][y 300]))
    
    (define paintcanvas% 
      (class canvas%
        (inherit get-dc refresh)
        (super-new)
        
        (define/override (on-paint)
          (send (get-dc) suspend-flush)
          (user:on-paint the-world (get-dc))
          (send (get-dc) resume-flush))
        
        (define/override (on-event mouse-event)
          (let* ([old-world the-world]
                 [new-world (on-mouse-event the-world mouse-event)])
            (if (eq? old-world new-world)
                (super on-event mouse-event)
                (begin
                  (set! the-world new-world)
                  (refresh)))))))
    
    (define paintcanvas (new paintcanvas% [parent diagramframe]))
    (send diagramframe show #t)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I thought this would be really easy but I can't find a simple solution,
Thought I'd try to implement SHA1 in Haskell myself. I came up with an
I thought this would be pretty academic but its not. I'm trying to traverse
I thought that would have been simple but it is not working. I can,
I thought this would be really simple but its proving to be very difficult.
I thought this would be a relatively simple task with something like FMOD, but
I thought I heard that py2exe was able to do this, but I never
I thought people would be working on little code projects together, but I don't
I thought I understood Java generics pretty well, but then I came across the
Thought it was pretty straight forward. But I get a iterator not dereferencable errro

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.