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)
-------------------------------------------------------------------------------------------------------------------------------------

MORE TRIALS TO GET MORE INTERESTING

From the previous trial with circles, I found it was very interesting to create something like a huge system like the underwater world with bubbles or.... maybe a galaxy. Yeah, should do it.

Comment : Tried with the alpha on black colours to blend out the circles, also applied one more ellipse function to draw the ring around a specific center. The outcome is magnificent, looked so much like a galaxy with a big planet at the center.
CODE :
------------------------------------------------------------------------------------------------------------------
 import math

XRES = 600
YRES = 400
centerX = random(XRES/2,XRES)
centerY = random(YRES/2,YRES)

def setup():
    size(XRES, YRES)
    background(255)
    noStroke()
    fill(0,0,0,80)
    smooth()
  
randata = []
for i in range(XRES):
    randata = randata + [random(-100.,100.)]
  
def plot(data, yoff):
    for i in range(1, XRES):
        angle = random(0.,PI*2)
        x = i*1.618*sin(angle)
        y = i*1.618*cos(angle)
        ellipse(centerX+x,centerY+y,data[i]/4,data[i]/4)
      
def filter(data):
    for i in range(1,XRES-1):
        data[i]=0.5*(data[i-1] + data[i+1])
                          
      
def draw():
    filter(randata)
    if (2*frameCount)<(800):
        plot(randata, 2*frameCount)
------------------------------------------------------------------------------------------------------------------

Now I was trying with more frameCount to get more circles, so I cranked it up into 2000 instead of 800. The number would cause a crash though, but would worth a try as well .

Comment : The outcome is great, but I thought it was a bit too off focus there. The black took lots of spaces, made it look like a black hole rather than a galaxy. Also to point out the tiny circles, I tried to tweak a little bit with the second "ellipse" function to get much smaller stars.

CODE :
------------------------------------------------------------------------------------------------------------------
 import math

XRES = 600
YRES = 400
centerX = random(XRES/2,XRES-200)
centerY = random(YRES/2,YRES-200)

def setup():
    size(XRES, YRES)
    background(255)
    noStroke()
    fill(0,0,0,80)
    smooth()
  
randata = []
for i in range(XRES):
    randata = randata + [random(-150.,150.)]
  
def plot(data, yoff):
    for i in range(1, XRES):
        angle = random(0.,PI*2)
        x = i*1.618*sin(angle)
        y = i*1.618*cos(angle)
        ellipse(centerX+x,centerY+y,data[i]/4,data[i]/4)
        ellipse(centerX+2*x,centerY+2*y,data[i]/4,data[i]/4)
      
def filter(data):
    for i in range(1,XRES-1):
        data[i]=0.5*(data[i-1] + data[i+1])
                          
      
def draw():
    filter(randata)
    if (2*frameCount)<(2000):
        plot(randata, 2*frameCount)
------------------------------------------------------------------------------------------------------------------

I thought I should have gone back a bit with the amount of circles as well as the radius.
Comment : Much smaller black center, the rings out side is clearly shaped. The outcome is awesome, I like it.

CODE :
------------------------------------------------------------------------------------------------------------------
 import math

XRES = 600
YRES = 400
centerX = random(XRES/2,XRES-200)
centerY = random(YRES/2,YRES-200)

def setup():
    size(XRES, YRES)
    background(255)
    noStroke()
    fill(0,0,0,80)
    smooth()
  
randata = []
for i in range(XRES):
    randata = randata + [random(-150.,150.)]
  
def plot(data, yoff):
    for i in range(1, XRES):
        angle = random(0.,PI*2)
        x = i*1.618*sin(angle)
        y = i*1.618*cos(angle)
        ellipse(centerX+x,centerY+y,data[i]/5,data[i]/5)
        ellipse(centerX+2*x,centerY+2*y,data[i]/7,data[i]/7)
      
def filter(data):
    for i in range(1,XRES-1):
        data[i]=0.5*(data[i-1] + data[i+1])
                      
      
def draw():
    filter(randata)
    if (4*frameCount)<(2000):
        plot(randata, 4*frameCount)
------------------------------------------------------------------------------------------------------------------ 

I just found the problem I got here was the center of my galaxy just randomly placed to the right of the sketch. So I tried to figure out the way to make this right. Putting a negative number in the random in the sketch would help. Also I tweaked the size of the sketch to get more stars in a sketch, I thought it would be more interesting though.

Comment : The ring is random as well. However the ring is pleasure to me already.

CODE :
------------------------------------------------------------------------------------------------------------------
 import math

XRES = 900
YRES = 700
centerX = random(XRES/2,XRES-200)
centerY = random(YRES/2,YRES-200)

def setup():
    size(XRES, YRES)
    background(255)
    noStroke()
    fill(0,0,0,80)
    smooth()
  
randata = []
for i in range(XRES):
    randata = randata + [random(-150.,150.)]
  
def plot(data, yoff):
    for i in range(1, XRES):
        angle = random(0.,PI*2)
        x = i*1.618*sin(angle)
        y = i*1.618*cos(angle)
        ellipse(centerX+x,centerY+y,data[i]/5,data[i]/5)
        ellipse(centerX+2*x,centerY+2*y,data[i]/7,data[i]/7)
      
def filter(data):
    for i in range(1,XRES-1):
        data[i]=0.5*(data[i-1] + data[i+1])
                          
      
def draw():
    filter(randata)
    if (4*frameCount)<(2500):
        plot(randata, 4*frameCount)
------------------------------------------------------------------------------------------------------------------

TRIALS WITH HARDER FILTER AND RANDOM IN CIRCLE

I stepped one more step to more complicated codes like random in circle and more advanced filtered random.

 Comment : The outcome is great, so random and fulfill. More interesting with these codes.
CODE :
------------------------------------------------------------------------------------------------------------------
import math

XRES = 600
YRES = 400
centerX = XRES/2
centerY = YRES/2
npts = 400

def setup():
    size(XRES, YRES)
    background(255)
    stroke(0)
    smooth()
   
randata = []
for i in range(XRES):
    randata = randata + [random(-100.,100.)]
   
def plot(data, yoff):
    for i in range(1, XRES):
        angle = PI*2
        x = i*1.618*sin(angle)
        y = i*1.618*cos(angle)
        line(x,y,i,yoff+data[i])
       
def filter(data):
    for i in range(1,XRES-1):
        data[i]=0.9*(data[i-1] + data[i+1])
                           
       
def draw():
    filter(randata)
    if (40*frameCount)<(YRES+200):
        plot(randata, 40*frameCount)
------------------------------------------------------------------------------------------------------------------

Then I tried smaller amount on filtering like (0.5-0.6) the multiply the frameCount with 50.
 Comment : The outcome is much crazier. The lines are filling all the blank on the sketch, and making really crazy net.
CODE :
------------------------------------------------------------------------------------------------------------------
 import math

XRES = 600
YRES = 400
centerX = XRES/2
centerY = YRES/2
npts = 400

def setup():
    size(XRES, YRES)
    background(255)
    stroke(0)
    smooth()
  
randata = []
for i in range(XRES):
    randata = randata + [random(-100.,100.)]
  
def plot(data, yoff):
    for i in range(1, XRES):
        angle = random(0.,PI*2)
        x = i*1.618*sin(angle)
        y = i*1.618*cos(angle)
        line(centerX+x,centerY+y,i/250,yoff+data[i])
      
def filter(data):
    for i in range(1,XRES-1):
        data[i]=0.5*(data[i-1] + data[i+1])
                      
      
def draw():
    filter(randata)
    if (50*frameCount)<(YRES+200):
        plot(randata, 50*frameCount)
------------------------------------------------------------------------------------------------------------------

The previous trial was crazy, but that with lines I wonder why not using ellipse shapes?
 Comment : This is an amazing outcome. Circles by circles, somehow I felt like I was 10k feet under the water where lots of bubbles surrounding me.
CODE :
------------------------------------------------------------------------------------------------------------------
 import math

XRES = 600
YRES = 400
centerX = XRES/2
centerY = YRES/2
npts = 400

def setup():
    size(XRES, YRES)
    background(255)
    stroke(0)
    smooth()
  
randata = []
for i in range(XRES):
    randata = randata + [random(-100.,100.)]
  
def plot(data, yoff):
    for i in range(1, XRES):
        angle = random(0.,PI*2)
        x = i*1.618*sin(angle)
        y = i*1.618*cos(angle)
        ellipse(centerX+x,centerY+y,data[i],data[i])
      
def filter(data):
    for i in range(1,XRES-1):
        data[i]=0.5*(data[i-1] + data[i+1])
                      
      
def draw():
    filter(randata)
    if (50*frameCount)<(YRES+200):
        plot(randata, 50*frameCount)
------------------------------------------------------------------------------------------------------------------

MORE UNDERSTANDING ON CODES

I got some ideas how these codes works, so I started to tweak as my pleasant.
At the very first, I tried with filtered random, tried to fix some numbers to get more interesting results.

 Comment :  Crazy waves caused from filter and random. Interesting.
CODE :
------------------------------------------------------------------------------------------------------------------
XRES = 600
YRES = 400

def setup():
    size(XRES, YRES)
    background(255)
    stroke(0)
    smooth()
   
randata = []
for i in range(XRES):
    randata = randata + [random(-50.,150.)]
   
def plot(data, yoff):
    for i in range(1, XRES):
        line(i-1,yoff+data[i-1],i,yoff+data[i])
       
def filter(data):
    for i in range(1,XRES-1):
        data[i]=0.5*(data[i-1] + data[i+1])
       
def draw():
    filter(randata)
    if (4*frameCount)<(YRES+100):
        plot(randata, 4*frameCount)
------------------------------------------------------------------------------------------------------------------

What if I tried with another shapes instead of using lines? Here with the circles
Comment : Looks crazy, I love this.
 CODE :
------------------------------------------------------------------------------------------------------------------
 XRES = 600
YRES = 400

def setup():
    size(XRES, YRES)
    background(255)
    stroke(0)
    smooth()
  
randata = []
for i in range(XRES):
    randata = randata + [random(-200.,200.)]
  
def plot(data, yoff):
    for i in range(1, XRES):
        ellipse(i-1,yoff+data[i-1],i,yoff+data[i])
      
def filter(data):
    for i in range(1,XRES-1):
        data[i]=0.5*(data[i-1] + data[i+1])
                          
      
def draw():
    filter(randata)
    if (40*frameCount)<(YRES+100):
        plot(randata, 40*frameCount)
------------------------------------------------------------------------------------------------------------------
And trial with rectangle

Comment : Hierarchy indeed, but not my types of art. Good trial to understand more on codes though.
CODE :
------------------------------------------------------------------------------------------------------------------
 XRES = 600
YRES = 400

def setup():
    size(XRES, YRES)
    background(255)
    stroke(0)
    smooth()
  
randata = []
for i in range(XRES):
    randata = randata + [random(-200.,200.)]
  
def plot(data, yoff):
    for i in range(1, XRES):
        rect(i-1,yoff+data[i-1],i,yoff+data[i])
      
def filter(data):
    for i in range(1,XRES-1):
        data[i]=0.5*(data[i-1] + data[i+1])
                      
      
def draw():
    filter(randata)
    if (40*frameCount)<(YRES+100):
        plot(randata, 40*frameCount)
------------------------------------------------------------------------------------------------------------------

EXAMPLES BY EXAMPLES

I was bit slow at understanding all of the random codes, so I tried almost the examples from the "random" lecture PDF files.
Example 1 :
Comment : In linear form, the simplest one.
CODE :
-----------------------------------------------------------------------------------------------------------------
XRES = 600
YRES = 600
CX = XRES/2
CY = YRES/2
npts = 5000

import math

def setup():
    size(XRES,YRES)
    background(255)
    stroke(0,10)
    smooth()
    noLoop()
   
def draw():
    for i in range(npts):
        r = CX + random(-200,200)
        line(r,CY-100,r,CY+100)
-----------------------------------------------------------------------------------------------------------------

Example 2 :
Comment : Just applied list in and get a slightly different result from the first one.
CODE :
-----------------------------------------------------------------------------------------------------------------
 XRES = 600
YRES = 600
CX = XRES/2
CY = YRES/2
npts = 5000

buckets = [0.]
buckets = buckets*XRES

def setup():
    size(XRES, YRES)
    background(255)
    stroke(0,10)
    smooth()
    noLoop()
  
def draw():
    for i in range(npts):
        r = CX + random(-200,200)
        line(r,CY-100,r,CY+100)
        ir = int(r)
        buckets[ir] = buckets[ir] + 1
      
    stroke(0)
    for i in range (XRES):
        line(i,CY-200,i,CY-200-buckets[i])
-----------------------------------------------------------------------------------------------------------------

Example 3 :
Comment : Still the same as the second one but with a gradient effect.
CODE :
-----------------------------------------------------------------------------------------------------------------
 XRES = 600
YRES = 600
CX = XRES/2
CY = YRES/2
npts = 5000

buckets = [0.]
buckets = buckets*XRES

def setup():
    size(XRES, YRES)
    background(255)
    stroke(0,10)
    smooth()
    noLoop()
  
def draw():
    for i in range(npts):
        r = CX
        for j in range(12): r = r + random(-50,50)
        line(r,CY-100,r,CY+100)
      
    stroke(0)
    for i in range(XRES):
        line(i, CY-200, i, CY-200-buckets[i])
----------------------------------------------------------------------------------------------------------------- 


THE VERY FIRST TRIAL

I used the example from the lecture to start off my project 2. The "Random bugs", I tried to understand the codes though.
Comment : simple but really effective. Furthermore, the random source comes from the center.
CODE
---------------------------------------------------------------------------------------------------------------
import math
import random

def rnd11():
    return 2.*random.random()-1.
   
SIZE = 600
xpos = SIZE/2.
ypos = SIZE/2.

def setup():
    global xpos,ypos
    size(SIZE, SIZE)
    smooth()
    fill(0,0,0,1)
    background(255)
   
def draw():
    global xpos, ypos
    rect(xpos,ypos,1,1)
    xpos = xpos + rnd11()
    ypos = ypos + rnd11()
---------------------------------------------------------------------------------------------------------------

Wednesday, 28 March 2012

FINAL SUBMISSION - Project 1

Tweak a little bit more, one more circle draw function.... so much more interesting outcome... LOVE IT!

Smoother version (in video format) PLEASE WATCH IN 720

CODE :
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
import math ##import math library

cx = 400.
cy = 400.
rad = 300.

##define 'colors' list
colors = range(5)
colors[0] = color(10,58,74,150)
colors[1] = color(25,106,115,150)
colors[2] = color(50,166,166,150)
colors[3] = color(161, 191, 51,150)
colors[4] = color(200, 217, 74, 150)

def setup():              ##setup the sketch
    size(800, 800)
    stroke(255)         ##white stroke
    smooth()             ##smoother graphic
    frameRate(100)

def draw():                                                ##draw on the sketch
    background(240)                                  ##almost white colour, refresh sketch
    time = millis()/9000.                              ##change through time
    x = (float)(cx+rad*math.cos(time))        ##position X
    y = (float)(cy+rad*math.sin(time))         ##positin Y
                                                                ##color changer | change through positionY
    if (y<=200.):
        rc = colors[0]
    if (y>200.) and (y<=400.):
        rc = colors[2]
    if (y>400.) and (y<=600.):
        rc = colors[3]
    if (y>600.) and (y<=800.):
        rc = colors[4]
    fill(rc)
    for i in range(1, 800):                     ##loop i = 1->799
        angle = y + i/2.01                      ##angle based on position Y
                                                         ##increase i for distance between spirals
        transX = i * 1.618 * math.pow(math.sin(angle),1)      ##Xtranslation
        transY = i * 1.618 * math.pow(math.cos(angle),1)     ##Ytranslation
        width = math.pow(i, -1)                                                      ##can use sin or cos(whatever)
        ellipse(x+transX, y+transY, width+i*0.39, width+i*0.39)    ##width+i*... = amplify number(big or small)
        ellipse(x-transX, y-transY, width+i*0.2, width+i*0.2)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++