added isosceles-triangle

svn: r16677
This commit is contained in:
Robby Findler 2009-11-10 23:54:53 +00:00
parent 4e3b1b4c26
commit a566cd488a
36 changed files with 65 additions and 34 deletions

View File

@ -71,6 +71,7 @@ and they all have good sample contracts. (It is amazing what we can do with kids
star star
star-polygon star-polygon
triangle triangle
isosceles-triangle
text text
text/font text/font

View File

@ -658,6 +658,15 @@
(make-bb w h (- h d)) (make-bb w h (- h d))
#f)))) #f))))
(define/chk (isosceles-triangle side-length angle mode color)
(let ([left-corner (make-polar side-length (+ (* pi 1/2) (/ (degrees->radians angle) 2)))]
[right-corner (make-polar side-length (- (* pi 1/2) (/ (degrees->radians angle) 2)))])
(make-a-polygon (list (make-point 0 0)
(make-point (real-part right-corner) (imag-part right-corner))
(make-point (real-part left-corner) (imag-part left-corner)))
mode
color)))
(define/chk (triangle side-length mode color) (define/chk (triangle side-length mode color)
(make-polygon/star side-length 3 mode color values)) (make-polygon/star side-length 3 mode color values))
@ -681,15 +690,15 @@
(make-polygon/star side-length 5 mode color (λ (l) (swizzle l 2)))) (make-polygon/star side-length 5 mode color (λ (l) (swizzle l 2))))
(define (make-polygon/star side-length side-count mode color adjust) (define (make-polygon/star side-length side-count mode color adjust)
(let ([poly (make-polygon (make-a-polygon (adjust (regular-polygon-points side-length side-count))
(adjust (regular-polygon-points side-length side-count)) mode color))
mode
color)]) (define (make-a-polygon points mode color)
(let ([poly (make-polygon points mode color)])
(let-values ([(l t r b) (simple-bb poly)]) (let-values ([(l t r b) (simple-bb poly)])
(make-image (make-translate (- l) (- t) poly) (make-image (make-translate (- l) (- t) poly)
(make-bb (- r l) (- b t) (- b t)) (make-bb (- r l) (- b t) (- b t))
#f)))) #f))))
(define (gcd a b) (define (gcd a b)
(cond (cond
[(zero? b) a] [(zero? b) a]
@ -798,6 +807,7 @@
regular-polygon regular-polygon
triangle triangle
isosceles-triangle
star star
star-polygon star-polygon

View File

@ -28,18 +28,18 @@
(ellipse 20 30 "solid" "slateblue") (ellipse 20 30 "solid" "slateblue")
(ellipse 20 10 "solid" "navy")) (ellipse 20 10 "solid" "navy"))
'image 'image
"38.png") "41.png")
(list '(frame (ellipse 20 20 "outline" "black")) 'image "37.png") (list '(frame (ellipse 20 20 "outline" "black")) 'image "40.png")
(list '(ellipse 60 60 "solid" "blue") 'image "36.png") (list '(ellipse 60 60 "solid" "blue") 'image "39.png")
(list '(scale/xy 3 2 (ellipse 20 30 "solid" "blue")) 'image "35.png") (list '(scale/xy 3 2 (ellipse 20 30 "solid" "blue")) 'image "38.png")
(list '(ellipse 40 60 "solid" "blue") 'image "34.png") (list '(ellipse 40 60 "solid" "blue") 'image "37.png")
(list '(scale 2 (ellipse 20 30 "solid" "blue")) 'image "33.png") (list '(scale 2 (ellipse 20 30 "solid" "blue")) 'image "36.png")
(list '(rotate 5 (rectangle 50 50 "outline" "black")) 'image "32.png") (list '(rotate 5 (rectangle 50 50 "outline" "black")) 'image "35.png")
(list '(rotate 45 (ellipse 60 20 "solid" "olivedrab")) 'image "31.png") (list '(rotate 45 (ellipse 60 20 "solid" "olivedrab")) 'image "34.png")
(list (list
'(beside/places "baseline" (text "ijy" 18 "black") (text "ijy" 24 "black")) '(beside/places "baseline" (text "ijy" 18 "black") (text "ijy" 24 "black"))
'image 'image
"30.png") "33.png")
(list (list
'(beside/places '(beside/places
"center" "center"
@ -48,7 +48,7 @@
(ellipse 20 30 "solid" "purple") (ellipse 20 30 "solid" "purple")
(ellipse 20 10 "solid" "indigo")) (ellipse 20 10 "solid" "indigo"))
'image 'image
"29.png") "32.png")
(list (list
'(beside/places '(beside/places
"bottom" "bottom"
@ -57,7 +57,7 @@
(ellipse 20 30 "solid" "slateblue") (ellipse 20 30 "solid" "slateblue")
(ellipse 20 10 "solid" "navy")) (ellipse 20 10 "solid" "navy"))
'image 'image
"28.png") "31.png")
(list (list
'(beside '(beside
(ellipse 20 70 "solid" "gray") (ellipse 20 70 "solid" "gray")
@ -65,7 +65,7 @@
(ellipse 20 30 "solid" "dimgray") (ellipse 20 30 "solid" "dimgray")
(ellipse 20 10 "solid" "black")) (ellipse 20 10 "solid" "black"))
'image 'image
"27.png") "30.png")
(list (list
'(overlay/xy '(overlay/xy
(rectangle 10 10 "solid" "red") (rectangle 10 10 "solid" "red")
@ -73,7 +73,7 @@
-10 -10
(rectangle 10 10 "solid" "black")) (rectangle 10 10 "solid" "black"))
'image 'image
"26.png") "29.png")
(list (list
'(overlay/xy '(overlay/xy
(rectangle 10 10 "solid" "red") (rectangle 10 10 "solid" "red")
@ -81,7 +81,7 @@
10 10
(rectangle 10 10 "solid" "black")) (rectangle 10 10 "solid" "black"))
'image 'image
"25.png") "28.png")
(list (list
'(overlay/xy '(overlay/xy
(rectangle 10 10 "outline" "red") (rectangle 10 10 "outline" "red")
@ -89,7 +89,7 @@
0 0
(rectangle 10 10 "outline" "black")) (rectangle 10 10 "outline" "black"))
'image 'image
"24.png") "27.png")
(list (list
'(overlay/xy '(overlay/xy
(ellipse 40 40 "outline" "black") (ellipse 40 40 "outline" "black")
@ -97,7 +97,7 @@
25 25
(ellipse 10 10 "solid" "forestgreen")) (ellipse 10 10 "solid" "forestgreen"))
'image 'image
"23.png") "26.png")
(list (list
'(overlay/places '(overlay/places
"right" "right"
@ -107,7 +107,7 @@
(rectangle 40 40 "solid" "red") (rectangle 40 40 "solid" "red")
(rectangle 50 50 "solid" "black")) (rectangle 50 50 "solid" "black"))
'image 'image
"22.png") "25.png")
(list (list
'(overlay/places '(overlay/places
"middle" "middle"
@ -115,7 +115,7 @@
(rectangle 30 60 "solid" "orange") (rectangle 30 60 "solid" "orange")
(ellipse 60 30 "solid" "purple")) (ellipse 60 30 "solid" "purple"))
'image 'image
"21.png") "24.png")
(list (list
'(overlay '(overlay
(ellipse 10 10 "solid" "red") (ellipse 10 10 "solid" "red")
@ -125,31 +125,34 @@
(ellipse 50 50 "solid" "red") (ellipse 50 50 "solid" "red")
(ellipse 60 60 "solid" "black")) (ellipse 60 60 "solid" "black"))
'image 'image
"20.png") "23.png")
(list (list
'(overlay '(overlay
(ellipse 60 30 "solid" "purple") (ellipse 60 30 "solid" "purple")
(rectangle 30 60 "solid" "orange")) (rectangle 30 60 "solid" "orange"))
'image 'image
"19.png") "22.png")
(list (list
'(text/font "not really a link" 18 "blue" #f 'roman 'normal 'normal #t) '(text/font "not really a link" 18 "blue" #f 'roman 'normal 'normal #t)
'image 'image
"18.png") "21.png")
(list (list
'(text/font "Goodbye" 18 "indigo" #f 'modern 'italic 'normal #f) '(text/font "Goodbye" 18 "indigo" #f 'modern 'italic 'normal #f)
'image 'image
"17.png") "20.png")
(list (list
'(text/font "Hello" 24 "olive" "Gill Sans" 'swiss 'normal 'bold #f) '(text/font "Hello" 24 "olive" "Gill Sans" 'swiss 'normal 'bold #f)
'image 'image
"16.png") "19.png")
(list '(text "Goodbye" 36 "indigo") 'image "15.png") (list '(text "Goodbye" 36 "indigo") 'image "18.png")
(list '(text "Hello" 24 "olive") 'image "14.png") (list '(text "Hello" 24 "olive") 'image "17.png")
(list '(star-polygon 20 10 3 "solid" "cornflowerblue") 'image "13.png") (list '(star-polygon 20 10 3 "solid" "cornflowerblue") 'image "16.png")
(list '(star-polygon 40 7 3 "outline" "darkred") 'image "12.png") (list '(star-polygon 40 7 3 "outline" "darkred") 'image "15.png")
(list '(star-polygon 40 5 2 "solid" "seagreen") 'image "11.png") (list '(star-polygon 40 5 2 "solid" "seagreen") 'image "14.png")
(list '(star 40 "solid" "gray") 'image "10.png") (list '(star 40 "solid" "gray") 'image "13.png")
(list '(isosceles-triangle 60 330 "solid" "lightseagreen") 'image "12.png")
(list '(isosceles-triangle 60 30 "solid" "aquamarine") 'image "11.png")
(list '(isosceles-triangle 200 170 "solid" "seagreen") 'image "10.png")
(list '(triangle 40 "solid" "tan") 'image "9.png") (list '(triangle 40 "solid" "tan") 'image "9.png")
(list '(regular-polygon 20 6 "solid" "red") 'image "8.png") (list '(regular-polygon 20 6 "solid" "red") 'image "8.png")
(list '(regular-polygon 20 4 "outline" "blue") 'image "7.png") (list '(regular-polygon 20 4 "outline" "blue") 'image "7.png")

View File

@ -73,6 +73,23 @@ Existing images can be rotated, scaled, and overlaid on top of each other.
@image-examples[(triangle 40 "solid" "tan")] @image-examples[(triangle 40 "solid" "tan")]
} }
@defproc[(isosceles-triangle [side-length (and/c positive? real?)]
[angle angle?]
[mode mode?]
[color (or/c symbol? string?)])
image?]{
Creates a triangle with two equal-length sides, of length @scheme[side-length]
where the angle between those sides is @scheme[angle]. The third
leg is straight, horizontally. If the angle is less than
@scheme[180], then the triangle will point up and if the @scheme[angle]
is more, then the triangle will point down.
@image-examples[(isosceles-triangle 200 170 "solid" "seagreen")
(isosceles-triangle 60 30 "solid" "aquamarine")
(isosceles-triangle 60 330 "solid" "lightseagreen")]
}
@defproc[(star [side-length (and/c real? positive?)] @defproc[(star [side-length (and/c real? positive?)]
[mode mode?] [mode mode?]
[color (or/c symbol? string?)]) [color (or/c symbol? string?)])

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 685 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 659 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 674 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 893 B

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 282 B

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 121 B

After

Width:  |  Height:  |  Size: 893 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 144 B

After

Width:  |  Height:  |  Size: 282 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 142 B

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 121 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 144 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 142 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1007 B

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1000 B

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 678 B

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 865 B

After

Width:  |  Height:  |  Size: 1007 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 865 B

After

Width:  |  Height:  |  Size: 1000 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 678 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 865 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 420 B

After

Width:  |  Height:  |  Size: 865 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 420 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB