Tuesday, July 22, 2008

processing notes July 17

For working with 3-d models

Core.jar
Is all the stuff under reference > language


Libraries
(obj loader) use for loading object files into processing.

(pro-midi) has some problems. Input and output to midi. Not written from scratch.

If you want stuff: write it yourself. See the site for more user-created libraries. Use any java code you want.

Use: import javax(where java libraries live).audio.mid(path)


Library is a collection of classes organized in a particular way. They are shared. Best ones get added to processing website. Some get implemented into core.

Core libraries don’t need to be removed if you don’t use anything. It just ignores them.


Sketchup----open source modeling program




lib
Design by numbers john Maida at mit group made
DBN simplified syntax and drawing, logo-style drawing
Book: design by numbers

But later people wanted to do more; motion, video, sound
That’s where Processing came from
Focused on making code as simple as possible. Should run into things that you can not do in the program.





Keith Peters book about flash has explanation of bitwise operators that makes sense!!! Don’t know which one.


Concatenation code:
You can add strings like this:

  println(myRed + ", " + myGreen + ", " + myBlue);



the
+
adds multiple characters.
Most numbers and characters can be typed without using entity codes, etc.
Characters = single quote
strings = double quote

black bar at the bottom of processing window is the console.




Variables in processing are containers. Like a little box. What’s in it can change. It has to have a type and a name. once it has those 2 things you can change it as often as you like. Really big program its easy to reuse variable names by accident. To avoid problems variables have both a type and a scope.

Within its function and within its class. If in setup you can use it in setup.
Within a function can only use it in that function. Then it forgets it ever existed.
 
Int mySize = 200;
Size (mySize, mySize);


If any 2 functions need to use it, put it above the setup and they will all have access to it. Don’t make variables in draw. If you do it a lot it will slow the program down. If you load an image in draw it will redraw the image over and over as it cycles through frames.

When creating processing sketch it creates a class. When your code gets too full of other stuff objects can be created as classes.


These are operators
num = num+1 is same as num++

num +=





If then statements


Need to use if with else if you want to be compliant. Statement needs to be true or false statement.

Width and height are reserved keywords that processing knows.

Logical operator uses double symbols, like
     &&    or   ||



Better video support possible in the coming 6-12 months hopefully.




The For Loop


It’s all about counting.

1. Start with a number. 0
2. add 1
3. stop when you get to 10



for (int i= 0; i<10; i++ ) {

}


for (int i= 0; i < listLength; i + + ) {
(spaces added to because blogger wouldn't post)
}


For loop is good when you repeat yourself efficiently.

Array is for storing lists of stuff. Java list is called array.

int[] circles = {
170,113,78,30,13};

[] indicates array
/*Length of an array is the number of elements in the list*/


If you work with an image of 400 x 300 would be 120,000 pix. With video take that number x the frame rate per second x number of seconds in the video. So for loop will make better code.


Tricky thing – array has a number of slots. Numbers start at 0 and end –say 4, array has 5 elements.

myList.length-1 will tell the last slot because the array starts numbering at 0. the out of bounds exception is a mistake with the array length. Reference on processing site has details of what you can do with arrays.




int[] circles = {
170,113,78,30,13};
size(400,400);
background(150);
noStroke();
smooth();

for (int j=0;j<4;j++) {

for (int i=0;i < circles.length; i++){
fill(random(0,255), random(0,255), random(0,255));
ellipse ((width/4)*j,(height/4)*j,circles[i],circles[i]);
}
}

Loop inside the loop allows the first loop of several concentric circles to be repeated several times.



For 4 pix x 3 pix image :

for (int i=0, i<4; i++)




translation matrix
keeps track of complex math

rotate and translate commands

pop and push matrices
there is a matrix of where all stuff. Push and pop allow you to move stuff relative to where I had previously been.

See 7b

What is hard- where starts at 0. rotates around 0. position is x-y but rotation always restarts at 0.