from PIL import Image
from math import sin
#varialbes you can change:
#distorts shape
#0 is no change, reccomend values >-1 and <1
e=0
f=0
#gives range in x and y
start=-2
end=2
#gives dimension of image
dim=10000
#gives number of iterations to check. higher numbers means longer computing, closer to center edges.
#increase resolution for a better picture first.
q=100
def mixsquare(toup,e,f):
	x,y,z,w=toup
	c=x*x-y*y+z+e
	d=2*x*y+w-f
	return (c,d,z,w)
data=[]
im=Image.new('RGB',(dim,dim))
c=start*dim
while c<dim*end:
	d=start*dim
	while d<dim*end:
		cp=1.0*c/dim
		dp=1.0*d/dim
		mix=(cp,dp,cp,dp)
		tic=0
		while cp*cp+dp*dp<4 and tic<q:
			mix=mixsquare(mix,e,f)
			cp,dp,ww,zz=mix
			tic=tic+1
		#	print cp,dp
		a=int(cp*255.0)
		b=int(dp*255.0)
#you can change the things inside data.append((#,#,#))
#it would likely be better if you designed them to range from 0-255
#		if tic==q:
		v=int((128-128*sin(a*a+b*b)))
		data.append((v,v,v))
#		elif tic%3==0:
#			data.append((a,int((510-a-b)/2.0),b))
#		elif tic%3==1:
#			data.append((abs(a-b),(b+a)/2,b*a/255))
#		elif tic%3==2:
#			data.append((a,a*int((510-a-b)/510.0),int(b*a/255.0)))
		d=d+end-start
	c=c+end-start
im.putdata(data)
im.save('Output.jpg')
