![]() |
![]() |
|
home—lectures—exams—hws—breeze (snow day)
Due Oct.05 (Fri) in class (hardcopy, and on D2L) Your name and the assignment-number must be in a comment at the start of the file.
The following problems build on the Asteroids project started in hw03—handling lists: due Sep.26 (Wed). You should add this code to (a copy of) the file Ship.java. Do not re-assign to any fields or variables.
You might want to review notions of distance vs. acceleration: one site is u3l2c.cfm. (Post on the message boards, if you find a site/explanation you like better.) We aren't actually dealing with acceleration at all, yet, but we will.
You do not need to worry about the screen-size or wrapping around for this hw (though you can add that if you like; you'll eventually need it).
(6pts)
In your racket version,
write the corresponding
For the following functions:
If you want to test these functions,
you can either call
(2pts)
In racket2,
write a function
Look in the racket documentation for helpful image-drawing functions.
(Either search directly,
or take a function you know about (like
You do not need to provide any test cases for the
draw functions, but you are welcome to.
In fact, you might find that writing one test case
makes writing the function trivial.
Here's a test-case I used (your artwork3
will differ, of course):
As ever: Do not use any images that you do not have a copyright to. Cite any images you got from others.
1
If you want to be fancier than just printing out
results, you can use JUnit tests.
This will require overriding
2I am not asking for a Java version of a drawing program. Java drawing libraries tend to be very heavyweight. I have heard of a java-implemention of racket's drawing primitives; you can experiment with javalib if you like. But only do so after finishing the racket exercises. ↩
3
Here is some code I used to make the picture of house and flowers.
Note how
;; Some example of drawing simple pictures, using the image.ss library. ;; See: http://docs.racket-lang.org/teachpack/2htdpimage.html (define house-image (above (triangle 60 'solid 'saddleBrown) (square 60 'solid 'darkGoldenRod))) ; one ellipse will serve as two petals: (define petals2 (ellipse 50 10 200 'MediumSeaGreen)) ; make-blossom: natnum -> image ; Return a flower-center, with 2*n petals. ; (define (make-blossom n) (make-blossom-help n n)) ; make-blossom-help: natnum, natnum -> image ; Return a flower with 2*i petals, out of 2*n total. ; (define (make-blossom-help i n) (cond [(zero? i) empty-image] [(positive? i) (overlay (rotate (* i (/ 360 n 2)) petals2) (make-blossom-help (sub1 i) n))])) (define the-blossom (make-blossom 7)) ; Add the stem, whose height is the same as the blossom: (define flower (overlay/offset the-blossom 0 (/ (image-height the-blossom) 2) (line 0 (image-height the-blossom) 'black))) (define house-with-flowers (place-image (circle 30 'solid 'yellow) 250 0 ; house+flowers, enclosed in a scene: (overlay/align 'middle 'bottom (beside/align 'bottom flower flower house-image flower) (empty-scene 250 180)))) |
home—lectures—exams—hws—breeze (snow day)
©2012, Ian Barland, Radford University Last modified 2012.Oct.10 (Wed) |
Please mail any suggestions (incl. typos, broken links) to ibarland ![]() |
![]() |