Usual rules for the code golf. Here is an implementation in python as an example
from PIL import Image
im = Image.new("RGB", (300,300))
for i in xrange(300):
print "i = ",i
for j in xrange(300):
x0 = float( 4.0*float(i-150)/300.0 -1.0)
y0 = float( 4.0*float(j-150)/300.0 +0.0)
x=0.0
y=0.0
iteration = 0
max_iteration = 1000
while (x*x + y*y <= 4.0 and iteration < max_iteration):
xtemp = x*x - y*y + x0
y = 2.0*x*y+y0
x = xtemp
iteration += 1
if iteration == max_iteration:
value = 255
else:
value = iteration*10 % 255
print value
im.putpixel( (i,j), (value, value, value))
im.save("image.png", "PNG")
The result should look like this
Use of an image library is allowed. Alternatively, you can use ASCII art. This code does the same
for i in xrange(40):
line = []
for j in xrange(80):
x0 = float( 4.0*float(i-20)/40.0 -1.0)
y0 = float( 4.0*float(j-40)/80.0 +0.0)
x=0.0
y=0.0
iteration = 0
max_iteration = 1000
while (x*x + y*y <= 4.0 and iteration < max_iteration):
xtemp = x*x - y*y + x0
y = 2.0*x*y+y0
x = xtemp
iteration += 1
if iteration == max_iteration:
line.append(" ")
else:
line.append("*")
print "".join(line)
The result
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
**************************************** ***************************************
**************************************** ***************************************
**************************************** ***************************************
**************************************** ***************************************
**************************************** ***************************************
**************************************** ***************************************
**************************************** ***************************************
*************************************** **************************************
************************************* ************************************
************************************ ***********************************
*********************************** **********************************
************************************ ***********************************
************************************* ************************************
*********************************** **********************************
******************************** *******************************
**************************** ***************************
***************************** ****************************
**************************** ***************************
************************ * * ***********************
*********************** * * **********************
******************** ******* ******* *******************
**************************** ***************************
****************************** *****************************
***************************** * * * ****************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
Edit:
Rules for the ASCII art:
- size in rows/columns is parametrized and the code must work with any valid value.
- at least three level of differentiation in density depending on the iteration count (so my prototype up there is not compliant)
- oriented horizontally (so my prototype up there is not compliant)
- critical parameters are fixed (max iteration = 1000, runaway value xx + yy <= 4.0)
Rules for the graphic:
- size in rows/columns is parametrized and the code must work with any valid value.
- at least three level of colors, gray scale
- oriented horizontally (my prototype is compliant)
Alternatively, you can use ASCII art.
<- nice. – Stillness