createWriter()
in
Programming Questions
•
8 months ago
I'm new to Processing. I have written a few elementary programs. In attempting to debug a simple graphics program, I want to output debugging data generated by the program to a file instead of to the console. It looks like createWriter() would allow me to do just that. However, when I code this into my program
==================
/** My Circle
* Processing: Test programs
* By Richard L. */
int segments;
float px, py, px2, py2;
float theta, angle, angle2;
float radius = 100;
void setup(){
size(800, 800);
background(100);
}
void draw(){
output = createWriter("mydata.txt"); //line 17
background (0);
stroke(255);
strokeWeight(10);
segments = 120;
theta = 360/segments;
for (int i = 1; i<(segments + 1); i++){
angle = theta*(i-1);
angle2 = theta*(i);
stroke(i+100, i+1, i+1);
smooth();
px = cos(radians(angle))*(radius) + 200;
py = sin(radians(angle))*(radius) + 200;
px2 = cos(radians(angle2))*(radius) + 200;
py2 = sin(radians(angle2))*(radius) + 200;
line(px, py, px2, py2);
//debugging output
println(i + " ---" + angle + " ---" + angle2 + " --- " + px + " --- " + py + " --- " + px2 + " --- " + py2);
//output.println(i + " ---" + angle + " ---" + angle2 + " --- " + px + " --- " + py + " --- " + px2 + " --- " + py2);
}
println("Stop");
//output.println("Stop");
//output.flush();
//output.close();
//exit();
}
==================
and attempt to run it, I get "Cannot find anything named "output."". If I exclude this (i.e., if I remove line 17), the program runs fine. What do I need to do to get createWriter to work? Note: I am running the program in Java mode.
(note, the reason I'm debugging the program is because it works fine with segments=120, but not with segments=100. With 120, the circle is completed. With 100, it only gets to 300 degrees instead of the full 360, despite looping the full 100 times. Strange. Haven't figured out why yet.)
Thanks.
1