TURN IN THIS ASSIGNMENT USING WEBWORK!!!
Do this homework using DrScheme. (Save the file as a ".scm" file--that is, with a .scm extension.)
Your parameters must be in the same order as they are shown here. If you are unsure, ask your TA. You will lose credit otherwise.
Your functions should be named exactly as they are shown in each problem.
Follow the HW Skeleton, these homeworks will be autograded and must be in the specified format. You will lose credit otherwise.
Any submissions which don't execute cleanly (i.e. no errors when you click Execute) may receive a grade of zero.
If you do not submit a .scm file, you may receive a grade of zero.
Remember that you must be in "Advanced Student Mode".
For all problems, you should read the words program and function to mean "program or group of programs," or "function or group of functions."
Each problem in this assignment is worth 5 points.
Credit will be given per problem on an all-or-nothing basis this means every function must work and have a correct design recipe to receive credit.
TAs are permitted to assist you ONLY with problems 1 through 3.
Problem 4 MAY NOT be attempted until problems 1 through 3 are complete.
Be sure to keep in mind that some functions will entail other functions to be written we purposely have not labeled them to see how high your abstraction is on your own. This means that just because say write a function, doesn't mean that you should write only one function for some of these problems.
Keep in mind the general guidelines for abstraction and the creation of local functions.... If you think you might need to reuse a function later on, don't make it local
In all this assignment can be worth upto 28% extra credit on a given homework meaning if you got a 72 on one homework it can be turned into a 100.
For part of this assignment, you will be creating a fractal. Some basic concepts need to be understood in how coordinates work on a computer screen before we continue.
On a computer screen, coordinates work in terms of placement from the upper-left-hand corner of the screen. This makes it possible for every coordinate on the screen to be represented by any pair of positive numbers. Lets assume for a moment that the box shown below is a computer screen that is set to a 800 x 640 resolution.
A
B
C
The letter A would be in the (0,0) position on the computer screen. The letter B is half way across on the "x-axis" and half way down on the "y-axis" represented by the (400,320) position coordinate. The letter C would be in the (800,640) coordinate position.
For this homework, we are going to be using some basic geometric formulas in order to generate our fractal. In order to do this, we need a way to translate between "normal" geometric coordinates, and those on a computer screen. In order to do this, only three things have to be known
- The point that you want to convert
- The coordinate system you are in
- The point that is the "center" of your coordinate system.
The first two parts are rather easy, but the third one might be a problem at times. In most geometric coordinate systems, the origin (0,0) is the center of the coordinate systems. For the purposes of this assignment, this will do just fine. On a computer screen this is slightly different. When graphics are done with Dr.Scheme, a small segment of the screen is portioned off into a window called a CANVAS. A canvas lets you draw on it through some built-in functions provided in the Dr.Scheme environment. The coordinate system of a canvas works the same as that of a computer screen. The key difference between the canvas and the computer screen is that you can make the canvas an arbitrary size, thus making it easy for you to also calculate the center of the canvas. In order to facilitate drawing processes in Dr.Scheme, a teachpack called draw.ss is provided. You may want to stop and take some time to use the Help Desk to familiarize yourself with the functions in draw.ss.
In order to convert between the geometric coordinate system and the graphical coordinate system, the work is minimal
The contract, purpose, and definition for this process is given below
;; geometric->graphic : posn posn -> posn
;;
;; Purpose:
;; Converts a coordinate given in a geometric system
;; to a coordinate on a computer screen centered at the
;; the point represented by the first POSN structure
;; consumed
(define (geometric->graphic center point)
(make-posn (+ (posn-x point) (posn-x center))
(- (posn-y center) (posn-y point))
)
)
You are welcome to use this function in this assignment without providing any
further documentation or design-recipe components.
You are provided with a way to convert between geometric to graphical coordinates. Write a function called graphic->geometric. The function should consume two posn structures and return the desired coordinate in the geometric system. The first posn structure will represent the "center point" of the graphics display area. The second posn structure will represent the point you wish to convert into geometric terms. Your function will be called in the following manner
(graphic->geometric <center point> <point to convert>)
The sample calls of this function would produce the following output
> (graphic->geometric (make-posn 200 200) (make-posn
205 195))
(make-posn 5 5)
> (graphic->geometric (make-posn 480 230) (make-posn
205 195))
(make-posn -275 35)
Now we need to create a function that will rotate a point through a given angle about the origin in the geometric system. The function should be called rotate which consumes a posn structure and an angle measurement (taken in degrees). The function will then return the given posn structure as if it was rotated about the origin of the geometric system through the given angle. The formula for rotating a point Q through a given angle A is
x = Qx cos A - Qy sin A
y = Qx sin A + Qy cos A
Your function will be called in the following manner
(rotate <point> <angle>)
The sample calls of this function would produce the following output
> (rotate (make-posn 1 0) 90)
(make-posn #i6.123031769111886e-017 #i1.0)
The sin and cos function in Dr.Scheme consume angle measurements that are in radian measurements. You will have to convert your angle from degrees to radians inside of your rotate function.
Write a function called rotate-graphic that consumes two posn structures and a angle. The first posn structure consumed represents a point in the graphical system that you wish to rotate about, the second posn structure consumed represents the point in the graphical system you wish to rotate. The angle (measured in degrees) is the amount that you wish to rotate the second point by. Your function should return the corresponding point in the graphical system once the rotation is complete.
Your function will be called in the following manner
(rotate-graphic <center point> <point to rotate> <angle measurement>)
Sample output
> (rotate-graphic (make-posn 300 400) (make-posn 325
390) 180)
(make-posn #i275.0 #i410.0)
> (rotate-graphic (make-posn -325 400) (make-posn -325
390) 180)
(make-posn #i-325.0 #i410.0)
You are now going to put your fractal together. Write a function called dragon that will take in two posn structures and an angle measurement. The function will use generative recursion to create the following fractal.

This fractal was created using the draw.ss teachpack. The commands used for this particular fractal will be given later, but lets go over the algorithm used to produce the image above.
Your function takes in two points and a initial angle. The two points can be called A and B. When the algorithm starts, it checks to see if A and B are too close to even worry about proceeding. In this case A and B are too close when the distance between them is less than or equal to 2 pixels. If this happens, the algorithm stops.
Assuming the two points are not too close, a line is drawn from point A to point B. A third point called C is then calculated. Point C, when rotated 45 degrees about point A should should form a right-isolese triangle with the segment AB when connected. This ultimately means that to calculate the placement of point C on the line AB, it's half the length of the segment AB times the square root of 2 we could bore you with the details of how to derive this formula, but that's a whole different story. The important thing that you see now is that you can find how far from point A point C should be on the segment AB.
Once you get the placement of point C on the segment AB, you then should
restart the algorithm again... You should restart it once with the point
A as your first starting point and point C as the second point. The trick
though is that point C MUST BE ROTATE 45 degrees about point A from it's
original placement on segment AB. The algorithm should also be started again
with point B being the starting point, and once again point C rotated 45
degrees about point A from its orginial
placement on the segment AB. ,but this time about
point B.
The image above is actual two calls to the dragon function. The commands below show calls that created the image (note that these commands may take a while to complete on some computers. Chances are if you are waiting more than 3 minutes to have any of these calls complete, you are doing something incorrectly.
> (stop)
> (start 400 400)
> (dragon (make-posn 100 350) (make-posn 100 250) 0)
true
> (dragon (make-posn 25 150) (make-posn 125 150) 0)
true
Your function will not be autograded, your TA will call the function and wait for the image to appear on the screen. If the image takes a vast amount of time to appear, your TA will deduct all the working points for the function. FOR THIS PROBLEM ONLY YOU SHOULD COMMENT OUT YOUR TEST SECTION IN THE DESIGN RECIPE (this is to avoid an long delays for the TAs when they execute your file).
You've seen an "ugly" version of the fractal already. You can also modify your function from problem 4 to do the following variations
In this variation, the lines that aren't really part of the image are not drawn. These lines are still used for calculation purposes, but they were not drawn. An additional 3 points will be awarded to problem 4 if this can be done.

