def test_mandelbrot_init(self): ans = mandelbrot(500) correct_x, correct_y = np.meshgrid(np.linspace(-2, 1, 500), np.linspace(-1.5, 1.5, 500)) correct_c = correct_x + 1j * correct_y self.assertTrue(np.array_equal(ans.c, correct_c))
def main(): # Question 1 sol1 = create_array() print 'The 2-D array is \n', sol1.array print '\n' print 'The new array for question 1a is \n', sol1.picking_row() print '\n' print 'The new array for question 1b is \n', sol1.picking_column() print '\n' print 'The new array for question 1c is \n', sol1.picking_section() print '\n' print 'The new array for question 1d is \n', sol1.picking_range() print '\n' # Question 2 print 'The array for question 2 is \n', divide_array() print '\n' # Question 3 generate_randArray() print '\n' # Question 4 candidate_set = mandelbrot(500) candidate_set.mandelbrot_iter() candidate_set.form_mask()
def test_compute2(self): np.seterr(over = 'ignore', invalid = 'ignore') X = np.linspace(-2,1,200) Y = np.linspace(-1.5,1.5,200) mask = np.zeros((len(X),len(Y))) for i in range(len(X)): for j in range(len(Y)): mask[i,j] = mandelbrot(X[i],Y[j]).compute self.assertTrue(np.array_equal(mandelbrot_compute2(-2,1,-1.5,1.5,200),mask))
def test_init(self): x = -2 y = -1 m = mandelbrot(x,y) self.assertTrue(m.x == x) self.assertTrue(m.y == y) self.assertTrue(m.N_max == m.some_threshold) self.assertTrue(m.compute == False)
def test_init(self): x = -2 y = -1 m = mandelbrot(x, y) self.assertTrue(m.x == x) self.assertTrue(m.y == y) self.assertTrue(m.N_max == m.some_threshold) self.assertTrue(m.compute == False)
def test_compute2(self): np.seterr(over='ignore', invalid='ignore') X = np.linspace(-2, 1, 200) Y = np.linspace(-1.5, 1.5, 200) mask = np.zeros((len(X), len(Y))) for i in range(len(X)): for j in range(len(Y)): mask[i, j] = mandelbrot(X[i], Y[j]).compute self.assertTrue( np.array_equal(mandelbrot_compute2(-2, 1, -1.5, 1.5, 200), mask))
def drawmandelbrotset(): im = Image.new('RGB', (WIDTH, HEIGHT), (0, 0, 0)) draw = ImageDraw.Draw(im) for x in range(0, WIDTH): for y in range(0, HEIGHT): # Convert pixel coordinate to complex number c = complex(RE_START + (x / WIDTH) * (RE_END - RE_START), IM_START + (y / HEIGHT) * (IM_END - IM_START)) # Compute the number of iterations m = mandelbrot(c) # The color depends on the number of iterations color = 255 - int(m * 255 / 80) # Plot the point draw.point([x, y], (color, color, color)) im.save('output.png', 'PNG')
def test_compute1(self): self.assertTrue(mandelbrot(0,0).compute)
arr = np.random.rand(10,3) print "A 10x3 array with random values in the range [0,1]:\n", arr, "\n\n" #find the abs difference between values and 0.5. then do argsort to get the ordering arr_diff = np.argsort(np.abs(arr-0.5)) #the 0th column in arr_diff the closest value to 0.5 col = arr_diff[:,0:1].ravel().tolist() #use fancy indexing to pull the correct values print "The values closest to 0.5 in each row are:\n", arr[np.arange(arr.shape[0]),col], "\n\n" print "PROBLEM FOUR\n" print "See directory for \'mandelbrot.png\'.\n" #Create a Mandelbrot object with max = 50, threshold = 50 and range [-2,1]x[-1.5,1.5]. I chose to use grid size 1000x1000. mandel = mandelbrot(50, 50, [-2,1], [-1.5,1.5], 1000) #Returns the grid with the Mandelbrot iteration applied to it iter_mandel = mandel.iterate(mandel.z) #Get the mask of the iteration below the threshold 50 mandel_mask = mandel.get_mask(iter_mandel) #Get the image in png format mandel.get_im(mandel_mask)
print "PROBLEM THREE\n" #A 10x3 array with entries in the range [0,1] arr = np.random.rand(10, 3) print "A 10x3 array with random values in the range [0,1]:\n", arr, "\n\n" #find the abs difference between values and 0.5. then do argsort to get the ordering arr_diff = np.argsort(np.abs(arr - 0.5)) #the 0th column in arr_diff the closest value to 0.5 col = arr_diff[:, 0:1].ravel().tolist() #use fancy indexing to pull the correct values print "The values closest to 0.5 in each row are:\n", arr[ np.arange(arr.shape[0]), col], "\n\n" print "PROBLEM FOUR\n" print "See directory for \'mandelbrot.png\'.\n" #Create a Mandelbrot object with max = 50, threshold = 50 and range [-2,1]x[-1.5,1.5]. I chose to use grid size 1000x1000. mandel = mandelbrot(50, 50, [-2, 1], [-1.5, 1.5], 1000) #Returns the grid with the Mandelbrot iteration applied to it iter_mandel = mandel.iterate(mandel.z) #Get the mask of the iteration below the threshold 50 mandel_mask = mandel.get_mask(iter_mandel) #Get the image in png format mandel.get_im(mandel_mask)
def test_compute1(self): self.assertTrue(mandelbrot(0, 0).compute)