Skip to content

Instantly share code, notes, and snippets.

@stevefaeembra
Last active May 27, 2017 22:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevefaeembra/dba1c4fc4ab862abc4ddca3d16871940 to your computer and use it in GitHub Desktop.
Save stevefaeembra/dba1c4fc4ab862abc4ddca3d16871940 to your computer and use it in GitHub Desktop.
chaos game processing.py script
'''
Created on 27 May 2017
Copyright Steven Kay
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
import random
PROPS = [3,5,11,33]
JUMPS = [.5,.7,.2,.3]
XXX = 1024*768
WORLD = [0]*XXX
TOT = 0
def setup():
size(1024,768)
background(0,0,0)
def iterate_points(index,x,y):
use = index % (len(PROPS))
ring = PROPS[use]
jump = JUMPS[use]
die = random.randint(0,ring)
ang = ((2.0*PI)/ring)*die
to_x = 512 + (350*sin(ang))
to_y = 768/2 + (350*cos(ang))
#return (x+to_x)/2, (y+to_y)/2
new_x = (jump*x)+((1.0-jump)*to_x)
new_y = (jump*y)+((1.0-jump)*to_y)
return new_x,new_y
def draw():
global TOT
stroke(255)
x,y = 0,0
for i in range(0,1000):
x, y = iterate_points(frameCount*1000+i,x,y)
x, y =int(x),int(y)
ix =y*1024+x
WORLD[ix] += 10
#ix =y*1024+(512-x) #mirror it
#WORLD[ix] += 10
stroke(WORLD[ix])
if TOT>1000 : #and x>512:
point(x,y)
#point(512-(x-512),y)
TOT += 1
def mousePressed():
saveFrame("/tmp/foo.png");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment