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 › what am i missing
Page Index Toggle Pages: 1
what am i missing? (Read 788 times)
what am i missing?
Nov 25th, 2005, 6:07pm
 
What am I missing–very unfortunatley no time at present to more thoroughly scour src.
beginShape(Points)vertex()endShape()  and  beginShape(LINES)vertex()endShape() just seem to be wrapped point() and line() calls.
I'm struggling to the understand the value added, other than consistency with other recording modes.
thanks.
Re: what am i missing?
Reply #1 - Nov 26th, 2005, 7:30pm
 
I'm trying to understand the language design decision to include beginShape() POINTS and LINES mode, if in fact they are just encapsulated point() and line() function calls. Browsing through the Processing src seems to imply this is the case. I think there is an argument to be made for their inclusion, with regard to consistency with the other shape record functions. However, I'm wondering if I'm not missing something more significant in the implementation. The following 2 simple snippets below give identical output, yet the line() approach does it with half as many lines of code as beginShape(LINES). In what situation might it be more efficient to call the latter?

size(300, 300);
background(255);
line (20, height/2, width-20, height/2);
line (width/2, height-20, width/2, 20);

size(300, 300);
background(255);
beginShape(LINES);
vertex (20, height/2);
vertex (width-20, height/2);
vertex (width/2, height-20);
vertex (width/2, 20);
endShape();

Once we move to the other beginShape() modes, there seems to be is a clear design benefit. For example, in the next 2 snippets, LINE_STRIP seems like a less kludgy solution than having to reassign terminal points yourself, or spin your own more elaborate record function. beginShape() also provides the benefit of some join control.

// elegant vertex() appraoch
size(300, 300);
background(255);
strokeWeight(3);
smooth();
beginShape(LINE_STRIP);
for (int i=0; i< 100; i++){
 vertex(random(width), random(height));
}
endShape();

// kludgy line() approach
size(300, 300);
background(255);
strokeWeight(3);
smooth();
float x = random(width);
float y = random(height);
for (int i=0; i< 100; i++){
 float x2 = random(width);
 float y2 = random(height);
 line(x, y, x2, y2);
 x = x2;
 y = y2;
}

Re: what am i missing?
Reply #2 - Nov 28th, 2005, 12:24am
 
beginShape POINTS and LINES etc can take 3D coordinates, whereas point() and line() only take 2D coordinates.
Re: what am i missing?
Reply #3 - Nov 28th, 2005, 3:14am
 
John,
I don't think that's correct. Check out:
http://test.processing.org/reference/line_.html
http://test.processing.org/reference/point_.html
Re: what am i missing?
Reply #4 - Nov 28th, 2005, 5:46am
 
beginShape() is intended to be more flexible at the expense of being a little more complicated to use. it handles more complicated shapes that can consist of many connected lines (so you get joins) or lines mixed with curves.

the line() and point() command are for the far more common cases (particularly for our audience) that simply need to draw a line or a point on the screen.

from the code side of things, line() may or may not call beginShape() etc to do the drawing. in the beta code, they do, but in the alpha code, they did not. they might be implemented one way or the other depending on tradeoffs of runtime efficiency vs. implementation efficiency--meaning the speed that things run at vs. the speed it takes me to write the code and maintain it. for beta, the latter is most important so that's how things are implemented.
Re: what am i missing?
Reply #5 - Nov 28th, 2005, 7:22am
 
Thanks Ben.
Page Index Toggle Pages: 1