[SOLVED] 代写 This assignment is due on Wednesday, 2/6 at 11:59 PM. Submit it using the handin server as assignm

30 $

File Name: 代写_This_assignment_is_due_on_Wednesday,_2/6_at_11:59_PM._Submit_it_using_the_handin_server_as_assignm.zip
File Size: 989.1 KB

SKU: 7945079683 Category: Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Or Upload Your Assignment Here:


This assignment is due on Wednesday, 2/6 at 11:59 PM. Submit it using the handin server as assignm
Remember to follow the design recipe for each function. In particular, every type mentioned in a sign introduced by a data definition, except for these well-known types: Number, Image, String, Boolean, K MouseEvent, Anything.
Note: In this assignment, you must develop your own data definition and your own structures. You m built-in primitive types, not any existing structures.
Exercise 1 Develop a data definition SolarSystem that is either a sun or a planet. Your data definiti look like this:
; A SolarSystem is one of: ;-…
;-…
To support this data definition, define a structure sun and a structure planet:
A sun structure stores a solar system whose only object is a sun. It should contain no information oth
fact that it is a sun. (This structure is similar to the engine in Lab 4.)
A planet structure stores a solar system whose outermost object is a planet. It should contain a dista next inner object, and should also contain the inner solar system. (This structure is like the train with you defined in Lab 4.) Its inner solar system may be either another planet or a sun. (This inner syste train with a last wagon removed.)
Exercise 2 Define three examples of SolarSystems.
Exercise 3 Write the template process-solar-system for your data definition SolarSystem.
Exercise 4 Design a function distance-of-solar-system which accepts a SolarSystem and re distance between its outermost object and its center. For example, the distance of a sun should be zer sun is located at the center of the solar system. To take another example, say we have a system of 3 o sun, an inner planet1 with a distance of 100, and an outer planet2 with a distance of 200; then, the di system (planet2) to the center should be 300.
Exercise 5 Design a function add-to-solar-system which accepts a SolarSystem and a distance a new SolarSystem which has the given SolarSystem plus a new planet that is the given distance away inner object. The given SolarSystem should be the inner system of the new planet.
Exercise 6 Design a function draw-solar-system which draws a SolarSystem. The sun in the So should be drawn simply as a small solid size-20 circle in the middle. Each planet in the SolarSystem s drawn as a circle whose radius is the planet¡¯s distance to the center of the solar system. So, a system o with two planets and a sun, should appear as a small solid size-20 circle in the middle, surrounded by and the radius of each ring should be that planet¡¯s distance to the center.
The overlay function will be very useful here. Remember, the overlay function takes two or mor inputs, and stacks them to build a single image. The first input goes on top of the second input, and t all lined up on their centers. For example:
(overlay (circle 20 “solid” “blue”) (circle 30 “outline” “red”))
stenalp dna snuS 1
noisruceR:5tnemngissA

produces an image where a small solid blue circle is stacked on top of a larger hollow red ring. This c example of drawing a SolarSystem with one planet and one sun.
Variations of the exercises in this section are done in lectures. Please review the code from lectures (a under Resources in Piazza) as you work the exercises. Sometimes your solutions will look similar to th lectures; this is fine.
Example Here is a sample exercise and a solution.
Sample exercise: Develop a data definition NestOfNumbers which can store arbitrarily many numbe corresponding structures named no-numbers and some-numbers. Define three examples of you definition.
Solution:
; A NestOfNumbers is one of:
; – (make-no-numbers)
; – (make-some-numbers Number NestOfNumbers)
(define-struct no-numbers []) (define-struct some-numbers [n ns])
(define ns1 (make-no-numbers))
(define ns2 (make-some-numbers 211 (make-no-numbers))) (define ns3 (make-some-numbers 37 ns2))
Exercise 7 Develop a data definition named Pair and a structure named pair for storing a pair of n representing x and y coordinates. Define three examples of your data definition.
Exercise 8 Develop a data definition PackOfPairs which can store arbitrarily many pairs of numbers data definition from the previous exercise. Name the structures you define no-pairs and some-pa three examples of your data definition.
Exercise 9 Write the templates for both data definitions you have developed, called process-pair process-pairs.
Exercise 10 Design a function called draw-pairs, which, given a PackOfPairs, visualizes each of th circle with radius 10 at location (x,y) (obtained via pair-x and pair-y) on an empty scene.
In the following exercises, we will create two interactive animations with big-bang. Both will be sim programs which use draw-pairs from Exercise 10.
In the first version, any mouse event will paint circles on the scene, and any keyboard event will undo recent painting operation (if there is one). In the second version, these operations will require specific events, “button-down” and “drag”, and a specific key event, “z”.
For big-bang, a world is always a PackOfPairs.
Exercise 11 Design an on-mouse function for big-bang called any-paint. Given a PackOfPair numbers for x and y coordinates, and a MouseEvent, any-paint causes big-bang to paint a new scene. Recall that an on-mouse function returns a world: so any-paint returns a PackOfPairs.
Design also an on-key function for big-bang called any-undo. Given a PackOfPairs and a Key undo causes big-bang to remove the most recently painted circle from the scene. Recall that an o function returns a world: so any-undo returns a PackOfPairs.
srebmun fo sriap ynaM 2

Finally, define a function run-any that takes a PackOfPairs as an initial world and runs big-ban draw-pairs, any-paint, and any-undo. Recall that big-bang returns the final world: so r returns a PackOfPairs.
Exercise 12 Design an on-mouse function for big-bang called paint. Given a PackOfPairs, tw x and y coordinates, and a MouseEvent, paint does the following. If the mouse event is “button “drag”, paint causes big-bang to paint a new circle on the scene. If the MouseEvent is anythin causes big-bang to do nothing to the scene.
Design also an on-key function for big-bang called undo. Given a PackOfPairs and a KeyEven the following. If the key pressed is “z”, undo causes big-bang to remove the most recently painte the scene. If any other key is pressed, undo causes big-bang to do nothing to the scene.
Finally, define a function run that takes a PackOfPairs as an initial world and runs big-bang wit pairs, paint, and undo. Recall that big-bang returns the final world: so run returns a PackO
The goal of this challenge section is to extend the paint program you just built so that the user can e other than the most recently painted circle. Specifically, pressing the “e” key should switch mouse e erasing circles. Pressing the “p” key should switch mouse events back to painting circles.
First, design a function that erases all circles at the mouse location (if any). This function should tak PackOfPairs and the mouse location as inputs and return a new (possibly shorter) PackOfPairs. To c circle is at the mouse location, we suggest you design a helper function that takes a Pair and the mou inputs and checks whether their distance is within the radius 10.
Second, write a new data definition for a world that stores not only a PackOfPairs, but also whether currently erase or paint. Using this new data definition, design new to-draw, on-mouse, and on- functions, and assemble them into a new big-bang.
u
o

h f
r v
e
resare :egnellahC 3

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] 代写 This assignment is due on Wednesday, 2/6 at 11:59 PM. Submit it using the handin server as assignm
30 $