Wednesday, March 6, 2013

quick icons in processing

Twice now I started fumbling with the need to make simple graphics for a demo. In both cases, it wasn't a picture or anything, just a big red arrow in one case, and a little "switcher" icon. Rather than fiddling with graphic programs (though I really should get better at learning some kind of vector art app) I went to processing:


PGraphics buf;

void setup(){
  size(30,30); 

  buf = createGraphics(30,30);
  buf.beginDraw();
  buf.stroke(255);
  buf.strokeWeight(2);
  buf.strokeCap(ROUND);
  buf.line(5,15,25,15);
  buf.line(5,15,10,10);
  buf.line(5,15,10,20);
  buf.line(25,15,20,10);
  buf.line(25,15,20,20);
  buf.endDraw();
  buf.save("switch.png"); 
}
void draw(){
  image(buf,0,0);
}

By using an offscreen graphics buffer, I could create an image with a transparent background, and then by doing most of the work in setup and saving then, I stopped myself from creating the image file over and over again. (But then I blasted the image to draw, so I can see it each time I changed and ran it.)

No comments:

Post a Comment