Wednesday 16 May 2012

Submission 242 - Project 2

Here is my final submission for Project 2

CODE
-------------------------------------------------------------------------------------------------------------------------------------

import math

XRES = 900 ##WIDTH is 900
YRES = 700 ##HEIGHT is 700
centerX = random(XRES/2-200,XRES-200) ##Center of the planet (random between the middle of the sketch to 200 units around)
centerY = random(YRES/2-200,YRES-200)

def setup(): ##Setup sketch
size(XRES, YRES)
background(0) ##Black BG
noStroke()
fill(255,255,255,80) ##White colour, 80 alpha
smooth()

randata = [] ##list randata
for i in range(XRES): ##size of the circle random
randata = randata + [random(-150.,150.)]

def plot(data, yoff): ##Star Contributor : random in a circle
for i in range(1, XRES):
angle = random(0.,PI*2)
x = i*1.618*sin(angle) ##golden ratio applied
y = i*1.618*cos(angle)
ellipse(centerX+x,centerY+y,data[i]/5,data[i]/5) ##main circles make the galaxy
ellipse(centerX+2*x,centerY+2*y,data[i]/7,data[i]/7) ##smaller circles make it more interesting

def filter(data):
for i in range(1,XRES-1):
data[i]=0.5*(data[i-1] + data[i+1]) ##Median filter for data

def draw():
filter(randata)
if (4*frameCount)<(2500): ##the amount of circles and speed of the sketch
plot(randata, 4*frameCount)
-------------------------------------------------------------------------------------------------------------------------------------

No comments:

Post a Comment