Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Image
- import numpy as np
- from random import uniform
- from math import sqrt, cos, sin, pi
- WIDTH, HEIGHT = 800, 800
- directory = 'C:/PythonWorkspace/Images/GateAnimation/RotX'
- a, b, c = 1.0, 1.0, 1.0 #Coefficients
- period = 600 #Period of transform
- epsilon = 2 * pi / period #Small value to transform by
- iterations = 600 #Number of series terms to sum
- points = 2000000 #Number of randomly chosen test points
- escapeRadius = 2.0 #"Bailout radius" for determining if C diverges
- imagShift, realShift = 0.0, 0.3 #Shift view of complex plane
- ratioReal, ratioImag = WIDTH / 2.8, HEIGHT / 2.8 #Screen:C-plane ratio
- for n in xrange( period ):
- counters = np.zeros( ( WIDTH, HEIGHT ) )
- img = Image.new( 'RGB', ( WIDTH, HEIGHT ), ( 200, 200, 200 ) )
- a = a #Transform coefficients
- b = b * cos( epsilon ) - c * sin( epsilon )
- c = b * sin( epsilon ) + c * cos( epsilon )
- for i in xrange( points ):
- z = 0
- path = []
- realPart = uniform( -2.4, 1.0 )
- imagPart = uniform( -1.8, 1.8 )
- C = complex( realPart, imagPart )
- for j in xrange( iterations ):
- q = z.conjugate() #Change of variable
- z = a * q**3 + b * q**2 + c * q + C #Generating Function
- path.extend( [ z.imag + imagShift, z.real + realShift ] )
- if abs( z ) > escapeRadius:
- while path:
- xValue = int( path.pop() * ratioReal ) + WIDTH / 2
- yValue = int( path.pop() * ratioImag ) + HEIGHT / 2
- if xValue > 0 and yValue > 0:
- if xValue < WIDTH and yValue < HEIGHT:
- counters[ xValue ][ yValue ] += 1
- counters[ xValue ][ -yValue ] += 1
- break
- maxCount = np.amax( counters )
- for x in xrange( WIDTH ): #Develop image from hit counts
- for y in xrange( HEIGHT ):
- color = int( 255 * ( sqrt( counters[x][y] / maxCount ) ) )
- img.putpixel( ( y, x ), ( color / 2, color / 2, color ) )
- img.save( directory + '/frame' + str( n + 1 ) + '.bmp' )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement