User Tools

Site Tools


Sidebar



processing2

Processing

for loop with array
String lines[] = loadStrings("http://companje.nl/api?netnummers");
 
for (String s:lines) {
  println(s);
}
from array to List to ArrayList
List<String> strings = new ArrayList(Arrays.asList(lines));
for loop with ArrayList
ArrayList<Dot> dots = new ArrayList();
 
for (Dot d:dots) {
  d.draw();
}
ArrayList / HashSet tricks
String[] allWords = split(join(loadStrings("rowboats.txt")," ").toUpperCase()," ");
String[] uniqueWords = sort(new HashSet<String>(Arrays.asList(allWords)).toArray(new String[0]));
//...
Arrays.asList(uniqueWords).indexOf(allWords[j]);
Basic movie copying
import processing.video.*;
Movie mov;
MovieMaker mm;
int w=1024;
int h=512;
 
void setup() {
  size(w,h);
  mov = new Movie(this,"waterworld.mov");
  mov.play();
  mm = new MovieMaker(this, w, h, "movie.mov", 30, MovieMaker.ANIMATION, MovieMaker.HIGH); 
}
 
void draw() {
  if (mov.available() && mov.width>1) image(mov,0,0);
  if (mov.time()<mov.duration()) mm.addFrame();
  else mm.finish();
}
ArrayIndexOutOfBoundsException: Coordinate out of bounds when playing Movie

Somehow the size of the first frame seems to 1×1 pixel. You can use this workaround.

mov = new Movie(this,"energy.mov");
mov.play();
//...
if (mov.available() && mov.width>1) image(mov,0,0);
Fibonacci Spiral

Fibonacci Spiral

float phi = (sqrt(5)+1)/2;
 
size(323,200);
translate(height/phi,0);
scale(height);
noStroke();  
smooth();
 
for (float i=0; i<10; i++) {
  fill(i/10*255);
  rect(0,0,1,1);
  fill(255,255,0,150);
  arc(0,0,2,2,0,PI/2);
  scale(1/phi);
  rotate(PI/2);
  translate(1/phi,0);   
}
processing2.txt · Last modified: 2014/11/23 16:33 (external edit)