Download - MzTEK Programming - Part 3
![Page 1: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/1.jpg)
![Page 2: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/2.jpg)
REVIEW LAST WEEK
![Page 3: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/3.jpg)
To create a new list (to declare it):
int[] x = new int[4];
![Page 4: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/4.jpg)
To create a new list (to declare it):
int[] x = new int[4];
what kind of things are in the list? i.e. how much space needs to be
reserved for each item
![Page 5: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/5.jpg)
To create a new list (to declare it):
int[] x = new int[4];
what kind of things are in the list? i.e. how much space needs to be
reserved for each item
[ ] means the data type is an array
![Page 6: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/6.jpg)
To create a new list (to declare it):
int[] x = new int[4];
what is the name of the list?
what kind of things are in the list? i.e. how much space needs to be
reserved for each item
[ ] means the data type is an array
![Page 7: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/7.jpg)
To create a new list (to declare it):
int[] x = new int[4];
what is the name of the list?
what kind of things are in the list? i.e. how much space needs to be
reserved for each item how long will the list be?
[ ] means the data type is an array
![Page 8: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/8.jpg)
if ( ) {
}else {
}
![Page 9: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/9.jpg)
if ( ) {
}else {
}
put in a comparison statement (like < or >)
![Page 10: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/10.jpg)
if ( ) {
}else {
}
put in a comparison statement (like < or >)
what to do if our comparison statement is true
![Page 11: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/11.jpg)
if ( ) {
}else {
}
put in a comparison statement (like < or >)
what to do if our comparison statement is true
what to do if our comparison statement is false
![Page 12: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/12.jpg)
if ( ) {
}else {
}
we don’t have to always have an else
statement, sometimes you only care if the statement is true
put in a comparison statement (like < or >)
what to do if our comparison statement is true
what to do if our comparison statement is false
![Page 13: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/13.jpg)
What if we want to use multiple if statements?
int counter;// some other code...if (counter < 10) {if (counter > 0 ) {counter++;
}}
![Page 14: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/14.jpg)
What if we want to use multiple if statements?
int counter;// some other code...if (counter < 10) {if (counter > 0 ) {counter++;
}}
If counter is less than 10 and greater than 0, then increase counter by 1.
![Page 15: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/15.jpg)
What if we want to use multiple if statements?
int counter;// some other code...if (counter < 10) {if (counter > 0 ) {counter++;
}}
If counter is less than 10 and greater than 0, then increase counter by 1.
counter is only increased if both if statements are true.
![Page 16: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/16.jpg)
What if we want to use multiple if statements?
int counter;// some other code...if (counter < 10) {if (counter > 0 ) {counter++;
}}
If counter is less than 10 and greater than 0, then increase counter by 1.
These are called nested if statements, because one is inside the { } of the other.
counter is only increased if both if statements are true.
![Page 17: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/17.jpg)
int counter;// some other code...if (counter > 10) {counter = 0;
}if (counter < 0 ) {counter = 0;}
}
What if we want to use multiple if statements?
![Page 18: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/18.jpg)
int counter;// some other code...if (counter > 10) {counter = 0;
}if (counter < 0 ) {counter = 0;}
}
If counter is greater than 10 or less than 0, then reset counter to 0.
What if we want to use multiple if statements?
![Page 19: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/19.jpg)
int counter;// some other code...if (counter > 10) {counter = 0;
}if (counter < 0 ) {counter = 0;}
}
If counter is greater than 10 or less than 0, then reset counter to 0.
counter is reset if either if
statements are true.
What if we want to use multiple if statements?
![Page 20: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/20.jpg)
BOOLEAN OPERATOR OR
ORTrue False
TrueFalse
True True
False False
OR
OR
OR
is
is
is
is
![Page 21: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/21.jpg)
BOOLEAN OPERATOR OR
ORTrue False
TrueFalse
True
True True
False False
OR
OR
OR
is
is
is
is
![Page 22: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/22.jpg)
BOOLEAN OPERATOR OR
ORTrue False
TrueFalse
True
True True
False False
OR
OR
OR
is
is
is
is
True
![Page 23: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/23.jpg)
BOOLEAN OPERATOR OR
ORTrue False
TrueFalse
True
True True
False False
OR
OR
OR
is
is
is
is
True
True
![Page 24: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/24.jpg)
BOOLEAN OPERATOR OR
ORTrue False
TrueFalse
True
False
True True
False False
OR
OR
OR
is
is
is
is
True
True
![Page 25: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/25.jpg)
BOOLEAN OPERATOR OR
ORTrue False
TrueFalse
True
False
True True
False False
OR
OR
OR
is
is
is
is
True
True
When using OR in code, type ||
![Page 26: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/26.jpg)
int counter;// some other code...
if (counter > 10) {counter = 0;
}if (counter < 0 ) {counter = 0;}
}
![Page 27: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/27.jpg)
int counter;// some other code...
if (counter > 10) {counter = 0;
}if (counter < 0 ) {counter = 0;}
} int counter;// some other code...
if ((counter < 0) ||counter > 10)) {counter = 0;
}
![Page 28: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/28.jpg)
int counter;// some other code...
if (counter > 10) {counter = 0;
}if (counter < 0 ) {counter = 0;}
} int counter;// some other code...
if ((counter < 0) ||counter > 10)) {counter = 0;
}
OR
![Page 29: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/29.jpg)
BOOLEAN OPERATOR AND
ANDTrue False
TrueFalse
True True
False False
AND
AND
AND
is
is
is
is
![Page 30: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/30.jpg)
BOOLEAN OPERATOR AND
ANDTrue False
TrueFalse
True True
False False
AND
AND
AND
is
is
is
is
False
![Page 31: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/31.jpg)
False
BOOLEAN OPERATOR AND
ANDTrue False
TrueFalse
True True
False False
AND
AND
AND
is
is
is
is
False
![Page 32: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/32.jpg)
False
BOOLEAN OPERATOR AND
ANDTrue False
TrueFalse
True True
False False
AND
AND
AND
is
is
is
is
True
False
![Page 33: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/33.jpg)
False
BOOLEAN OPERATOR AND
ANDTrue False
TrueFalse
False
True True
False False
AND
AND
AND
is
is
is
is
True
False
![Page 34: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/34.jpg)
False
BOOLEAN OPERATOR AND
ANDTrue False
TrueFalse
False
True True
False False
AND
AND
AND
is
is
is
is
True
When using AND in code, type &&
False
![Page 35: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/35.jpg)
int counter;// some other code...
if (counter < 10) {if (counter > 0 ) {counter++;
}}
![Page 36: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/36.jpg)
int counter;// some other code...
if (counter < 10) {if (counter > 0 ) {counter++;
}}
int counter;// some other code...
if ((counter > 0) &&(counter < 10)) {counter++;
}
![Page 37: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/37.jpg)
int counter;// some other code...
if (counter < 10) {if (counter > 0 ) {counter++;
}}
int counter;// some other code...
if ((counter > 0) &&(counter < 10)) {counter++;
}
AND
![Page 38: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/38.jpg)
BOOLEAN OPERATOR NOT
NOT True
FalseNOT
is
is
![Page 39: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/39.jpg)
BOOLEAN OPERATOR NOT
NOT True
FalseNOT
Falseis
is
![Page 40: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/40.jpg)
BOOLEAN OPERATOR NOT
NOT True
FalseNOT
False
True
is
is
![Page 41: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/41.jpg)
BOOLEAN OPERATOR NOT
NOT True
FalseNOT
False
True
is
is
When using NOT in code, type !
![Page 42: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/42.jpg)
int stopLoop = 0;// some other code...
if(!stopLoop) {// some more code...
}
![Page 43: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/43.jpg)
int stopLoop = 0;// some other code...
if(!stopLoop) {// some more code...
}
NOT
![Page 44: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/44.jpg)
LOOPS
There are two ways to repeat something:
1. Do this N number of times.
2. Keep doing this until something else happens.
![Page 45: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/45.jpg)
LOOPS
There are two ways to repeat something:
1. Do this N number of times.
2. Keep doing this until something else happens.
Repeat this event in the calendar this
many times.
![Page 46: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/46.jpg)
LOOPS
There are two ways to repeat something:
1. Do this N number of times.
2. Keep doing this until something else happens.
Repeat this event in the calendar this
many times.
Repeat this event in the calendar until a certain
date occurs.
![Page 47: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/47.jpg)
DO THIS N TIMES
int i;for(i=0; i<4; i++) {
}
![Page 48: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/48.jpg)
DO THIS N TIMES
int i;for(i=0; i<4; i++) {
}
start with a number, in this case 0
![Page 49: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/49.jpg)
DO THIS N TIMES
int i;for(i=0; i<4; i++) {
}
start with a number, in this case 0
if this statement is true
![Page 50: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/50.jpg)
DO THIS N TIMES
int i;for(i=0; i<4; i++) {
}
start with a number, in this case 0
if this statement is true
then do whatever is written here
![Page 51: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/51.jpg)
DO THIS N TIMES
int i;for(i=0; i<4; i++) {
}
start with a number, in this case 0
if this statement is true
when you’ve done what’s in the { } once, do this, in this case add make i equal to its current value plus 1
then do whatever is written here
![Page 52: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/52.jpg)
DO THIS N TIMES
int i;for(i=0; i<4; i++) {
}
start with a number, in this case 0
if this statement is true
when you’ve done what’s in the { } once, do this, in this case add make i equal to its current value plus 1
then do whatever is written here
go back to see if the middle statement is still
true
![Page 53: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/53.jpg)
KEEP DOING THIS UNTIL SOMETHING ELSE HAPPENS
while ( ) {
}
![Page 54: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/54.jpg)
KEEP DOING THIS UNTIL SOMETHING ELSE HAPPENS
while ( ) {
}
if the statement here is true
![Page 55: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/55.jpg)
KEEP DOING THIS UNTIL SOMETHING ELSE HAPPENS
while ( ) {
}
if the statement here is true
then do what is between { } once
![Page 56: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/56.jpg)
KEEP DOING THIS UNTIL SOMETHING ELSE HAPPENS
while ( ) {
}
if the statement here is true
then do what is between { } once
then repeat by checking the statement again
![Page 57: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/57.jpg)
EXERCISEWrite out each iteration of these loops and what the variables equal at the end of each loop.
int i;int j = 15;
for (i=0; i<5; i++) {j = j * 2 - i;
}
int k = 100;
while ( k > 0 ) {k = k -10;
}
![Page 58: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/58.jpg)
EXERCISE
Go through code at http://processing.org/learning/basics/embeddediteration.html
• identify all of the variables, why were those data types chosen?
• identify all of the comparisons made
• identify all control structures
• draw a diagram explaining what is happening in the code
![Page 59: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/59.jpg)
float box_size = 11; float box_space = 12; int margin = 7; size(200, 200); background(0); noStroke(); // Draw gray boxes for (int i = margin; i < height-margin; i += box_space){ if(box_size > 0){ for(int j = margin; j < width-margin; j+= box_space){ fill(255-box_size*10); rect(j, i, box_size, box_size); } box_size = box_size - 0.6; }}
![Page 60: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/60.jpg)
float box_size = 11; float box_space = 12; int margin = 7; size(200, 200); background(0); noStroke(); // Draw gray boxes for (int i = margin; i < height-margin; i += box_space){ if(box_size > 0){ for(int j = margin; j < width-margin; j+= box_space){ fill(255-box_size*10); rect(j, i, box_size, box_size); } box_size = box_size - 0.6; }}
![Page 61: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/61.jpg)
float box_size = 11; float box_space = 12; int margin = 7; size(200, 200); background(0); noStroke(); // Draw gray boxes for (int i = margin; i < height-margin; i += box_space){ if(box_size > 0){ for(int j = margin; j < width-margin; j+= box_space){ fill(255-box_size*10); rect(j, i, box_size, box_size); } box_size = box_size - 0.6; }}
![Page 62: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/62.jpg)
float box_size = 11; float box_space = 12; int margin = 7; size(200, 200); background(0); noStroke(); // Draw gray boxes for (int i = margin; i < height-margin; i += box_space){ if(box_size > 0){ for(int j = margin; j < width-margin; j+= box_space){ fill(255-box_size*10); rect(j, i, box_size, box_size); } box_size = box_size - 0.6; }}
![Page 63: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/63.jpg)
float box_size = 11; float box_space = 12; int margin = 7; size(200, 200); background(0); noStroke(); // Draw gray boxes for (int i = margin; i < height-margin; i += box_space){ if(box_size > 0){ for(int j = margin; j < width-margin; j+= box_space){ fill(255-box_size*10); rect(j, i, box_size, box_size); } box_size = box_size - 0.6; }}
![Page 64: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/64.jpg)
FUNCTIONS
![Page 65: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/65.jpg)
input
output
function
![Page 66: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/66.jpg)
input
output
function
A function is something that can take input, do something, and then output something.
![Page 67: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/67.jpg)
input
output
function
A function is something that can take input, do something, and then output something.
The input and output are optional, some functions do
not have both.
![Page 68: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/68.jpg)
input
output
function
A function is something that can take input, do something, and then output something.
The input and output are optional, some functions do
not have both.
Functions exist so that you don’t have to
write a lot of code.
![Page 69: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/69.jpg)
size(300, 400);
When you call the function size( )
![Page 70: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/70.jpg)
size(300, 400);
When you call the function size( )
it creates a window with the parameters you entered
![Page 71: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/71.jpg)
size(300, 400);
When you call the function size( )
and then the program continues with the next line of code.
it creates a window with the parameters you entered
![Page 72: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/72.jpg)
size(300, 400);
When you call the function size( )
and then the program continues with the next line of code.
it creates a window with the parameters you entered
It has a return type of void, so there’s nothing given back directly to your program, but it does some work for you. It created the window.
![Page 73: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/73.jpg)
size(300, 400);
When you call the function size( )
and then the program continues with the next line of code.
it creates a window with the parameters you entered
It has a return type of void, so there’s nothing given back directly to your program, but it does some work for you. It created the window.
In Processing, (as far as I know) all functions have a void return type.
![Page 74: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/74.jpg)
void means that nothing is returned.
![Page 75: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/75.jpg)
void means that nothing is returned.
void setup( ) {
}
![Page 76: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/76.jpg)
void means that nothing is returned.
void setup( ) {
}
is typed when you want to have something happen between { }.
![Page 77: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/77.jpg)
void means that nothing is returned.
void setup( ) {
}
is typed when you want to have something happen between { }.
The void in front of setup means nothing is returned after setup( ) is finished.
![Page 78: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/78.jpg)
In Arduino:
int val = 0;int inPin = 7;val = digitalRead(inPin);
![Page 79: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/79.jpg)
In Arduino:
int val = 0;int inPin = 7;val = digitalRead(inPin);
function name
![Page 80: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/80.jpg)
In Arduino:
int val = 0;int inPin = 7;val = digitalRead(inPin);
function name
input parameters and
type
![Page 81: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/81.jpg)
In Arduino:
int val = 0;int inPin = 7;val = digitalRead(inPin);
function name
input parameters and
type
an int is returned, so it needs to be stored somewhere
![Page 82: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/82.jpg)
FINAL EXERCISE
![Page 83: MzTEK Programming - Part 3](https://reader034.vdocuments.us/reader034/viewer/2022051209/548349a5b07959520c8b4a07/html5/thumbnails/83.jpg)
void setup() {// create the windowsize(400, 400);
}
void draw() {// set the colourfill(10, 10, 255);
// draw the circleellipse(mouseX, mouseY, 100, 100);
}
Within your program use:
• Variables
• For or while loop
• If or if/else
Start with this code.
Create a Processing program that generatively draws depending on the
mouse position.