Recently I've been looking at Povray, pyprocessing, and cfdg (version 3.0) as tools for creating digital images. I have branched two separate blogs where I mainly explore jruby + processing and processing.py

Thursday, 15 January 2009

Exploring IO in processing

Processing has some pretty simple syntax for IO, but you can see its java roots. Heres an example I knocked up earlier that uses one Processing program to create another! The second program (once moved to a new folder join_the_dots, preferably in your sketchbook folder will display an empty polygon that connects the 'mouse click' defined points. To exit the point entry program, press any key!!!

   1:PrintWriter output;
2:PFont font;
3:
4:int[] first;
5:void setup(){
6: size(400, 400);
7: font = createFont("TimesRoman", 24);
8: textFont(font);
9: fill(0);
10: text("Click Mouse to Register Point:", 5, 25);
11: text("Any Key to exit:", 5, 50);
12: output = createWriter("join_the_dots.pde");
13: output.println("size(400, 400);");
14: output.println("smooth();");
15: output.println("strokeWeight(4);");
16: output.println("beginShape(LINE);");
17:}
18:
19:void draw(){
20:}
21:// Click mouse to register a point
22:void mousePressed() {
23: if (first == null){
24: first =new int[2];
25: first[0] = mouseX;
26: first[1] = mouseY;
27: output.println("vertex(" + first[0] + ", " + first[1] + ");");
28: }
29: else{
30: output.println("vertex(" + mouseX + ", " + mouseY + ");");
31: output.println("vertex(" + mouseX + ", " + mouseY + ");");
32: }
33:}
34:// Press any key to end drawing
35:void keyPressed() {
36: output.println("vertex(" + first[0] + ", " + first[1] + ");");
37: output.println("endShape(CLOSE);");
38: output.flush(); // Writes the remaining data to the file
39: output.close(); // Finishes the file
40: exit(); // Stops the program
41:}

No comments:

Post a Comment

Followers

Blog Archive

About Me

My photo
Pembrokeshire, United Kingdom
I have developed JRubyArt and propane new versions of ruby-processing for JRuby-9.1.5.0 and processing-3.2.2