#~ Copyright (c) 2014 Jonathan Whitaker #~ Permission is hereby granted, free of charge, to any person obtaining a copy #~ of this software and associated documentation files (the "Software"), to deal #~ in the Software without restriction, including without limitation the rights #~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell #~ copies of the Software, and to permit persons to whom the Software is #~ furnished to do so, subject to the following conditions: #~ The above copyright notice and this permission notice shall be included in #~ all copies or substantial portions of the Software. #~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE #~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, #~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN #~ THE SOFTWARE. # Inspiration drawn from http://math.andrej.com/category/random-art/ . And by 'Inspiration drawn.." I mean it was his # cool stuff that sparked this idea, and I may have stolen one or two of his functions (with his permission!). If you're going to # make use of this code please make sure the credit goes back to him, and also to me (Jonathan Whitaker, www.gdriv.es/johnowhitaker) import turtle #The functions I'll be using def sin(x): return (2.718281828459045**(x*1j)).imag def cos(x): return (2.718281828459045**(x*1j)).real def Sin(c, phase, freq): return (sin(phase + freq * c[0]),sin(phase + freq * c[1]),sin(phase + freq * c[2])) def Cos(c, phase, freq): return (sin(phase + freq * c[0]),sin(phase + freq * c[1]),sin(phase + freq * c[2])) def bSin(c, phase, freq): freq = freq/10.0 return (sin(phase + freq * c[0]),sin(phase + freq * c[1]),sin(phase + freq * c[2])) def bCos(c, phase, freq): freq = freq/10.0 return (sin(phase + freq * c[0]),sin(phase + freq * c[1]),sin(phase + freq * c[2])) def Well(c): return ((1 - 2 / (1 + c[0]*c[0])** 8), (1 - 2 / (1 + c[1]*c[1])** 8), (1 - 2 / (1 + c[1]*c[1])** 8)) def Tent(c): return ((1 - 2 * abs(c[0])), (1 - 2 * abs(c[1])), (1 - 2 * abs(c[2]))) def Sum(a, b): #actually average :P r1, g1, b1 = a r2, g2, b2 = b r3, g3, b3 = ((r1+r2)/2.0, (g1+g2)/2.0, (b1+b2)/2.0) return [r3, g3, b3] def Product(a, b): r, g, b = a[0]*b[0], a[1]*b[1], a[2]*b[2] return(r, g, b) def Mod(x,y): (r1,g1,b1) = x (r2,g2,b2) = y try: r3 = r1 % r2 g3 = g1 % g2 b3 = b1 % b2 return (r3, g3, b3) except: return (0,0,0) def Mix(a, b, c): (r1,g1,b1) = a (r2,g2,b2) = b w1, w2, w3 = (c[0]+1)/2, (c[1]+1)/2, (c[2]+1)/2 r, g, b = (w1*r1+(1-w1)*r2), (w2*g1+(1-w2)*g2), (w3*b1+(1-w3)*b2) return (r, g, b) bob = turtle.Turtle() bob.ht() bob.pensize(2000) bob.forward(1) bob.pensize(1) turtle.tracer(1000) def draw(function, xstart, ystart, xsize, ysize): #xstart, ystart, xsize, ysize = 0, 0, 256, 256 for y in range(ystart, ystart+ysize, 1): bob.penup() bob.goto(xstart, y) bob.pendown() for x in range(xstart, xstart+xsize, 1): u = 2 * float((x-xstart)/250.0) - 1.0 v = 2 * float((y-ystart)/256.0) - 1.0 X = (u, u, u) Y = (v, v, v) exec(function) r,g,b = (a[0]+1.0)/2,(a[1]+1.0)/2,(a[2]+1.0)/2 r, g, b = (r-int(r)),(g-int(g)), (b-int(b)) #stop invalid colours bob.color(r, g, b) bob.forward(1) turtle.clear() print function draw('a = Well(Mix(Mix(bCos(Sum(X, Product(Y, Y)), 3.02001292317, 2.32109206029), Mix(X, Y, Y), Sum((0.758050721771132, 0.22485439469955082, 0.8909725701161852), X)), Mod(Mix(Y, X, Y), Tent(X)), bCos(Sum(Product((0.0900006170476797, 0.991943272743145, 0.32329566333949544), (0.01520765634544996, 0.4435305107427775, 0.12860730821286004)), Product(Mix(X, X, Y), Mod(X, (0.7671522537642487, 0.40489079867407174, 0.7607519581821848)))), 0.564886284696, 3.59862939928)))', 30, 22, 256, 256) draw('a = Well(Sum(Well(Mix((0.5191673305223623, 0.16469728452479093, 0.8835335508873503), Y, (0.019148691166625986, 0.1257941003735067, 0.5208588657151579))), Well(Mix(Y, X, Y))))', -286, 22, 256, 256) draw('a = Product(Product(Sum(Mod((0.46426970212980423, 0.6865556377999732, 0.20342967973875203), (0.8023552568293205, 0.7427859986551726, 0.4764325597419743)), Well(X)), Tent(Tent(X))), Tent(Tent(Mod(X, Y))))', -286, -278, 256, 256) draw('a = Well(Mix(Mod(Product((0.6708812683648796, 0.3107618525011592, 0.6937389341079395), X), Well(Y)), bSin(Sum(Product(Y, (0.776238672916275, 0.530947648534944, 0.0839970806297533)), Product(bSin(Sum(X, Product((0.7415921100821066, 0.259318723395043, 0.2727435893896609), X)), 1.34300549474, 2.36343320062), Tent(Y))), 2.80540545004, 5.60807613484), Mix(Well(X), Tent(Y), Mod(Y, Y))))', 30, -278, 256, 256) turtle.exitonclick()