Question

This is what I am supposed to do: I think he wants us to do this in Java. Thank you! Fractals (a)...

This is what I am supposed to do:

I think he wants us to do this in Java. Thank you!

Fractals

(a) Write a function in Racket to create a Koch curve fractal. The Koch curve can be constructed by starting with a line (segment), then recursively altering each line segment as follows:

divide the line segment into three segments of equal length.

draw an equilateral triangle that has the middle segment from step 1 as its base and points outward.

remove the line segment that is the base of the triangle from step 2.

The real fractal follows this procedure an infinite number of times. We don’t have that much time. So, your function will take two arguments, the size of the curve (first line segment in pixels), and the number of iterations to apply the fractal generating algorithm.

Your code will start out:

#lang racket ; A picture

(require 2htdp/image)

Note that the 0th iteration of the fractal is a straight line.

This is the code he gave us to start off with:

Starter code for problem 3:

(define (koch-curve length iteration)

(if (= iteration 0) (line length 0 "black") "do other stuff including 4 recursive calls"))

0 0
Add a comment Improve this question Transcribed image text
Answer #1

NOTE:- Please upvote if you find the solution useful in any way.

// For any doubts or queries, use the comment section below.

The Koch curve is a mathematical curve and one of the earliest fractal curves to have been described. It is based on the Koch curve, which appeared in a 1904 paper titled “On a continuous curve without tangents, constructible from elementary geometry” by the Swedish mathematician Helge von Koch.

I don't fully understand the code provided by you, but below is an example of how you can create a koch-curve in python.

It has all the requirements you needed including calling of the function with two arguments i.e, size of curve and number of iterations.

CODE:

from turtle import *

# function to create koch snowflake or koch curve
def koch_curve(lengthSide, levels):
   if levels == 0:
       forward(lengthSide)
       return
   lengthSide /= 3.0
   koch_curve(lengthSide, levels-1)
   left(60)
   koch_curve(lengthSide, levels-1)
   right(120)
   koch_curve(lengthSide, levels-1)
   left(60)
   koch_curve(lengthSide, levels-1)

# main function
if __name__ == "__main__":
   # defining the speed of the turtle
   speed(0)                 
   length = 300.0

   # Pull the pen up – no drawing when moving.
   # Move the turtle backward by distance, opposite
   # to the direction the turtle is headed.
   # Do not change the turtle’s heading.         
   penup()                     

   backward(length/2.0)

   # Pull the pen down – drawing when moving.         
   pendown()         
   for i in range(3):     
       koch_curve(length, 4)
       right(120)

   # To control the closing windows of the turtle
   mainloop()     
// Code ends here

Add a comment
Know the answer?
Add Answer to:
This is what I am supposed to do: I think he wants us to do this in Java. Thank you! Fractals (a)...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT