Category: Assignment-05-Ten-Lines

A Good ‘Ol Fashioned Rumble! (Ten Liner)

Uh oh, looks like there’s a rumble! Use your cursor to either flee the scene, or stay and fight. When the circles get closer together, the screen flashes to give the effect of punches being thrown. The biggest challenge I faced for this assignment was getting each circle to move at a different rate. The method I ended up using allows the speed of a circle to be faster if it was drawn towards the end of the for loop.

 

##Will Taylor
## A Good 'Ol Fashioned Rumble (Ten Liner)
width, height = 400,400
radius = 10
circleXY = [[int(random(width)), int(random(height))],
[int(random(width)), int(random(height))],
[int(random(width)), int(random(height))],
[int(random(width)), int(random(height))],
[int(random(width)), int(random(height))],
[int(random(width)), int(random(height))],
[int(random(width)), int(random(height))],
[int(random(width)), int(random(height))],
[int(random(width)), int(random(height))],
[int(random(width)), int(random(height))]]
def setup():
size(width,height)
frameRate(32)

def draw():
background(255)
smooth()
strokeWeight(2)
stroke(0)


def checkMatch():
for i in xrange(len(circleXY)):
x = circleXY[i][0]
y = circleXY[i][1]
if (x == mouseX and y == mouseY):
background(0)
return True


def drawCircles():
rad = radius
for i in xrange(len(circleXY)):
if (i > len(circleXY)/2):
stroke(0)
fill(255)
else:
stroke(150)
fill(0)
ellipse(circleXY[i][0], circleXY[i][1], rad, rad);


def updateCircleX():
for i in xrange(len(circleXY)):
if (circleXY[i][0] > mouseX):
circleXY[i][0] -= int(2*(i+1)%4 + (i+1))
elif (circleXY[i][0] < mouseX):
circleXY[i][0] += int((i+2)%4 + (i+1))

def updateCircleY():
vChase = 1
for i in xrange(len(circleXY)):
if (circleXY[i][1] > mouseY):
circleXY[i][1] -= int(2*(i+1) - i)
elif (circleXY[i][1] < mouseY):
circleXY[i][1] += int(2*(i+1) - i)

def updateCircles():
updateCircleX()
updateCircleY()

drawCircles()

updateCircles()
checkMatch()

 

Dandilion (10 lines)

mbk-10lines

For this project I wanted to make a flower blow in the wind. I wanted the mouse to blow the seeds off of the flower, and then have them wrap around the border and land back onto the flower. This turned out to be a bit more challenging than I had originally thought.

10-lines-sketch

sinWave 10 lines

 

 

clair chin

10 lines moving along sin wave with amplitude according to mouse X sinwave

<pre lang="java" line="1">


int startingX;
int increment;
float x;
float pi;


void setup()
{
 size(800,300);
 increment=width/11;
 x=0;
 pi=3.141592654;
}


void draw()
{
 background(0);
 println(x<2*pi);
 if (x<2*pi)
 {
 x=x+(2*(pi/100));
 } 
 else
 {
 x=0;
 }
 float waveLevel=map(mouseX,0,width,0,70);
 for (int i=1;i<11;i++)
 {
 stroke(255);
 float shift = sin(x+i*2*pi/10)*waveLevel;
 line((increment*i),140+shift,(increment*i),155+shift);
 }
 
}

</pre>

 

 

Ten Liners

Soon, he multiplied. Gathering new companions upon his plane, our one was now many. Together they inhabited the two-dimensional world they had been handed, but now they gained a true sense of ownership. One is timid, many are strong. Together they observe any and all intruders on their plain. They seek the knowledge their intruders hold.

import java.awt.Robot;
import java.awt.AWTException;
import processing.serial.*;
import java.awt.MouseInfo;
import java.awt.Point;

Robot rob;

boolean allAlerted;
ArrayList<LineMan> lineList;
ArrayList<Position> atkPosList;
ArrayList<Position> restPosList;
ArrayList<Position> mouseHits;
int lastUpdate;
int timeWait;
boolean oneAlerted;

void setup() {
  size(800,600);
  cursor(HAND);
  
  //Set up Bot to move mouse
  try {
  rob = new Robot();
  }
  catch (AWTException e) {
    e.printStackTrace();
  }
  mouseHits = new ArrayList<Position>();
  updateAtkPositions();
  createRestPositions();
  createLines();
  allAlerted = false;
  lastUpdate = 0;
  oneAlerted = false;
  
}

void draw() {
  background(255);
  updatePositions();
  mouseChecks();
  updateLines();
  drawLines();
}

void keyPressed() {
  //Get x,y of frame to offset changes. 
  int x = frame.getLocation().x;
  int y = frame.getLocation().y;
  rob.mouseMove(x +  width/2, y + height/2);
}

void mouseChecks() {
  if (mouseInWindow() && !oneAlerted) {
    oneAlerted = true;
    alertClosest();
  } else if (!mouseInWindow()) {
    oneAlerted = false;
    ignoreMouse();
  }
  checkAlerted();
}

boolean mouseInWindow() {
  Point mousePos = (MouseInfo.getPointerInfo().getLocation());
  int mWinX = mousePos.x;
  int mWinY = mousePos.y;
  int fX = frame.getLocation().x;
  int fY = frame.getLocation().y;
  if ((mWinX > fX && mWinX < fX + width) &&
     (mWinY > fY && mWinY < fY + height)) {
   return true;
  } else {
   return false;
  } 
}

void alertClosest() {
  int closest = 0;
  int closestD = width;
  for (int i = 0; i < 10; i++) {
    if (dist(mouseX, mouseY, lineList.get(i).x, lineList.get(i).y) < closestD) {
      closest = i;
    }
  }
  lineList.get(closest).alerted = true;
}

void ignoreMouse() {
  for (int i = 0; i < 10; i++) {
    lineList.get(i).alerted = false;
  }
}

void updatePositions() {
  updateAtkPositions();
  if ((millis() - lastUpdate)/1000.0 >= 1.5) {
    lastUpdate = millis();
    updateRestPositions();
  }
}

void checkAlerted() {
  boolean check = true;
  for (int i = 0; i < 10; i++) {
    if (lineList.get(i).alerted == false) {
      check = false;
      allAlerted = false;
      break;
    }
  }
  if ((check)) {
      allAlerted = true;
  }
}

      
void createLines() {
  lineList = new ArrayList<LineMan>();
  for (int i = 0; i < 10; i++) {
    float x = random(width*.1, width*.9);
    float y = random(height * .1, height * .9);
    lineList.add(new LineMan(x,y,i));
  }
}

void updateAtkPositions() { 
  atkPosList = new ArrayList<Position>();
  float r = width * .07; // radius around mouse
  for (int i = 0; i < 10; i++) {
    float theta = i * (6.28 / 10 );
    atkPosList.add(new Position(mouseX + (r * cos(theta)), mouseY + (r * sin(theta)) ) );
// This Code shows the attack positions
//    strokeWeight(5);
//    point(mouseX + r * cos(theta),mouseY +  r * sin(theta));
  }
}

void createRestPositions() {
  restPosList = new ArrayList<Position>();
  for (int i = 0; i < 10; i++) {
    float x = random(width * .15, width * .85);
    float y = random(height * .15, height * .85);
    restPosList.add(new Position(x,y));
  }
  
}

void updateRestPositions() {
  for (int i = 0; i < 10; i++) {
    if (random(10) < 2) {
      restPosList.get(i).x = random(width*.15, width*.85);
      restPosList.get(i).y = random(height*.15,width*.85);
    }
  }
}

void updateLines() {
  int count = 0;
  for (int i = 0; i < 10; i++) { 
    lineList.get(i).update();
    if (lineList.get(i).alerted){
      count += 1;
    }
  }
}

void drawLines() {
  for (int i = 0; i < 10; i++) {
    lineList.get(i).drawMe();
  }
}
    

class LineMan {
  float x;
  float y;
  float lineLength;
  float thickness;
  float headX;
  float headY;
  float bottomX;
  float bottomY;
  float distance;
  int index;
  float speed;
  Position atkPos;
  Position restPos;
  boolean attacking;
  boolean alerted;
  boolean inPlace;
  float yChange;
  float sinCurve;
  float sinCurveChange;
  float cosCurve;
  float cosCurveChange;
  float xChange;
  
  LineMan(float x,float y,int index) {
    this.x = x;
    this.y = y;
    this.lineLength = (int)random(height * .05, height * .1);
    this.thickness = (int)random(2, 5);
    this.speed = max(width/4, height/4)/(this.lineLength * this.thickness); //Fatter lines move slower. 
    this.headX = x; 
    this.headY = y - lineLength/2;
    this.bottomX = x;
    this.bottomY = y + lineLength/2;
    this.alerted = false;
    this.update();
    this.sinCurveChange = .1;
    this.cosCurveChange = 0;
    this.index = index;
    this.sinCurve = random(0, 6.28);
    this.cosCurve = random(0, 6.28);
  }
  
  void drawMe() {
    strokeWeight(this.thickness);
    line(this.bottomX, this.bottomY, this.headX, this.headY);
  }
  
  void update() {
    if ((allAlerted)) {
      this.attacking = true;
    } else {
      this.attacking = false;
    } 
    
    this.sinCurve += this.sinCurveChange;
    this.sinCurve = this.sinCurve % 6.28;
    this.cosCurve += this.cosCurveChange;
    this.cosCurve = this.cosCurve % 6.28;
    float coEff;
    float xCoEff;
    
    if ((this.alerted) && (!this.attacking)) {
      coEff = .2; //Slow
      xCoEff = 2;
      this.cosCurveChange = .3; //Side to Side Motion
    } else if ((this.attacking) && (!this.inPlace)){
      coEff = 10; //Fast
      xCoEff = 2;
      this.cosCurveChange = .3; //Side to Side Motion;
    } else if ((this.attacking) && (this.inPlace)) {
      coEff = 2; //Sort of Slow
      xCoEff = 2;
      this.cosCurveChange = .1; //Side to Side Motion;
    } else {
      coEff = 5; //No one on screen
      xCoEff = 0;
     this.cosCurveChange = 0; //Side to Side Motion
    }
    
    if (this.alerted) {
      this.alertBuddy();
    }
    
    // CoEff... offset by height of window... sin wave
    this.yChange = coEff * (height / (float)400) * sin(this.sinCurve); 
    this.xChange = xCoEff * (width / (float)400) * (cos(this.cosCurve));
    this.definePos();
    this.move();
  }
  
  void definePos() {
    this.atkPos = atkPosList.get(this.index);
    this.restPos = restPosList.get(this.index); 
    if (this.attacking) {
      if ((abs(this.x - this.atkPos.x) <= width*.02) &&
          (abs(this.y - this.atkPos.y) <= height*.02)) {
        this.inPlace = true;
      } else {
        this.inPlace = false;
      }
    } else {
      if ((abs(this.x - this.restPos.x) <= width * .02) &&
          (abs(this.y - this.restPos.y) <= height * .02)){
        this.inPlace = true;
          } else {
        this.inPlace = false;
          }
    }
  }
  
  void move() {
    if ((this.attacking) && (!this.inPlace)){
      float distance = dist(this.x, this.y, this.atkPos.x, this.atkPos.y);
      this.x += this.speed*(-((this.x - this.atkPos.x)/distance));
      this.y += this.speed*(-((this.y - this.atkPos.y)/distance));
    } else if ((!this.attacking) && (!this.inPlace)){
      float distance = dist(this.x, this.y, this.restPos.x, this.restPos.y);
      this.x += this.speed*(-((this.x - this.restPos.x)/distance));
      this.y += this.speed*(-((this.y - this.restPos.y)/distance));
    }
    this.headX = this.x + this.xChange; 
    this.headY = (this.y - lineLength/2) + this.yChange;
    this.bottomX = this.x + this.xChange;
    this.bottomY = this.y + lineLength/2 + this.yChange;
  }
  
  void alertBuddy() {
    if (random(10) < .5) {
      lineList.get((int)random(10)).alerted = true;
    }
  }
    
}

class Position {
  float x;
  float y;
  
  Position(float x, float y) {
    this.x = x;
    this.y = y;
  }
}

TEN LINES

Move your mouse over the screen. Ten lines will reach out and grab your mouse from an invisible grid of circles. I drew this out in peak condition on paper beforehand, as seen below:

my plan my plan

While there were some speed bumps navigating the javascript arrays, I was able to complete it exactly as I had initially envisioned:

tenlines

10 Lines: The Menhirs

Screen Shot 2014-10-01 at 17.22.37

Menhirs, also called standing stones, are a type of monolith found in Northern Europe. This is a minimal experiment in landscape generation using these objects as inspiration. They rotate with the mouse, and stones are added and remove by left and right clicking respectively.

code:

//The Menhirs. Ignore the Aztec look.

ArrayList<Menhir> menhirs;

//seperately handles a menhir drawing
void drawMenhir(int x,int y,int dw,int dh){
  noStroke();
  int ang = dw/4;
  fill(255);
  beginShape();
  vertex(x+dw, y+dh-ang);
  vertex(x+dw/2, y+dh);
  vertex(x, y+dh-ang);
  vertex(x, y+ang);
  vertex(x+dw/2,y);
  vertex(x+dw,y+ang);
  endShape();
  stroke(0);
  strokeWeight(3);
  beginShape();
  vertex(x+dw,y+ang + 20);
  vertex(x+dw, y+dh-ang);
  vertex(x+dw/2, y+dh);
  vertex(x+dw/2,y+2*ang);
  vertex(x+dw,y+ang);
  vertex(x+dw/2,y);
  vertex(x, y+ang);
  vertex(x, y+dh-ang);
  endShape();
  noFill();

}

//seperately draws the shadow of a menhir
void drawShadow(int x,int y,int dw,int dh){
  int ang = dw/4;
  stroke(0);
  noFill();
  beginShape();
  vertex(x, y+dh-ang);
  vertex(x-dh,y+dh-ang+(dh/2));  //here be logial derails
  vertex(x-dh+dw/10,y+dh-ang+(dh/2)+ang/5);
  vertex(x + dw/10, y+dh-ang + ang/5);
  vertex(x+ (2*dw/10), y+dh-ang +(2*ang/5));
  vertex(x-dh+ (2*dw/10),y+dh-ang+(dh/2)+(2*ang/5));
  vertex(x-dh+ (3*dw/10),y+dh-ang+(dh/2)+(3*ang/5));  
  vertex(x+ (3*dw/10), y+dh-ang +(3*ang/5));
  vertex(x+ (4*dw/10), y+dh-ang +(4*ang/5));
  vertex(x-dh+ (4*dw/10),y+dh-ang+(dh/2)+(4*ang/5));
  vertex(x-dh+ (5*dw/10),y+dh-ang+(dh/2)+(5*ang/5)); 
  vertex(x+ (dw/2) - ang , y+dh-ang + 3*ang/2);
  endShape();
  
}

// class that handles the standing stones
class Menhir{
  int x;
  int y;
  int trueY;
  int h;
  int w;
  float radius;
  
  Menhir(){
    x = 0;
    y = 0;
    trueY = 0;
    h = int(random(90,height/4));
    w = int(random(30,width/8));
    radius = map (noise(millis()), 0.0,1.0 , 0.0,0.6);
  }
  
  //given an angle relative to the baseline (y = width/2), 
  //places the menhir on that angle. 
  void update(float ang){
    x = width/2 + int(width*radius * cos(ang));
    y = height/2 + int(height*radius * sin(ang));
    trueY = y;
    if(mouseX < width/2) { 
      x = width - x;
      y = height - y;
    }
  }
  
  //I'm bad at code.
  void displayShadow(){
    drawShadow(x,y,w,h);
  }
  
  void display(){
    drawMenhir(x,y,w,h);
  }
  
}

//creates the environment and the first menhir
void setup(){
  size(700,700);
  menhirs = new ArrayList<Menhir>();
  menhirs.add(new Menhir());
}

//function that sorts the menhirs based on y position, so that
//they can later drawn from front to back.
//Zach Rispoli helped write this. 
ArrayList<Menhir> zjrispolsort(ArrayList<Menhir> menhirs){
  ArrayList<Menhir> sorted = new ArrayList<Menhir>();
  ArrayList<Menhir> temp = new ArrayList<Menhir>();
  for(int i = 0; i < menhirs.size(); i++){
    temp.add(menhirs.get(i));
  }
  while(temp.size() > 0) {
    int minIndex = 0;
    for(int i = 0; i < temp.size(); i++) {
      if(temp.get(i).y < temp.get(minIndex).y) {
        minIndex = i;
      }
    }
    sorted.add(temp.get(minIndex));
    temp.remove(minIndex);
  }
  
  return sorted;
}

//finds the relative angle of the mouse, and uses that to find
//the angle that each menhir should hold, then draws them in place
void draw(){
  background(255);
  float dx = float(mouseX -(width/2));
  float dy = float(mouseY -(height/2));
  float mrads = atan(dy/dx);
  float diff = TWO_PI/float(menhirs.size()+1);

  for (int i = 0; i< menhirs.size(); i++) {
    Menhir menhir = menhirs.get(i);
    float ang = mrads + diff*(i+1);
    menhir.update(ang);
  }
  
  
  ArrayList<Menhir> tempMenhirs = zjrispolsort(menhirs);
  
  //shadows rendered seperately so that all menhirs appear in front
  //of the other menhirs' shadows
  for (int i = 0; i< tempMenhirs.size(); i++) {
    Menhir menhir = tempMenhirs.get(i);
    menhir.displayShadow();
  }
  
  for (int i = 0; i< tempMenhirs.size(); i++) {
    Menhir menhir = tempMenhirs.get(i);
    menhir.display();
  }
}

// left click adds a menhir up to 10, right click removes a menhir
// down to 1
void mousePressed() {
  if (mouseButton == LEFT && menhirs.size() < 10){
    println("menhir added");
    menhirs.add(new Menhir());
  } else if (mouseButton == RIGHT && menhirs.size() > 1){
    menhirs.remove(0);
  }
}

Alex Ten Liner

Screen Shot 2014-10-01 at 5.07.59 PM

For this project, I wanted 10 lines to vibrate around the courser. Several challenges that arose were trying to figure out how to make diagonal lines starting at the bottom left and moving to the top right. I still have not figured out how to make the random variable move on the inverted axis. Therefore, unlike thee other lines that run diagonal from top left to bottom right, horizontal and vertical, the diagonal lines that run from bottom left top top right do not vibrate into each other.

void setup() {
  size(400,400);
  frameRate(10);
}

void draw(){
  background(0);
  
  float dx=random (-10, 10);
  float dy=random (-12, 12);
  float da=random (-15,15);
  float db=random (-17,17);
  float dc=random (-20,20);
  strokeWeight(3);
  
  //diagonal L to R down
  stroke(50);
  line(0,0, (mouseX-6)+dx,(mouseY-6)+dx);
  stroke(150);
  line((mouseX+6)+db,(mouseY+6)+db, width,height);
  
  //horizontal
  stroke(75);
  line(0,height/2, (mouseX-10)+da,(mouseY));
  stroke(175);
  line((mouseX+10)+dc,(mouseY), width,height/2);
  
  //vertical
  stroke(255);
  line(width/2,0, (mouseX),(mouseY-10)+dy);
  stroke(125);
  line((mouseX),(mouseY+10)+dc, width/2,height);
  
  //diagonal L to R up top
  stroke(50);
  line(0,350, (mouseX-8)+db,(mouseY+5)+db);
  stroke(225);
  line((mouseX+5)+dy,(mouseY-8)+dy, 350,0);
  
  //diagonal L to R up btm
  stroke(100);
  line(50,height, (mouseX-5)+dc,(mouseY+8)+dc);
  stroke(200);
  line((mouseX+8)+da,(mouseY-5)+da, width,50);
}

10 kinked lines

bloggif_542c6974451ce

Moving the mouse right, the line kinks and folds downward.


void setup () {
  size (600,400); 
  smooth ();
}

void draw () {
  
  background (100);
  strokeWeight (3);
  stroke (255);
  
  for (int i= 140; i <400; i+=25) {
    
    float mx = map (mouseX, 0, height, 150, 300);
    line (i, mx, i+40, 300);
    
    if (mouseY>150){
      for (int j=140; j<400; j+=25)
      
      line (j, mx, j+40, 150);
    }
    }
   
    }

Ten Lines

Concept Concept

Again, for this piece I had envisioned something that played with the idea of the mouse pushing a line forward and back. For my ten lines project I had similar problems as seen in my first one. Mainly these problems dealt with if statements and making sure they weren’t contradicting one another. I created a series of ten lines that when up horizontally that reacted to whether or not the mouse was in a certain range. The lines would then move away the mouse if it was in that range. Overall I didn’t really like this piece, mostly because of the fact that it wasn’t what I envisioned in addition to my long hours spent attempting to tackle it.

 

Complete Complete
float x1=100;
float x2=345;

int y2=300;
void setup(){
  size(450,450);
  
  
}


void draw(){
  background(0);
  
  stroke(255);
  

 
 for (int i = 0; i < =10; i = i+1) {
   
   float imov= map(i,0,10,0,height);
  line(x1, imov, x2, imov);

 if( (mouseX>=200)&&(mouseX< =300)){
   x1= imov-15;
  
 }else{
   
   x1=100;
 }
 if (mouseY<200){
   x1= random(100);
 }
 }
  
}