Posts categorized “Processing”.

Mouse tracking outside of the screen using Processing

This code borrows MouseInfo from JAVA to get coordinates outside of Processing’s display window. It also includes the ability to compile a PDF when you’re done by pressing the UP key in the sketch. Enjoy.

// trackScreen by Colin Owens
// Using JAVA mouseInfo for a bit of hackiness
// Use to your heart's content with attribution
// 2010

import processing.pdf.*;

Point mouse;

float weight = .05;
int lastX, lastY;

int aa = 0;

void setup() {
  background(255);
  size(screen.width,screen.height);
  mouse = MouseInfo.getPointerInfo().getLocation();  

  lastX = mouse.x;
  lastY = mouse.y;
  smooth();
  beginRecord(PDF, "filename.pdf");
  println("I'm running");
}

void draw(){
  mouse = MouseInfo.getPointerInfo().getLocation();  

  noStroke();
  fill(0,10);

  if(lastX == mouse.x && lastY == mouse.y) {
    noFill();
    stroke(aa,10);
    strokeWeight(1);
    ellipse(mouse.x,mouse.y, 20+weight,20+weight);

    noStroke();
    fill(255,03);
    ellipse(mouse.x,mouse.y, 10+weight,10+weight);
    weight = weight+.05;
  }

  else {
    stroke(aa);
    strokeWeight(.5);
    line(lastX, lastY,mouse.x,mouse.y);
    weight = .05;
  }

  lastX = mouse.x;
  lastY = mouse.y;

} 

void keyPressed() {
  if (key == CODED) {
    if (keyCode == UP) {
      endRecord();
      exit();
    }
  }
}

Processing Examples

Here are all of the examples, which were prepared by Peter Kirn of Create Digital Media. We are only required to do up to example 2d this week. If you want to do more, please do so. Be prepared to ask questions and to be confused, but don’t let this go to the last minute. It requires quite a bit of attention, just like a foreign language (because it is). Mess with it. Break it. Start over again. Put random numbers in there. Take some of the examples in Processing and mess with those. Break them. Start over again. Combine a few. Play!

Next week I will introduce variables and how variables are the key to understanding most of this stuff and why it’s not that hard after all.

Here is your link to the exercises.

Colin

—>

Processing

In preparation for the next assignment, we will learn the fundamentals of programming and visualization. We will be using processing, an open source programming language geared specifically for designers, artist and researchers. What you learn in Processing can be applied to ActionScript, Java and similar languages–the structure is basically the same.

For class next monday, download the Processing language through this link. If you are on a PC or you prefer to download from the downloads page, use this link. Be sure and download only the 0135 version.

Please feel free to take a look at the examples under FILE > EXAMPLES. To run an application, all you have to do is click on the “play” button on the upper left-hand corner.

If you have any questions, please email me.