0

I've write several function that need to used in function mandelbrot to draw it, here are these:

# sp that takes integer n, element y, list xs. insert the specified element y after every n elements.
sp 1 'a' ['b','c','d'] = ['b','a','c','a','d','a']

# plane that gives (x/r,y/r) where x and y are int, -2<x/r<1,-1<y/r<1.
plane 1 = [(-2.0,-1.0),(-1.0,-1.0),(0.0,-1.0),(1.0,-1.0),(-2.0,0.0),(-1.0,0.0),(0.0,0.0),(1.0,0.0),(-2.0,1.0),(-1.0,1.0),(0.0,1.0),(1.0,1.0)]

# orbit, is the same in this question : Haskell infinite recursion in list comprehension

print(take 3 (orbit(2,1))) = [(2,1),(5,5),(2,51)]

# find, is the same in this questionL haskell: recursive function that return the char in a tuple list with certain condition(compare)

print(find 0.4 [(0.15,'#'),(0.5,'x'),(1,'.')]) == 'x' ## >all will print char ' '

So I'm trying to use sp,plane,orbit,and find,this four function with a new func named norm, that calculate the distances of points from the origin:

norm (x,y) = x*x + y*y

Now is my question:

I'm little confused about what should do and why that, so I think I will first use plane to all the points, then use orbit to print the list with the point? And after this, what should I do? Can anyone explain these relationship of each function and what I should do?

Separate code or explanation are fine. The mandelbrot function should draw something that looks like mandelbrot contains '#' 'x' '.' and ' '.

Community
  • 1
  • 1
o1xhack
  • 87
  • 9
  • 2
    Do you understand the definition of the Mandelbrot set (mathematically, unrelated to Haskell)? – user253751 Oct 04 '16 at 02:36
  • 1
    You should split the task into 2 parts. Step 1 is print an image with colour based on a simple function, such as the distance of each point in a plane from the origin, with the colour representing the distance. You can make an array of colour values, indexed by distance. For distances larger than the array length, take the *modulus* of the distance, so the colours used will wrap. Step 2 is to write a Mandelbrot implementation using the *iterations* at each point as the colour index. The *scale* of the x-y plane will be different, so you need to convert the pixel coordinates to the range ±2. – Weather Vane Oct 05 '16 at 17:20

1 Answers1

0

I figure it out.

So what I need to do is:

-- find all points using plane r
-- using orbit list comprehension to take the orbit with one point at index i
-- using norm(x,y) to calculate the distance of orbit to the original
-- using find to give the list of char
-- finally using sp to put character with 'n'
-- all these stuff can using the list comprehension combine together.

Just for anyone who want to know how to solve this.

o1xhack
  • 87
  • 9