OK, so you made your first code “sketch”, but the likely hood is high, you have now idea “what is going on”.
Let’s start to talk about that a bit.
Here is the code again;
1
2
3
function setup(){
ellipse(20, 20, 30, 30);
}
First, let’s discuss line two.
In line no. 2, we used our first “function”.
A function is a;
A function is a;
()
, without a space between them and the piece of text.
nameOfFunction()
A function;
In our case, the function we are using in line no. 2 is ellipse()
.
The ellipse function is used to draw ellipses, such as;
The behavior or specifics of what a function does are specified by “parameters”.
In p5, this may be;
Parameters;
,
.In our example, there are 4 parameters.
20
pixels in, along the X-axis (from the left of the canvas).20
pixels down, along the Y-axis (from the top of the canvas).1
2
3
function setup(){
ellipse(20, 20, 30, 30);
}
I would like you to know change these parameters and notice the change to your code “sketch”.
ellipse()
function in line 2.Doing this will change the position and size of the ellipse in the left corner of the available code output area.
Regrettably, until you spend many, many, many, hours coding in p5, or any language, it will be difficult to remember;
Luckily, any language “worth it’s salt” will have detailed and accessible documentation. p5 is a language designed for artists and beginners, and has a great documentation section.
Let’s look at the documentation for the ellipse()
function. Below is the documentation page for the ellipse()
function from the p5 website.
Notice that this page from top-to-bottom tells the user;
ellipse()
function.ellipse()
function, this lists the function, along with the parameters it accepts.[]
, are optional parameters.
ellipse()
, providing only the w
parameter is acceptable, as the function will use the same value for the height of the ellipse, thereby creating a perfect circle.ellipse()
each parameter expects a “Number”.ellipse()
, the function returns a new “ellipse object”.(Direct Link to ellipse()
doc page. In case the page does not load below, or you would like to see the page directly in the p5 website.)
The following link will take you to the top-level page for p5 documentation. You should book mark this page, as you will utilize it a lot this semester. Please do a number of things on this page;
ellipse()
function and identify how it is categorized? (i.e. what headings is it underneath?)ellipse()
. See if the documentation for these functions makes sense? And if you can understand how they might be used?