Question: Write a racket program that creates a fractal image. Creating a 2 d fractal is easy: Draw a shape or shapes Then once or twice
Write a racket program that creates a fractal image. Creating a d fractal is easy: Draw a shape or shapes Then once or twice scale them down, maybe rotate them, maybe move them, maybe change the color, Draw them again Repeat For example: define makeImage depth rotateAmount inputPolygonwhen depth ; loop on polygons. send inputPolygon scale ; polygon scale send inputPolygon rotate rotateAmount ; polygon rotate in radians send inputPolygon translate ; polygon translate drawToScreen inputPolygon ; draw polygon makeImage depth rotateAmount inputPolygon This is just an example that takes a polygon, scales it a little, rotates it a little, translates it a little and then draws it The numbers for the scaling, translating and rotating are nothing special. Different numbers will give different patterns. Changing the numbers a little bit each time the function is called will also generate different patterns. To get the look of something getting continually smaller, the scale numbers are always less than one. For branching, here's an example: define makeImage depth rotateAmount inputPolygonwhen depth ;; loop on polygons. move it a little, then draw itsend inputPolygon scale ; polygon scale send inputPolygon rotate rotateAmount ; polygon rotate in radians send inputPolygon translate ; polygon translate drawToScreen inputPolygon ; draw polygonset numPoly numPolymakeImage depth rotateAmountduplicatePolygon inputPolygonmakeImage depth rotateAmount inputPolygon Look at the branching function: makeImage depth rotateAmountduplicatePolygon inputPolygon This will draw polygons spinning off in the opposite direction. This call to makeImage is not called with the input polygon, but with a duplicate of it That is so the inputPolygon is unchanged for the call to makeImage that follows. You don't need to call the branching function every time. You could call it when the value of depth is even, or divisible by or use the random number generator to branch randomly. Branching every time can generate a large number of polygons. If the above function is called with a depth value of then a million polygons will be drawn. Drawing actual treelike shapes requires some additional bookkeeping. The x and y coordinates of the end of the current branch need to be calculated so that a new branch can be placed there. To do this, initialize x and y to the end of the first branch and then perform the same transformations on x and y that are done to each branch. Notes on Random numbers Random numbers are called pseudorandom because a computer can't actually select a random number. The random number generator creates a sequence of numbers that have a randomlooking distribution. If a program is restarted, the number generator will create the same exact sequence of numbers. This can be helpful because if you are creating an image that uses random numbers, this means that you can create the exact same image from the same sequence of numbers. It's possible to start a different sequence of numbers. This is done by selecting a different seed number. randomseed for example, restarts the random number sequence with the seed If you wanted to have a different sequence of numbers every time a program is run, a common thing to do is to set the random seed based upon the current time in milliseconds: randomseed bitwiseand currentmilliseconds #xfffffff Duplicating and resetting polygons ;define newPolygon oldPolygon ; does not duplicate polygon. newPolygon points to oldPolygon ; duplicates polygon define newPolygon new dcpathsend newPolygon append oldPolygon ; reset polygon send inPoly reset ; deletes all points send inPoly moveto ; adds new points or readds old points send inPoly lineto send inPoly lineto send inPoly close Assignment requirements: A unique d fractal that approximates your assigned image. An exact match is of course, not required. The goal is to write code that generates a pattern that's similar to the assigned image. If your image has multiple plants, then your assignment should have them too. d graphics are not required. The goal is to create a d fractal that simulates the image. This can be done using the polygon scale, translate, and rotate functions that we've covered so far. Although these are pictures of three dimensional plants, the goal is to create a twodimensional pattern that matches the image. Rest of the instructions, I posted in the screenshot. The picture is what we need to create through this instruction in DRracket code. Minimum mathbf polygons
That may sound like a lot, but it's very easy to do You want to avoid creating an image with hundreds of millions of polygons.
You will need to calculate your image times for the last assignment, so you want an image that you can generate in a reasonabl
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
