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 2d 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 inputPolygon)(when (> depth 0) ; loop on polygons. (send inputPolygon scale 0.50.5) ; polygon scale (send inputPolygon rotate rotateAmount) ; polygon rotate in radians (send inputPolygon translate 1.51.5) ; polygon translate (drawToScreen inputPolygon) ; draw polygon (makeImage (- depth 1) 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 inputPolygon)(when (> depth 0) ;; loop on polygons. move it a little, then draw it.(send inputPolygon scale 0.50.5) ; polygon scale (send inputPolygon rotate rotateAmount) ; polygon rotate in radians (send inputPolygon translate 1.51.5) ; polygon translate (drawToScreen inputPolygon) ; draw polygon)(set! numPoly (+1 numPoly))(makeImage (- depth 1)(- rotateAmount)(duplicatePolygon inputPolygon))(makeImage (- depth 1) rotateAmount inputPolygon))) Look at the branching function: (makeImage (- depth 1)(- rotateAmount)(duplicatePolygon 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 5, 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 20, then a million polygons will be drawn. Drawing actual tree-like 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 pseudo-random because a computer can't actually select a random number. The random number generator creates a sequence of numbers that have a random-looking 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. (random-seed 37), for example, restarts the random number sequence with the seed 37. 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: (random-seed (bitwise-and (current-milliseconds) #x7fffffff)) Duplicating and resetting polygons ;(define newPolygon oldPolygon) ; does not duplicate polygon. newPolygon points to oldPolygon ; duplicates polygon (define newPolygon (new dc-path%))(send newPolygon append oldPolygon) ; reset polygon (send inPoly reset) ; deletes all points (send inPoly move-to 00) ; adds new points - or re-adds old points (send inPoly line-to 11)(send inPoly line-to 21.5)(send inPoly close) Assignment requirements: A unique 2d 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. 3d graphics are not required. The goal is to create a 2d 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 two-dimensional 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{50000}\) 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 600 times for the last assignment, so you want an image that you can generate in a reasonabl
Write a racket program that creates a fractal

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!