We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am watching the Codetrain videos in order to learn how to program using Processing. In video 6.3
while discussing loops, Daniel creates a sketch that uses the functions size, stroke, background and strokeWeight. In all previous videos these functions were inside of setup but in this video they stand alone at the beginning of the code.
Is there any difference in the way these functions act when inside or outside of setup? If not, what is the purpose of the setup function?
I think I knew this, although I am not certain what a callback function is. But that does not address my question about why Daniel intialized size, stroke, strokeWeight and background outside of setup
Ah! You've meant a sketch w/o functions. That is called "immediate mode" or something like that. :\">
The PDE (Processing's IDE) automatically wraps up the functionless sketch into 1 function behind the scenes. \m/
That simplified style is for when a sketch got no animations.
It simply renders 1 static image and it's done. :)>-
Here's an online example using such style: :bz
A callback function is a customized code which is expected to be invoked when some event happens.
In the case of setup(), it is called back when the sketch is finished initializing itself.
And draw() is called back each time the sketch finishes rendering the current canvas' content to the window.
So does this mean that Processing creates void setup automatically if there is none there?
voidwhen referring to a function. L-)
voidsimply means that a function doesn't
()is the way to indicate that something is a function. :-B
This is a static sketch without functions (and therefore without setup()):
A program written as a list of statements (like the previous examples) is called a static sketch. In a static sketch, a series of functions are used to perform tasks or create a single image without any animation or interaction.
Interactive programs are drawn as a series of frames, which you can create by adding functions titled setup() and draw() as shown in the code below. These are built-in functions that are called automatically.
The setup() block runs once, and the draw() block runs repeatedly. As such, setup() can be used for any initialization; in this case, setting the screen size, making the background orange, and setting the stroke color to white. The draw() block is used to handle animation. The size() function must always be the first line inside setup().
So, in both cases setup is not created automatically if there is none there.
But of course, processing is starting things up under the hood before setup() is called (when it's there). That's why gotoloop wrote:
in case of a static sketch, there can't be a setup(), since there are no functions
in case of a Interactive program or sketch, I strongly recommend to always have a setup() (and size() as its first line)
Don't mix static and interactive approach. Either no command is in an function (static sketch) or all commands are in functions (interactive program)
This is helpful but it creates a new question for me. You say
Either no command is in a function (static sketch) or all commands are in functions (interactive program)
what is the definition of the word "command" ?
In the videos that I have been watching, global variables are declared outside of setup(). Are variable declarations not considered a command?
commands are fill, stroke, line() and rect() and all of those
Thanks to both of you who took the time to help me out