We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › draw()ing for beginners
Pages: 1 2 
draw()ing for beginners (Read 2043 times)
draw()ing for beginners
Sep 29th, 2005, 5:14pm
 

i feel quite stupid, but im not able to continue with the program within draw() after pushing a button (->saveframe)...

i thought loop() would make that run again, but it doesnt really work...
it tried to do like:

void keyPressed(){
  if (key==...)  {
     safeframe......);
     loop();
  }
}

and all other variants i could think of...

thanks for any help



Re: draw()ing for beginners
Reply #1 - Sep 29th, 2005, 5:21pm
 
try this:

Code:

boolean save;

void setup()
{
...
save=false;
}

void draw()
{
...
if(save)
{
saveframe(...);
save=false;
}
}

void keyPressed()
{
if(key==...)
{
save=true;
}
}


I'm not entirely sure if that'll solve it, but it might.
Re: draw()ing for beginners
Reply #2 - Sep 29th, 2005, 6:38pm
 
good idea and thanx for the help, but that doesnt solve
the problem...

its still stopping after the safeframe!

(the funny thing is: in an old version (67 i think) im running the program without any problem, im even able to use loop() instead of draw())
Re: draw()ing for beginners
Reply #3 - Sep 29th, 2005, 6:50pm
 

What about just using save() does that make any difference?

I've not encountered problems with this before.
Re: draw()ing for beginners
Reply #4 - Sep 29th, 2005, 8:30pm
 
could it be just that you're not capitalizing saveFrame() properly?
Re: draw()ing for beginners
Reply #5 - Sep 29th, 2005, 10:51pm
 
using save() doesnt make a difference and i do capitalize saveFrame() properly...

but i think the problem must be there, im using keys and the mouse for other functions without any problem..the saving process is going very well, i get the pictures i want (which was the problem with the old version)

i must say that im realy not a good programer, im sure i didnt choose the best way to do. im just confused cause it worked very well with version 67...
Re: draw()ing for beginners
Reply #6 - Sep 29th, 2005, 10:55pm
 
If you can, post all the code here, or give a link to the code, then it might be possible to go and hunt down the problem.
Re: draw()ing for beginners
Reply #7 - Sep 30th, 2005, 11:10am
 
i went back to 67!!
i dont have problems with stopping there and with the input of jonG i was able to eliminate the safing problems i had before...

Thanks a lot to everybody for the help!





Re: draw()ing for beginners
Reply #8 - Sep 30th, 2005, 11:59am
 
It would still be good to see the code that doesn't work, in case there is an issue that needs resolving that other coders are going to encounter.

Bug tracking basically!
Re: draw()ing for beginners
Reply #9 - Sep 30th, 2005, 4:06pm
 
right, 67 isn't being supported anymore so if there's something legitimately broken in the new release, then we need to fix it.

btw, JohnG's listed method is no longer necessary as of beta.. the mouse and key event handling are now done properly at the end of draw, but you're allowed to draw things inside of them (where you weren't allowed to in the alpha releases).
Re: draw()ing for beginners
Reply #10 - Oct 17th, 2005, 9:52pm
 
Hi. I'm using version 91 on OS X and I'm experiencing the very same problem. Whenever I use save() or saveFrame() my program hangs having first managed to save a frame succesfully. For example a code like this:

Code:

void draw() {
 ...
 if ( doSaving ) {
   print("Saving a frame ... ");
   saveFrame();
   println("Done.");
   doSaving = false;
 }
 ...
}


produces the following output to stdout and then hangs:

Code:

Saving a frame ... Done.


I have tried quite a few different combinations none of which has worked. I suspect a bug.

Update:

To my slight surprise the following snippet works ok:

Code:

color[] cols = new color[2];
int c = 0;

void setup() {
size(100, 100);
cols[0] = color(255, 0, 0);
cols[1] = color(0, 0, 255);
}

void draw() {
background(cols[c]);
c = 1 - c;
saveFrame();
}
Re: draw()ing for beginners
Reply #11 - Oct 17th, 2005, 10:02pm
 
could you post the exact code that causes the error?

also, open up a terminal, type "java -version", and tell me what it writes back to you?
Re: draw()ing for beginners
Reply #12 - Oct 17th, 2005, 10:08pm
 
Code:

$ java -version
java version "1.4.2_09"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_09-232)
Java HotSpot(TM) Client VM (build 1.4.2-54, mixed mode)


I shall post the faulty code later on but now I've got to get some sleep. It's past eleven here in Finland.
Re: draw()ing for beginners
Reply #13 - Oct 18th, 2005, 7:33am
 
Good morning.  I guess I pinpointed the problem. The call to save() or saveFrame() seems to slow down all subsequent calls to line() by a factor somewhere between ten and hundred. So any program that uses line drawing extensively will practically freeze after saving the first frame.

I wrote two pieces of code that exemplifies this phenomenon. I'll post them here when I get home.
Re: draw()ing for beginners
Reply #14 - Oct 18th, 2005, 9:33pm
 
Here are the two pieces of code I promised earlier today. The first one works ok whereas the second one doesn't:

Code:

// Example A: This program seems to work ok. A frame is saved
// at every press of key 'S' and program continues to draw without
// problems.

color[] cols = new color[3];
int a = 0, b = 0;

void setup() {
size(100, 100);
cols[0] = color(255, 0, 0);
cols[1] = color(0, 255, 0);
cols[2] = color(0, 0, 255);
}

void draw() {
a = (a + 1) % 2;
b = (b + 1) % 3;
for ( int x = 0; x < 100; x++ ) {
for ( int y = (x + a) % 2; y < 100; y += 2) {
set(x, y, cols[b]);
}
}
}

void keyPressed() {
char k = (char) key;
if ( k == 's' || k == 'S' ) {
saveFrame();
}
}


Code:

// Example C: The following program exhibits strange
// saveFrame behaviour. Prior to saving the framerate
// is very high (tens or hundreds of frames per second).
// After a frame is saved by pressing 'S' the framerate
// drops down to few frames per second.

// My original program draws over ten thousand lines per
// frame. So if saveFrame() mysteriously slows down line()
// then it is pretty obvious why the program seems to freeze
// completely.

color[] cols = new color[3];
int a = 0, b = 0;

void setup() {
size(100, 100);
cols[0] = color(255, 0, 0);
cols[1] = color(0, 255, 0);
cols[2] = color(0, 0, 255);
}

void draw() {
a = (a + 1) % 2;
b = (b + 1) % 3;
stroke(cols[b]);
for ( int y = a; y < 100; y += 2) {
line(0, y, 99, y);
}
}

void keyPressed() {
char k = (char) key;
if ( k == 's' || k == 'S' ) {
saveFrame();
}
}
Pages: 1 2