Paints a picture in the abstract style.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 | # PREAMBLE
# My original intention was to create some
# disruptive visual camoflage, inspired by the pattern on
# the bark of plane trees. The result was never quite what I intended
# and several fixes had to be incorperated to aproximate what I wanted.
# The end result is effective though and reminds me of a Jackson Pollock
# or a Monet painting.
# I think that the program does quite a good job of producing an aesteticalty
# pleasing picture, through a purely mathematical process,
# though some considerable tweeking on the part of the programmer
# was needed to achieve this.
# In this version, I am able to show a wide variety of colour schemes.
# Artists code their colours according to three dimensions, (hue, chorma and saturation)
# This might be a more apropriate approach than (red, green, blue).
# CODE
from Tkinter import *
from math import *
from random import*
# critical parameters, adjust to suit
W = 800 # canvas dimensions
H = 500 # golden ratio
nLow = 25 # recursive limiter
nCover = 0.05 # Adjusts probability of a particular area being painted over per sweep
nMSpan = 10.0 # Same as above, These two parameters depend upon the number of recursions
nCSpan = 8.0 # Same for colour range
nSplatterSize = 0.25
# scale factor per recursion. i.e. not scale invariant
aScale = [0.05, .1, .6, 0.9,0.9,0.3,0.1,0.1,0.1,0,0,0,0,0,0,0,0,0,0,0,0]
# colours
aColour = [0.5,0.0,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5]
# The two functions VibrantHousePaint and DrawDrip
# can be modified to suit
def VibrantHousePaint(oM, nR):
# colour scheme
rg = oM.rg
rb = oM.rb
gb = oM.gb
cR = ColStr(int((ZeroToOne(oM.r + rg - rb - oM.rgb , nCSpan * nR)) * nMaxR) + nMinR) # red
cG = ColStr(int((ZeroToOne(oM.g - rg + gb - oM.rgb , nCSpan * nR)) * nMaxG) + nMinG) # green
cB = ColStr(int((ZeroToOne(oM.b + gb - rb - oM.rgb , nCSpan * nR)) * nMaxB) + nMinB) # blue
return '#' + cR + cG + cB
def DrawDrip(nX, nY, oM, nR, bScheme):
colour = apply(bScheme, (oM, nR))
nL = (nLow + 0.0) * nR / 3
nX1 = dist(nX, nL * nSplatterSize)
nY1 = dist(nY, nL * nSplatterSize)
nL2 = dist(nL , nL)
canvas.create_oval( nX1, nY1, nX1 + nL2, nY1 + nL2, fill = colour, width = 0)
canvas.create_rectangle( nX1, nY1 , nX1 + nL2 / 2.0, nY1 + nL2 / 2.0, fill = colour, width = 0)
canvas.update()
class splat:
def __init__(self,z,r,g,b,rg,rb,gb,rgb):
self.z = z
self.r = r
self.g = g
self.b = b
self.rg = rg
self.rb = rb
self.gb = gb
self.rgb = rgb
def ColStr( x):
if x > 255:
x = 0
if x < 0:
x = 255
s = "%x" % x # converts x into a hexidecimal string
if len( s) < 2:
s = '0' + s
return s
def Load(aGrid, nX, nY, n):
# changes value if not set, or else it returns the value
cKey = str( nX) + '_' + str( nY)
if aGrid.has_key(cKey):
return aGrid[cKey]
aGrid[cKey] = n
return n
def ZeroToOne(nM, nSpan):
# maps the Real domain onto [0 , 1]
return atan(nM * nSpan) / pi + 0.5
def mid(n1, n2):
return int((n1 + n2) / 2)
def dist(nP, nScale):
return nP + (random() - 0.5) * nScale
def odist(A, nS1, nS2):
z = 0
r = 0
g = 0
b = 0
h = 0
v = 0
rg = 0
rb = 0
gb = 0
rgb = 0
for i in A:
z += i.z
r += i.r
g += i.g
b += i.b
rg += i.rg
rb += i.rb
gb += i.gb
rgb += i.rgb
l = len(A)
z = dist(z / l, nS1)
r = dist(r / l, nS2)
g = dist(g / l, nS2)
b = dist(b / l, nS2)
rg = dist(rg / l, nS2)
rb = dist(rb / l, nS2)
gb = dist(gb / l, nS2)
rgb = dist(rgb / l, nS2)
return splat(z, r, g, b, rg, rb, gb, rgb)
def FracDown(aGrid, nX1, nY1, nX2, nY2, oTL, oTR, oBL, oBR, nLim, nRecursive, bScheme):
# fractal lanscape grenerator
dx = nX2 - nX1
dy = nY2 - nY1
nS = aScale[nRecursive]
nSC = aColour[nRecursive]
oT = odist([oTL, oTR], nS * nHorizFactor, nSC)
oL = odist([oTL, oBL], nS, nSC)
oR = odist([oTR, oBR], nS, nSC)
oB = odist([oBL, oBR], nS * nHorizFactor, nSC)
oM = odist([oTL, oTR, oBL, oBR], nS * nDiagFactor, nSC)
nXm = mid(nX1, nX2)
nYm = mid(nY1, nY2)
oTL = Load(aGrid, nX1, nY2, oTL)
oTR = Load(aGrid, nX2, nY2, oTR)
oBL = Load(aGrid, nX1, nY1, oBL)
oBR = Load(aGrid, nX1, nY1, oBR)
if dx <= nLow and dy <= nLow:
if ZeroToOne(oM.z, nMSpan * sqrt(nRecursive)) > nLim:
DrawDrip(nXm, nYm, oM, sqrt(nRecursive), bScheme)
return
t1 = (aGrid, nX1, nYm, nXm, nY2, oTL, oT, oL, oM, nLim, nRecursive + 1, bScheme)
t2 = (aGrid, nXm, nYm, nX2, nY2, oT, oTR, oM, oR, nLim, nRecursive + 1, bScheme)
t3 = (aGrid, nX1, nY1, nXm, nYm, oL, oM, oBL, oB, nLim, nRecursive + 1, bScheme)
t4 = (aGrid, nXm, nY1, nX2, nYm, oM, oR, oB, oBR, nLim, nRecursive + 1, bScheme)
aT = [t1,t2,t3,t4]
shuffle(aT)
for i in aT:
apply(FracDown, i)
def ColourRange():
nMin = int(random() * 255)
nMax = int(random() * 255)
if nMin > nMax:
nMin, nMax = nMax, nMin
return nMin, nMax - nMin
def Frac(nLim, bScheme):
aGrid = {}
s1 = splat(0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0)
s2 = splat(0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0)
s3 = splat(0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0)
s4 = splat(0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0)
FracDown(aGrid, 0, 0, W - 1, H - 1, s1, s2, s3, s4,nLim, 1, bScheme)
seed()
canvas = Canvas( width = W, height = H)
canvas.pack(side = TOP)
canvas.create_rectangle( 0, 0, W, H, fill = 'gray', width = 0)
nHorizFactor = (W + 0.0) / (H + 0.0)
nDiagFactor = sqrt(H**2 + W**2) / (H + 0.0)
nMinR, nMaxR = ColourRange()
nMinG, nMaxG = ColourRange()
nMinB, nMaxB = ColourRange()
Frac(nCover, VibrantHousePaint)
print 'done'
|
Some research has been done into the fractal qualities of visual art. This program creates a semi random painting with similar fractal qualities. A large number of colour ranges can be generated for viewing.