From c0e39b6a9153079f4ea5e8af0a74001e1e9e97c2 Mon Sep 17 00:00:00 2001 From: a11ce Date: Fri, 13 Dec 2024 14:46:13 -0600 Subject: [PATCH 1/2] Add universe-inset parameter --- htdp-lib/2htdp/private/check-aux.rkt | 13 ++++++++++--- htdp-lib/2htdp/private/world.rkt | 9 +++++---- htdp-lib/2htdp/universe.rkt | 5 +++-- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/htdp-lib/2htdp/private/check-aux.rkt b/htdp-lib/2htdp/private/check-aux.rkt index 455401c43..e9709861b 100644 --- a/htdp-lib/2htdp/private/check-aux.rkt +++ b/htdp-lib/2htdp/private/check-aux.rkt @@ -8,7 +8,14 @@ (provide (all-defined-out)) -(define INSET 5) ;; the space around the image in the canvas +(define universe-inset ;; the space around the image in the canvas + (make-parameter + 5 + (λ (v) + (unless (and (integer? v) + (<= 0 v 1000)) + (raise-argument-error 'universe-inset "an integer between 0 and 1000 (inclusive)" v)) + v))) (define RATE 1/30) ;; the clock tick rate (define TRIES 3) ;; how many times should register try to connect to the server (define PAUSE 1/2) ;; # secs to wait between attempts to connect to server @@ -53,8 +60,8 @@ ;; MouseEvent% -> [List Nat Nat MouseEventType] ;; turn a mouse event into its pieces (define (mouse-event->parts e) - (define x (- (send e get-x) INSET)) - (define y (- (send e get-y) INSET)) + (define x (- (send e get-x) (universe-inset))) + (define y (- (send e get-y) (universe-inset))) (values x y (cond [(send e button-down?) "button-down"] [(send e button-up?) "button-up"] diff --git a/htdp-lib/2htdp/private/world.rkt b/htdp-lib/2htdp/private/world.rkt index 282221738..4a70793a7 100644 --- a/htdp-lib/2htdp/private/world.rkt +++ b/htdp-lib/2htdp/private/world.rkt @@ -220,6 +220,7 @@ (define/pubment (create-frame/universe) (define play-back:cust (make-custodian)) + (define inset (universe-inset)) (define frame-x 2) (define frame-y 2) @@ -256,10 +257,10 @@ (stretchable-width #f) (stretchable-height #f) (style '(no-hscroll no-vscroll)) - (horizontal-inset INSET) - (vertical-inset INSET))) - (send editor-canvas min-client-width (sub1 (+ width INSET INSET))) - (send editor-canvas min-client-height (sub1 (+ height INSET INSET))) + (horizontal-inset inset) + (vertical-inset inset))) + (send editor-canvas min-client-width (sub1 (+ width inset inset))) + (send editor-canvas min-client-height (sub1 (+ height inset inset))) (set!-values (enable-images-button disable-images-button) (inner (values void void) create-frame/universe frame play-back:cust)) (send editor-canvas focus) diff --git a/htdp-lib/2htdp/universe.rkt b/htdp-lib/2htdp/universe.rkt index 2cd219ef8..062f98888 100644 --- a/htdp-lib/2htdp/universe.rkt +++ b/htdp-lib/2htdp/universe.rkt @@ -27,7 +27,7 @@ ;; (only-in "private/launch-many-worlds.rkt" launch-many-worlds launch-many-worlds/proc) (only-in "private/stop.rkt" make-stop-the-world) - (only-in "private/check-aux.rkt" sexp? SQPORT) + (only-in "private/check-aux.rkt" sexp? SQPORT universe-inset) (only-in "private/pad.rkt" pad-event? pad=?) htdp/error (rename-in lang/prim (first-order->higher-order f2h))) @@ -178,7 +178,8 @@ (provide big-bang ;; : see below - pad-handler ;; : see below + pad-handler ;; : see below + universe-inset ) (provide-primitives From 63d79ffcec260fba9b4d6cf3346230deb46d9db6 Mon Sep 17 00:00:00 2001 From: a11ce Date: Fri, 13 Dec 2024 15:30:29 -0600 Subject: [PATCH 2/2] Document universe-inset --- htdp-doc/teachpack/2htdp/scribblings/universe.scrbl | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/htdp-doc/teachpack/2htdp/scribblings/universe.scrbl b/htdp-doc/teachpack/2htdp/scribblings/universe.scrbl index 6a77d9d48..1d7330413 100644 --- a/htdp-doc/teachpack/2htdp/scribblings/universe.scrbl +++ b/htdp-doc/teachpack/2htdp/scribblings/universe.scrbl @@ -2034,3 +2034,15 @@ Finally, here is the third function, which renders the state as an image: @bold{Exercise} Design a function that takes care of a world to which the universe has lost its connection. Is @emph{Result} the proper contract for the result of this function? + +@section[#:tag "universe-extra"]{Extra Features in Racket} + +This section documents features of the universe teachpack not available in +the HtDP student languages. + +@defparam[universe-inset inset-width (integer-in 0 1000) + #:value 5]{ + A @tech[#:doc '(lib "scribblings/guide/guide.scrbl")]{parameter} that controls + the visual inset of the window displayed by @racket[animate] or @racket[big-bang]. + The inset usually appears as a white border. + }