Category: Assignment-04-Iteration

Iteration – My Least Interactive Friends

The generative image shown below is a composite of the names of my ten least interactive Facebook friends. By first downloading and parsing the html data from my Facebook wall, I can tell based on date of posts, and amount of interactions, which of my friends are actually interacting with my “online self”. The results are actually quite astonishing. I remember each of these names. Each of these people have some place in my history and the fact that they are here is quite appropriate in that both online and in real lie I barely associated my self with these people but knew them “just enough”. My program uses iteration to both generate the image and constantly run over the html data.

Snap 2014-11-17 at 12.54.31

It’s quite a large file…

from defineFriends import *
from htmlParse import *
wall = parseWall()

list = defineFriends(wall)

tenLeast = []

nFriends = 10

for i in range(nFriends):
    tenLeast.append(list[i][0])
    
def setup():
    size(1000,800)
    textAlign(CENTER)
    
    background(0x3b5998)
    fill(211,211,211)
    noStroke()
    rect(0, height * .15, width, height)
    
    textSize(50)
    a = loadFont("LucidaGrande-48.vlw")
    textFont(a)
    fill(255)
    text("Social Strangers", width / 2, height * .125)
    fill(120)
    for i in range(nFriends):
        xLoc = ((i % 2) * width * .5 ) + width * .25
        yLoc = height * (.14 * (i % nFriends/2)) + height * .27
        textSize(30 + random(10))
        text(tenLeast[i], xLoc, yLoc)
    
    fill(240,240,240)
    rect(0, height * ((.14 * (nFriends*.5 - .3))) + height * .25, width, height)
from htmlParse import *
import string
#Define all friends and find out when you friended them .
    
# I joined Sunday, January 18, 2009

def defineFriends(wall):
    global friendDict, dateSinceFriend
    with open("friends.txt", "r") as inf:
        friends = inf.readlines()
    
    friendDict = {}
    dateSinceFriend = {}
    
    for friend in friends:
        friendDict[friend.strip("\n")] = 0
        dateSinceFriend[friend.strip("\n")] = 0
        
    ageOfFriendship(dateSinceFriend, friendDict,wall)
    return rateWallPosts(friendDict, dateSinceFriend, wall)
    
    
#Calculates rough distance between two dates as tuples. 
def distanceBetweenDates(start, end):
    return end[0] - start[0] + \
    end[1] * 30 - start[1] * 30 + \
    end[2] * 365 - start[2] * 365 
    
monthToIndex = {
                "January" : 1,
                "February" : 2,
                "March" : 3,
                "April" : 4,
                "May" : 5, 
                "June" : 6, 
                "July" : 7,
                "August" : 8, 
                "September" : 9,
                "October" : 10,
                "November" : 11,
                "December" : 12
                }

dayToIndex = {
              "Sunday" : 1,
              "Monday" : 2,
              "Tuesday" : 3,
              "Wednesday" : 4,
              "Thursday" : 5, 
              "Friday" : 6,
              "Saturday" : 7
              }

abbrToMonth = {
               "Jan" : "January",
               "Feb" : "February",
               "Mar" : "March",
               "Apr" : "April",
               "May" : "May",
               "Jun" : "June",
               "Jul" : "July",
               "Aug" : "August",
               "Sep" : "September", 
               "Oct" : "October", 
               "Nov" : "November",
               "Dec" : "December"
               }

abbrToMonthLen = {
               "Jan" : 7,
               "Feb" : 8,
               "Mar" : 5,
               "Apr" : 5,
               "May" : 3,
               "Jun" : 4,
               "Jul" : 4,
               "Aug" : 6,
               "Sep" : 9, 
               "Oct" : 7, 
               "Nov" : 8,
               "Dec" : 8
               }

abbrToDay = {
             "Mon" : "Monday",
             "Tue" : "Tuesday",
             "Wed" : "Wednesday",
             "Thu" : "Thurday",
             "Fri" : "Friday",
             "Sat" : "Saturday",
             "Sun" : "Sunday"
             }

abbrToDayLen = {
             "Mon" : 7,
             "Tue" : 8,
             "Wed" : 10,
             "Thu" : 9,
             "Fri" : 7,
             "Sat" : 9,
             "Sun" : 7
             }

days = dayToIndex.keys()
months = monthToIndex.keys()

def dayOfWeek():
    # 5 is number of days into 2014 for sunday
    daystotal = (365*(year() - 1)) + (int(floor((year()-1)/4))) -(int(floor((year() - 1)/100))) + (int(floor((year() - 1)/400))) + day()
    return daystotal % 7

def metaLineFilter(wall):
    metaList = []
    for line in wall:
        temp = ""
        for c in line:
            temp = temp + c
            if temp == '<div class="meta">':
                metaList.append(line)
                
    return metaList 

def gaugeResponses(friendDict, dateSinceFriend, filtered):
    for item in filtered:
        time = findTime(item[0])
        
        name = findNameExtended(item[1])
        
        if not(name == "%s" % myName):
            try:
                dist = distanceBetweenDates((myDay, myMonth, myYear), (time[0],time[1],time[2]))
                coeff = map(dist, 0, today, 0, 4)
                friendDict[name] = friendDict[name] + (1 * coeff)
            except:
                friendDict[name] = 1 * coeff
                
def findNameExtended(item):
    item = item.strip("</div>")
    lower = string.lowercase
    check = False
    name = ""
    for c in item:
        if c.isspace():
            name += c
            check = True
        elif check and c.islower() and not(c == "d"):
            return name.strip()
        else:
            check = False
            name += c
            
         

def findTimes(dictionary, friendDict, friendList):
    for item in friendList:
        timeFriended = findTime(item[0])
        name = findName(item[1].strip("</div>").strip("</p"))
        
        timeTillFriend = (timeFriended[0] - myDay) + \
                    ((timeFriended[1] * 30) - (myMonth * 30)) + \
                    ((timeFriended[2] * 365) - (myYear * 365))
              
        friendedFor = map(timeTillFriend, 0, today, today, 0)
        
        dictionary[name] = int(friendedFor)
        friendDict[name] = 0
        
def findName(item):
    # Ignore "Luca Damasco and"
    start = 17
    
    #Ignore " are now friends."
    end = len(item) - 17
    
    return item[start:end]

def findTime(item):
            
        day = item[0:3]
        temp = ""
        for c in day:
            temp += c
            
        day = temp
        
        dayLen = abbrToDayLen[day]
            
#         dayI = dayToIndex[abbrToDay[day]]
        
        month = item[dayLen + 1 : dayLen+4]
        
        monI = monthToIndex[abbrToMonth[month]]
        
        monLen = abbrToMonthLen[month]
        
        index = dayLen + monLen
        
        dayI = item[index + 2: index + 4]
        
        
        if dayI[1] == ",":
            dayI = dayI[0]
            
        dayLen = 2
        
        index += 2 + 3
        
        year = item[index : index + 5]   
        
        return (int(dayI), int(monI), int(year)) 
        
def ageOfFriendship(dictionary, friendDict, wall):
    metaList = metaLineFilter(wall) #Only shows meta data on wall. 
    
    filtered = filterLines(metaList,True) #Filters to find only friendings
    
    findTimes(dictionary, friendDict, filtered) #Finds out how long you've been a friend and adds it to the dictionary. 
   
def rateWallPosts(friendDict, dateSinceFriend, wall):
    metaList = metaLineFilter(wall)
    
    filtered = filterLines(metaList, False)
    
    gaugeResponses(friendDict, dateSinceFriend, filtered)
    
    friendListTup = []
    friendList = friendDict.keys()
    
    for name in friendList:
        friendListTup.append((name, friendDict[name]))
        
    finalList = []
    for friend in friendListTup:
        if not(friend[1] == 0):
            finalList.append(friend)

    finalList.sort(key = lambda friend : friend[1])
    
    return finalList
    
def filterLines(lineList, check):
    newList = []
        
    for line in lineList:
        divFree = line.strip('<div class="meta">')
        a = divFree.split(" EST")
        b = divFree.split(" EDT")
        if len(a) >= 2:
            divFree = a
        else: 
            divFree = b
        
        if check:
            if divFree[1][0:22] == "</div>%s and" % myName:
                newList.append(divFree)
        else:
            if not(divFree[1][0:22] == "</div>%s and" % myName) :
                newList.append(divFree)
            
    return newList

def initDefine():
   global today, myName, myMonth, myYear, myDay
   
   myName = "Luca Damasco"
   myMonth = 1
   myDay = 18
   myYear = 2009
   
   today = distanceBetweenDates((myDay, myMonth, myYear), 
                             (day(), month(), year()))

   
initDefine()
def parseWall():
    newList = []
    complete = []
    
    with open("wall.htm", "r") as inf:
        wall = inf.readlines()
    
    for item in wall:
        wallEdit = item.split('<p>')
        newList.append(wallEdit)

    for item in newList:
        for line in item:
            complete.append(line)
        
    return complete

Wallpaper

Screen Shot 2014-10-03 at 3.18.57 PM

Screen Shot 2014-10-03 at 3.18.53 PM

Screen Shot 2014-10-03 at 3.18.19 PM

  
  size(600, 600); 
  background(255); 
  noStroke();
  
  float Xspacing =random (20, 100);
  
  for (int y=1; y< =500; y=y+100) {
    for (int n=1; n<=10; n=n+1) { 
      float flowerX = n*Xspacing;
  
      float petalSize = random(4, 16); 
      float middleSize= random (4, 10);
  
      float R= (255);
      float G= random (114, 206);
      float B= random (114, 211);
      fill(R, G, B);
      ellipse (flowerX, y, middleSize, middleSize);

        float R2= (156);
      float  G2= random (248, 255);
      float B2= random (156, 255);
      fill (R2, G2, B2);
      ellipse (flowerX, y-17, petalSize, petalSize); //petal 1
      ellipse (flowerX+16, y-5, petalSize, petalSize);//petal 2
      ellipse (flowerX+11, y+12, petalSize, petalSize);//petal 3
      ellipse (flowerX-11, y+12, petalSize, petalSize);//petal 4
      ellipse (flowerX-16, y-5, petalSize, petalSize);//petal 5
    }
  }

Iterative

Iterative

I attempted to play around with some arbitrary math, rectangles and color and see what designs I could come up with. I started with the window-like rectangles and set their width and position according to iteration, but then I wondered, “Hey, why does it have to stop there?” So I also added iterative elements to the color as well as the alpha of the windows, and added more lines/rectangles to boot. This yellowy-blue-red rectangle structure was what I ended up with. Admittedly, I could have spent some more time fleshing out more details to make the overall piece better, but I’m happy about the result. The code is small and nothing too advanced is at play here.

EverLight

Don’t ask me about the name, but this iteration happened completely by accident. I was messing around with creating a grid of ellipses for my other idea when I decided to use lines instead. However, all i did was change “ellipse” to “line” and it created this amazingly cool, modern image.

Screen Shot 2014-09-24 at 6.06.01 PM

 

void setup(){
  size(1280,720);
  background(0);

}
void draw(){
  int orig = 0;
  int x = int(random(6,20));

  strokeWeight(1);
   for (int i=1; i

Duress

 

 

Duress

a .gif of the wallpaper running

This is an experiment in a  dynamic desktop wallpaper. It is a simple white plain containing randomly-generated, vibrating red dots. these are generated recursively, and their random movement is recursive down the trees The program could be scaled to cover an entire wall. I find the quiet stress of the piece kind of amusing given the conventional purpose of a wallpaper

//recursive class that are represented by cicles in-render
class Node {
  color c;
  float xpos;
  float ypos;
  int radius;
  boolean hasChildren;
  Node child1;
  Node child2;
  Node child3;
  
  Node(color tempC, float tempXpos, float tempYpos, int tempRadius) {
    c = tempC;
    xpos = tempXpos;
    ypos = tempYpos;
    radius = tempRadius;
    float inc = 40.0;
    float r = red(c);
    float g = green(c)-inc;
    float b = blue(c)-inc;
    // base case: when the colour is close to true red, no recusion
    // is called
    if( b >= 10){
      // creates connected nodes based off of current node
      hasChildren = true;
      child1 = new Node(color(r,g,b),(xpos+random(0,width/5)),
                      (ypos+random(-(width/5),width/5)),radius);
      child2 = new Node(color(r,g,b),(xpos+random(0,width/5)),
                      (ypos+random(-(width/5),width/5)),radius);
      child3 = new Node(color(r,g,b),(xpos+random(0,width/5)),
                      (ypos+random(-(width/5),width/5)),radius); 
    } else {
      hasChildren = false; 
    }
  }
  
  //pre-updates a node with the movement of a parent node, and
  //feeds that information to its children
  void predate(float x, float y){
    xpos += x;
    ypos += y;
    if(hasChildren) {
      child1.predate(x,y);
      child2.predate(x,y);
      child3.predate(x,y);
    }
  }  
  
  //couses random movement in the node, and feeds that movement to
  //its children, as well as causing them to update
  void update() {
    float x = random(-2,2);
    float y = random(-5,5);
    xpos += x;
    ypos += y;
    if(hasChildren) {
      child1.predate(x,y);
      child2.predate(x,y);
      child3.predate(x,y);
      child1.update();
      child2.update();
      child3.update();
    }
  }
  
  //draws the red circles and connecting lines
  void display() {
    if(hasChildren) {
      stroke(1);
      line(xpos,ypos,child1.xpos,child1.ypos);
      line(xpos,ypos,child2.xpos,child2.ypos);
      line(xpos,ypos,child3.xpos,child3.ypos);
      child1.display();
      child2.display();
      child3.display();
    }
    noStroke();
    fill(c);
    ellipse(xpos,ypos,radius,radius);
  }
}



// class for the root node - similar to Nodes, but static - 
// not nescesarry, could be streamlined into the Node class
class Root {
  color c;
  float xpos;
  float ypos;
  int radius;
  Node child1;
  Node child2;
  Node child3;
  
  Root(color tempC, float tempXpos, float tempYpos, int tempRadius) {
    c = tempC;
    xpos = tempXpos;
    ypos = tempYpos;
    radius = tempRadius;
    float inc = 40.0;
    float r = red(c);
    float g = green(c)-inc;
    float b = blue(c)-inc;
    child1 = new Node(color(r,g,b),(xpos+random(0,width/5)),
                      (ypos+random(-(width/5),width/5)),radius);
    child2 = new Node(color(r,g,b),(xpos+random(0,width/5)),
                      (ypos+random(-(width/5),width/5)),radius);
    child3 = new Node(color(r,g,b),(xpos+random(0,width/5)),
                      (ypos+random(-(width/5),width/5)),radius);                     
    
  }
  
  void update() {
    child1.update();
    child2.update();
    child3.update();
  }
  
  void display() {
    line(xpos,ypos,child1.xpos,child1.ypos);
    line(xpos,ypos,child2.xpos,child2.ypos);
    line(xpos,ypos,child3.xpos,child3.ypos);
    child1.display();
    child2.display();
    child3.display();
    noStroke();
    fill(c);
    ellipse(xpos,ypos,radius,radius);
    stroke(1);
  }
}

Root progen;

//
void setup() {
  size(1080,720);
  progen = new Root(color(240,240,240), float(width/20), float(height/2),35);
}



void draw() {
  background(255);
  progen.update();
  progen.display();
}

 

Iterative wallpaper

Screen Shot 2014-09-17 at 8.55.28 PM

 

This is the wallpaper I made for the iterative assignment. Some aspects of this pattern I had fun playing with involved opacities of the shapes, as well as the layering that occurs as the program runs. Unfortunately, I was unable to recover the exact code after my computer died, but I will post the code I used to start, below.

 

// Will Taylor
// Iteration wallpaper

int width = 800; int height = 800;
int fr = 24;

void setup(){
size(width, height);
background(255);

}

void draw(){
background(#FF4D6E);
strokeWeight(5);
stroke(#4DFF6F);

int diam = width/10;
float rad = diam*.75;
//green lines
for (int i = 0; i <=20; i++){
line(0, i*diam/2, width, i*diam);
}
stroke(0);
for (int r = 0; r <= 13; r++){
for (int c = 0; c <= 13; c++){
smooth();
strokeWeight(5);
fill(#FFF300,25); // yellow
ellipse(r*rad, c*rad, diam, diam);
strokeWeight(2);
fill(#008AFF, random(100)); // blue
ellipse(r*rad, c*rad, diam/4, diam/4);
}

}

}

 

 

Wallpaper

Gif of wallpaper Gif of wallpaper

 

wallpaper

Wallpaper

When making this piece I didn’t really have a specific visualization of what I wanted the piece to look like as much as I did a color scheme I wanted to work around. I wanted to create something that was dynamic that worked with the scheme of red, black, yellow and white. What I did first was create an ellipse which I repeated across a boundary of fifty, by fifty using a loop. I did the same thing for the smaller ellipse located inside it. Another thing I added was a series of lines, also created by a for loop. These lines ran from opposite corners of the image, one from a negative section beyond the canvas and another from the width of it. I also made the colors of another series of lines I created-along with the inside circles—running through the bottom left and top right corner of the canvas to change from a random number from 1 to 121 and changed the blue and green value of the stroke, creating different shades of yellow.

 EDITED: I added a moving gif of the wallpaper and also changed the parameters of the circles and lines being drawn so that they aren’t confined to the space which can be seen in the new version of the code below.

import processing.video.*;

void setup(){
 size(500,500);
 background(255,2,14);
frameRate(5);

}

void draw(){

 float cu= random (1,121);

for (int x = 0; x< =width; x+=40){//creating a shape from width minus wall (50) and continues until it reacheds wall(50) 
//meaning 800-50=750 so from 750 up over and over again until it reaches 50
  for(int y = 0; y<height; y+=40){//doing the same thing
  noStroke();
   
    
   fill(0,0,0);
   ellipse(x-1, y-1, 50,50);
   fill(255,cu,0);
   ellipse(x+1,y+1, 15,15);
   
   stroke(5);
   
   line(x,y,-x,-y);//all going towards a negative number somewhere
   stroke(255,255,255);
   line(2*x,2*y,-x,-y);
   stroke(255,cu,cu);
   line(4*y, 4*x,-x,-y);//line four times as much as x and y going to a negative number
   stroke(0,0,0);
   line(width,height,x,y);//lines coming from the end of the screen to x and y
   
   stroke(255,cu*2,cu);
   line(4*width, 4*height,-x,-y);
   
 

    }
  }
}

&nbsp;

Wallpaper

sketch23

With this, I wanted to make something that was visually pleasing with a small amount of coding, by disguising something that is really simple as something more complicated. At first glance this looks like it might be in 3d, or have complex shapes in it, but its just 2d circles stacked up on each other. I want to exercise the ability to code concisely, keeping everything simple and painfully clear at the base and then build up on that. So this defiantly would be a base for a bigger project.

Iteration

 

Iteration

I first wanted to create an mirror ball like background iteration but I couldn’t get the hang of it. I tried with rectangles but then it didn’t look as how I wanted it to look like. So instead I made a triangles that will go over and over again but since it looked too simple I added random colours to it mainly something of pink. It did turn out how I wanted it to be and I tried to do it with other shapes too but then the math was too complicated for me to figure out how to put it together into a shape so I just did the one with the triangle.

 

void setup(){
  size(800, 800);
  frameRate(3);
  noStroke();
}

void randomFill(){
  fill(color(random(165, 230), random(70, 185), random(160, 220)));
}

void drawTriangle( int dimension, int x1CoOrd, int y1CoOrd, 
                    int x2CoOrd, int y2CoOrd, int x3CoOrd, 
                    int y3CoOrd){
  int x1 = dimension * x1CoOrd;
  int y1 = dimension * y1CoOrd;
  int x2 = dimension * x2CoOrd;
  int y2 = dimension * y2CoOrd;
  int x3 = dimension * x3CoOrd;
  int y3 = dimension * y3CoOrd;
  randomFill();
  triangle(x1, y1, x2, y2, x3, y3);
}


void pattern(int x, int y, int dimension){
  pushMatrix();
  translate(x, y);
  drawTriangle(dimension, 0, 0, 0, 1, 1, 0);
  drawTriangle(dimension, 0, 1, 1, 0, 1, 1);
  drawTriangle(dimension, 1, 0, 1, 1, 2, 1);
  drawTriangle(dimension, 1, 0, 2, 1, 2, 0);
  drawTriangle(dimension, 0, 1, 0, 2, 1, 2);
  drawTriangle(dimension, 0, 1, 1, 1, 1, 2);
  drawTriangle(dimension, 1, 1, 1, 2, 2, 1);
  drawTriangle(dimension, 1, 2, 2, 1, 2, 2);
  popMatrix();
}

void draw(){
  background(100);
  fill( 0, 121, 184 );
  int dimension = 100;
  for (int i = 0; i < 800; i = i+200) {
    pattern(0, i, dimension);
    pattern(200, i, dimension);
    pattern(400, i, dimension);
    pattern(600, i, dimension);
  }
}