From 676df4b33828df00bcbd63ead054cf6c8f54798c Mon Sep 17 00:00:00 2001 From: Robby Findler Date: Thu, 12 Nov 2009 20:21:33 +0000 Subject: [PATCH] added polygon svn: r16735 --- collects/2htdp/image.ss | 1 + collects/2htdp/private/image-more.ss | 18 ++++++++++++ .../teachpack/2htdp/scribblings/image-gen.ss | 1 + .../teachpack/2htdp/scribblings/image-toc.ss | 26 ++++++++++++++++++ .../teachpack/2htdp/scribblings/image.scrbl | 26 +++++++++++++++++- .../2htdp/scribblings/img/150e1d5e9f.png | Bin 0 -> 230 bytes .../2htdp/scribblings/img/25354f2b84e.png | Bin 0 -> 1053 bytes collects/tests/2htdp/test-image.ss | 22 +++++++++++++++ 8 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 collects/teachpack/2htdp/scribblings/img/150e1d5e9f.png create mode 100644 collects/teachpack/2htdp/scribblings/img/25354f2b84e.png diff --git a/collects/2htdp/image.ss b/collects/2htdp/image.ss index 25c2426037..3ca112db06 100644 --- a/collects/2htdp/image.ss +++ b/collects/2htdp/image.ss @@ -71,6 +71,7 @@ and they all have good sample contracts. (It is amazing what we can do with kids square rhombus regular-polygon + polygon star star-polygon triangle diff --git a/collects/2htdp/private/image-more.ss b/collects/2htdp/private/image-more.ss index a5c7a2d729..11d951eb16 100644 --- a/collects/2htdp/private/image-more.ss +++ b/collects/2htdp/private/image-more.ss @@ -6,6 +6,7 @@ scheme/gui/base htdp/error scheme/math + lang/posn (for-syntax scheme/base)) (define (show-image g [extra-space 0]) @@ -214,6 +215,17 @@ arg] [(underline) (and arg #t)] + [(posns) + (check-arg fn-name + (and (list? arg) + (andmap posn? arg)) + 'list-of-posns + i arg) + (check-arg fn-name + (>= (length arg) 3) + 'list-of-at-least-three-posns + i arg) + arg] [else (error 'check "the function ~a has an argument with an unknown name: ~s" fn-name @@ -653,6 +665,11 @@ ;; rectangle +(define/chk (polygon posns mode color) + (make-a-polygon (map (λ (p) (make-point (posn-x p) (posn-y p))) posns) + mode + color)) + (define/chk (rectangle width height mode color) (make-a-polygon (rectangle-points width height) mode color)) @@ -901,6 +918,7 @@ square rhombus + polygon regular-polygon triangle isosceles-triangle diff --git a/collects/teachpack/2htdp/scribblings/image-gen.ss b/collects/teachpack/2htdp/scribblings/image-gen.ss index 63a4c83d75..cbaf4b9c66 100644 --- a/collects/teachpack/2htdp/scribblings/image-gen.ss +++ b/collects/teachpack/2htdp/scribblings/image-gen.ss @@ -1,6 +1,7 @@ #lang scheme/gui (require 2htdp/private/image-more + lang/posn mrlib/image-core) (define-namespace-anchor anchor) diff --git a/collects/teachpack/2htdp/scribblings/image-toc.ss b/collects/teachpack/2htdp/scribblings/image-toc.ss index 410b31fdd7..adc68393fa 100644 --- a/collects/teachpack/2htdp/scribblings/image-toc.ss +++ b/collects/teachpack/2htdp/scribblings/image-toc.ss @@ -207,6 +207,32 @@ (list '(line 30 -20 "red") 'image "12948ac080d.png") (list '(line -30 20 "red") 'image "69aaaa680d.png") (list '(line 30 30 "black") 'image "8e1ebaaf82.png") + (list + '(polygon + (list + (make-posn 0 0) + (make-posn 0 40) + (make-posn 20 40) + (make-posn 20 60) + (make-posn 40 60) + (make-posn 40 20) + (make-posn 20 20) + (make-posn 20 0)) + "solid" + "plum") + 'image + "150e1d5e9f.png") + (list + '(polygon + (list + (make-posn 0 0) + (make-posn -10 20) + (make-posn 60 0) + (make-posn -10 -20)) + "solid" + "burlywood") + 'image + "25354f2b84e.png") (list '(star-polygon 20 10 3 "solid" "cornflowerblue") 'image diff --git a/collects/teachpack/2htdp/scribblings/image.scrbl b/collects/teachpack/2htdp/scribblings/image.scrbl index 926c5d4bd5..81a0403719 100644 --- a/collects/teachpack/2htdp/scribblings/image.scrbl +++ b/collects/teachpack/2htdp/scribblings/image.scrbl @@ -1,8 +1,10 @@ #lang scribble/doc @(require (for-label (except-in 2htdp/image image?) - lang/htdp-beginner + ;lang/htdp-beginner;(only-in beginner-require) + lang/posn scheme/gui/base) + lang/posn "shared.ss" "image-util.ss" scribble/manual) @@ -162,6 +164,28 @@ other. The top and bottom pair of angles is @scheme[angle] and the left and righ (star-polygon 20 10 3 "solid" "cornflowerblue")] } + +@defproc[(polygon [verticies (listof posn?)] + [mode mode?] + [color (or/c symbol? string?)]) + image?]{ + Constructs a polygon connecting the given verticies. + + @image-examples[(polygon (list (make-posn 0 0) + (make-posn -10 20) + (make-posn 60 0) + (make-posn -10 -20)) + "solid" "burlywood") + (polygon (list (make-posn 0 0) + (make-posn 0 40) + (make-posn 20 40) + (make-posn 20 60) + (make-posn 40 60) + (make-posn 40 20) + (make-posn 20 20) + (make-posn 20 0)) + "solid" "plum")] +} @defproc[(line [x1 real?] [y1 real?] [color (or/c symbol? string?)]) image?]{ Constructs an image representing a line segment that connects the points diff --git a/collects/teachpack/2htdp/scribblings/img/150e1d5e9f.png b/collects/teachpack/2htdp/scribblings/img/150e1d5e9f.png new file mode 100644 index 0000000000000000000000000000000000000000..f659e6912498451f84d14267cffcecadc2e6b969 GIT binary patch literal 230 zcmeAS@N?(olHy`uVBq!ia0vp^nm}yJ!2~4tyI$7;Qfob3978JRyuG2wci2FLIbb_i zM#9Ca?x+8b-%wn(;eh<5G@Zkx%W4H?NBifU3>Q0{cC*0#W5?}e>JPW$6pr3mb2elw^Pi3-QRv&#caDTzcy|y z`rxk=y)EbFrqt8ZYSk0{t*@`yIm!I;^}0!Aj*?r_|K0~l=mJ&fHRc^tR@&&waNyFc d$FrBk+f^$^%@y$WT?lkIgQu&X%Q~loCIG`FWSjs1 literal 0 HcmV?d00001 diff --git a/collects/teachpack/2htdp/scribblings/img/25354f2b84e.png b/collects/teachpack/2htdp/scribblings/img/25354f2b84e.png new file mode 100644 index 0000000000000000000000000000000000000000..953227b9f7eafe2b321f79b401f17cda8df9c17c GIT binary patch literal 1053 zcmV+&1mgRNP)4(t!|vKnBzYG)#MoHtAHXl@&xD~fT$CGn(_XYU?M*uglTv6Wbi%+u0x68+ zgdFY0aU37y?S%|9uB_NPI7y$om3F`HeP<=@>Rae_+tsBz5bKP)R7jdHBh3U?9H^A4 zul>^a>&dW<5U~oByG%$uD=t=CWS~;Y>$a+kch#Uja!(_3Ot@53s8fPizYu-VfJ!L< zz`@I(j;hbbc0!mqMaCr)Qe*ZE;L}E^nedLk* z@W(gpgLld1zy_tb zaN5{PFQt!WW~q>jyOft9Hj)h<;Ob;=eP`v{WYdHxK$zGC$|Vz0&*YPd8Tcu${d&LK z+)E_EROob`3dw{dP6;9{a-3jSt?ie)tKY|v7Z-#z;uQS})TlM>@L*Q}sLe0`@>EDBTw)g|T;j*M0?o}o_h0;&sJyr!&7jUL-yt@0Aw9>s0?Ml{-tBjeQxO;& zBX^An$%Hhm1pwg4-SMsfIC}T=;PuZb%Zm%v3FT$VCF3qKn13lM52c!HnUXtKgh}dUj?|TuP;WcG@T2C(44>Fzb&c$ z3y-?$G&WE6-X@!4_H~O zfoELR*CS4pk>yNC$|bQcMeX*ptJa5Coui$}M`%0{}Fu zEB(_WzYQTWtp&d%aCOgxHRW|18;`M>Vcex$QvSa