SlideShare a Scribd company logo

MzTEK Programming - Part 2

Second lecture on introductory programming for MzTEK. It covers arrays and primitive data types. It is assumed you are at least a little familiar with Processing.

1 of 131
Download to read offline
MzTEK Programming - Part 2
REVIEW LAST WEEK
Think of idea




         Break down problem
            into tiny steps


                        Write code for
                          one step


                                           Run
                                         program
Interactive
       Development
     Environment (IDE)


Code You’ve                     Instructions for
 Written                 ?         Computer

                    Compiler   Executable Program
                       +        (e.g. .exe or .app)
                     Linker
                       +
                     Loader
int   x;
int   y;
int   width;
int   height;

size(200, 200);

x = 150;
y = 100;
width = 90;
height = 80;

ellipse(x, y, width, height);
int   x;
int   y;
int   width;
                  ingredients or variables
int   height;

size(200, 200);

x = 150;
y = 100;
width = 90;
height = 80;

ellipse(x, y, width, height);
Ad

Recommended

Lecture 6 polymorphism
Lecture 6 polymorphismLecture 6 polymorphism
Lecture 6 polymorphismthe_wumberlog
 
02. Data Type and Variables
02. Data Type and Variables02. Data Type and Variables
02. Data Type and VariablesTommy Vercety
 
MzTEK Programming - Part 1
MzTEK Programming - Part 1MzTEK Programming - Part 1
MzTEK Programming - Part 1Becky Stewart
 
Auditory Display in MIR
Auditory Display in MIRAuditory Display in MIR
Auditory Display in MIRBecky Stewart
 
MzTEK Programming - Part 3
MzTEK Programming - Part 3MzTEK Programming - Part 3
MzTEK Programming - Part 3Becky Stewart
 
Intro to openFrameworks
Intro to openFrameworksIntro to openFrameworks
Intro to openFrameworksKyle McDonald
 
The Nature of Code via Cinder - Modeling the Natural World in C++
The Nature of Code via Cinder - Modeling the Natural World in C++The Nature of Code via Cinder - Modeling the Natural World in C++
The Nature of Code via Cinder - Modeling the Natural World in C++Nathan Koch
 
A Gentle Introduction to openFrameworks
A Gentle Introduction to openFrameworksA Gentle Introduction to openFrameworks
A Gentle Introduction to openFrameworksBecky Stewart
 

More Related Content

Similar to MzTEK Programming - Part 2

Data Types and variables in C++.pptx
Data Types and variables in C++.pptxData Types and variables in C++.pptx
Data Types and variables in C++.pptxjamilmalik19
 
Java data types, variables and jvm
Java data types, variables and jvm Java data types, variables and jvm
Java data types, variables and jvm Madishetty Prathibha
 
2 1. variables & data types
2 1. variables & data types2 1. variables & data types
2 1. variables & data types웅식 전
 

Similar to MzTEK Programming - Part 2 (6)

Variables
VariablesVariables
Variables
 
Primitive Data Types and Variables Lesson 02
Primitive Data Types and Variables Lesson 02Primitive Data Types and Variables Lesson 02
Primitive Data Types and Variables Lesson 02
 
General Talk on Pointers
General Talk on PointersGeneral Talk on Pointers
General Talk on Pointers
 
Data Types and variables in C++.pptx
Data Types and variables in C++.pptxData Types and variables in C++.pptx
Data Types and variables in C++.pptx
 
Java data types, variables and jvm
Java data types, variables and jvm Java data types, variables and jvm
Java data types, variables and jvm
 
2 1. variables & data types
2 1. variables & data types2 1. variables & data types
2 1. variables & data types
 

Recently uploaded

Chromatography-Gas chromatography-Principle
Chromatography-Gas chromatography-PrincipleChromatography-Gas chromatography-Principle
Chromatography-Gas chromatography-Principleblessipriyanka
 
UniSC Fraser Coast library self-guided tour
UniSC Fraser Coast library self-guided tourUniSC Fraser Coast library self-guided tour
UniSC Fraser Coast library self-guided tourUSC_Library
 
Practical Research 1: Qualitative Research and Its Importance in Daily Life.pptx
Practical Research 1: Qualitative Research and Its Importance in Daily Life.pptxPractical Research 1: Qualitative Research and Its Importance in Daily Life.pptx
Practical Research 1: Qualitative Research and Its Importance in Daily Life.pptxKatherine Villaluna
 
Data Modeling - Entity Relationship Diagrams-1.pdf
Data Modeling - Entity Relationship Diagrams-1.pdfData Modeling - Entity Relationship Diagrams-1.pdf
Data Modeling - Entity Relationship Diagrams-1.pdfChristalin Nelson
 
DISCOURSE: TEXT AS CONNECTED DISCOURSE
DISCOURSE:   TEXT AS CONNECTED DISCOURSEDISCOURSE:   TEXT AS CONNECTED DISCOURSE
DISCOURSE: TEXT AS CONNECTED DISCOURSEMYDA ANGELICA SUAN
 
Food Web SlideShare for Ecology Notes Quiz in Canvas
Food Web SlideShare for Ecology Notes Quiz in CanvasFood Web SlideShare for Ecology Notes Quiz in Canvas
Food Web SlideShare for Ecology Notes Quiz in CanvasAlexandraSwartzwelde
 
CapTechTalks Webinar Feb 2024 Darrell Burrell.pptx
CapTechTalks Webinar Feb 2024 Darrell Burrell.pptxCapTechTalks Webinar Feb 2024 Darrell Burrell.pptx
CapTechTalks Webinar Feb 2024 Darrell Burrell.pptxCapitolTechU
 
ACTIVIDAD DE CLASE No 1 sopa de letras.docx
ACTIVIDAD DE CLASE No 1 sopa de letras.docxACTIVIDAD DE CLASE No 1 sopa de letras.docx
ACTIVIDAD DE CLASE No 1 sopa de letras.docxMaria Lucia Céspedes
 
skeletal system details with joints and its types
skeletal system details with joints and its typesskeletal system details with joints and its types
skeletal system details with joints and its typesMinaxi patil. CATALLYST
 
2.20.24 Asian Americans and the Myth of the Model Minority.pptx
2.20.24 Asian Americans and the Myth of the Model Minority.pptx2.20.24 Asian Americans and the Myth of the Model Minority.pptx
2.20.24 Asian Americans and the Myth of the Model Minority.pptxMaryPotorti1
 
UniSC Moreton Bay Library self-guided tour
UniSC Moreton Bay Library self-guided tourUniSC Moreton Bay Library self-guided tour
UniSC Moreton Bay Library self-guided tourUSC_Library
 
Evaluation and management of patients with Dyspepsia.pptx
Evaluation and management of patients with Dyspepsia.pptxEvaluation and management of patients with Dyspepsia.pptx
Evaluation and management of patients with Dyspepsia.pptxgarvitnanecha
 
Barrow Motor Ability Test - TEST, MEASUREMENT AND EVALUATION IN PHYSICAL EDUC...
Barrow Motor Ability Test - TEST, MEASUREMENT AND EVALUATION IN PHYSICAL EDUC...Barrow Motor Ability Test - TEST, MEASUREMENT AND EVALUATION IN PHYSICAL EDUC...
Barrow Motor Ability Test - TEST, MEASUREMENT AND EVALUATION IN PHYSICAL EDUC...Rabiya Husain
 
Writing Agony Letter & If type O+1 & Diphthongs + Text “Arab Science”.pdf
Writing Agony Letter & If type O+1 & Diphthongs + Text “Arab Science”.pdfWriting Agony Letter & If type O+1 & Diphthongs + Text “Arab Science”.pdf
Writing Agony Letter & If type O+1 & Diphthongs + Text “Arab Science”.pdfMr Bounab Samir
 
ICSE English Literature Class X Handwritten Notes
ICSE English Literature Class X Handwritten NotesICSE English Literature Class X Handwritten Notes
ICSE English Literature Class X Handwritten NotesGauri S
 
mean stack mean stack mean stack mean stack
mean stack mean stack  mean stack  mean stackmean stack mean stack  mean stack  mean stack
mean stack mean stack mean stack mean stackNuttavutThongjor1
 
Shapley Tech Talk - SHAP and Shapley Discussion
Shapley Tech Talk - SHAP and Shapley DiscussionShapley Tech Talk - SHAP and Shapley Discussion
Shapley Tech Talk - SHAP and Shapley DiscussionTushar Tank
 

Recently uploaded (20)

Chromatography-Gas chromatography-Principle
Chromatography-Gas chromatography-PrincipleChromatography-Gas chromatography-Principle
Chromatography-Gas chromatography-Principle
 
Capter 5 Climate of Ethiopia and the Horn GeES 1011.pdf
Capter 5 Climate of Ethiopia and the Horn GeES 1011.pdfCapter 5 Climate of Ethiopia and the Horn GeES 1011.pdf
Capter 5 Climate of Ethiopia and the Horn GeES 1011.pdf
 
UniSC Fraser Coast library self-guided tour
UniSC Fraser Coast library self-guided tourUniSC Fraser Coast library self-guided tour
UniSC Fraser Coast library self-guided tour
 
Practical Research 1: Qualitative Research and Its Importance in Daily Life.pptx
Practical Research 1: Qualitative Research and Its Importance in Daily Life.pptxPractical Research 1: Qualitative Research and Its Importance in Daily Life.pptx
Practical Research 1: Qualitative Research and Its Importance in Daily Life.pptx
 
Data Modeling - Entity Relationship Diagrams-1.pdf
Data Modeling - Entity Relationship Diagrams-1.pdfData Modeling - Entity Relationship Diagrams-1.pdf
Data Modeling - Entity Relationship Diagrams-1.pdf
 
DISCOURSE: TEXT AS CONNECTED DISCOURSE
DISCOURSE:   TEXT AS CONNECTED DISCOURSEDISCOURSE:   TEXT AS CONNECTED DISCOURSE
DISCOURSE: TEXT AS CONNECTED DISCOURSE
 
Food Web SlideShare for Ecology Notes Quiz in Canvas
Food Web SlideShare for Ecology Notes Quiz in CanvasFood Web SlideShare for Ecology Notes Quiz in Canvas
Food Web SlideShare for Ecology Notes Quiz in Canvas
 
CapTechTalks Webinar Feb 2024 Darrell Burrell.pptx
CapTechTalks Webinar Feb 2024 Darrell Burrell.pptxCapTechTalks Webinar Feb 2024 Darrell Burrell.pptx
CapTechTalks Webinar Feb 2024 Darrell Burrell.pptx
 
ACTIVIDAD DE CLASE No 1 sopa de letras.docx
ACTIVIDAD DE CLASE No 1 sopa de letras.docxACTIVIDAD DE CLASE No 1 sopa de letras.docx
ACTIVIDAD DE CLASE No 1 sopa de letras.docx
 
first section physiology laboratory.pptx
first section physiology laboratory.pptxfirst section physiology laboratory.pptx
first section physiology laboratory.pptx
 
skeletal system details with joints and its types
skeletal system details with joints and its typesskeletal system details with joints and its types
skeletal system details with joints and its types
 
2.20.24 Asian Americans and the Myth of the Model Minority.pptx
2.20.24 Asian Americans and the Myth of the Model Minority.pptx2.20.24 Asian Americans and the Myth of the Model Minority.pptx
2.20.24 Asian Americans and the Myth of the Model Minority.pptx
 
UniSC Moreton Bay Library self-guided tour
UniSC Moreton Bay Library self-guided tourUniSC Moreton Bay Library self-guided tour
UniSC Moreton Bay Library self-guided tour
 
Evaluation and management of patients with Dyspepsia.pptx
Evaluation and management of patients with Dyspepsia.pptxEvaluation and management of patients with Dyspepsia.pptx
Evaluation and management of patients with Dyspepsia.pptx
 
Barrow Motor Ability Test - TEST, MEASUREMENT AND EVALUATION IN PHYSICAL EDUC...
Barrow Motor Ability Test - TEST, MEASUREMENT AND EVALUATION IN PHYSICAL EDUC...Barrow Motor Ability Test - TEST, MEASUREMENT AND EVALUATION IN PHYSICAL EDUC...
Barrow Motor Ability Test - TEST, MEASUREMENT AND EVALUATION IN PHYSICAL EDUC...
 
Writing Agony Letter & If type O+1 & Diphthongs + Text “Arab Science”.pdf
Writing Agony Letter & If type O+1 & Diphthongs + Text “Arab Science”.pdfWriting Agony Letter & If type O+1 & Diphthongs + Text “Arab Science”.pdf
Writing Agony Letter & If type O+1 & Diphthongs + Text “Arab Science”.pdf
 
ICSE English Literature Class X Handwritten Notes
ICSE English Literature Class X Handwritten NotesICSE English Literature Class X Handwritten Notes
ICSE English Literature Class X Handwritten Notes
 
mean stack mean stack mean stack mean stack
mean stack mean stack  mean stack  mean stackmean stack mean stack  mean stack  mean stack
mean stack mean stack mean stack mean stack
 
Time-Honored Wisdom: African Teachings for VUCA Leaders
Time-Honored Wisdom: African Teachings for VUCA LeadersTime-Honored Wisdom: African Teachings for VUCA Leaders
Time-Honored Wisdom: African Teachings for VUCA Leaders
 
Shapley Tech Talk - SHAP and Shapley Discussion
Shapley Tech Talk - SHAP and Shapley DiscussionShapley Tech Talk - SHAP and Shapley Discussion
Shapley Tech Talk - SHAP and Shapley Discussion
 

MzTEK Programming - Part 2

  • 3. Think of idea Break down problem into tiny steps Write code for one step Run program
  • 4. Interactive Development Environment (IDE) Code You’ve Instructions for Written ? Computer Compiler Executable Program + (e.g. .exe or .app) Linker + Loader
  • 5. int x; int y; int width; int height; size(200, 200); x = 150; y = 100; width = 90; height = 80; ellipse(x, y, width, height);
  • 6. int x; int y; int width; ingredients or variables int height; size(200, 200); x = 150; y = 100; width = 90; height = 80; ellipse(x, y, width, height);
  • 7. int x; int y; int width; ingredients or variables int height; size(200, 200); x = 150; y = 100; directions or algorithm width = 90; height = 80; ellipse(x, y, width, height);
  • 8. data type int x; int y; int width; ingredients or variables int height; size(200, 200); x = 150; y = 100; directions or algorithm width = 90; height = 80; ellipse(x, y, width, height);
  • 9. data type variable name int x; int y; int width; ingredients or variables int height; size(200, 200); x = 150; y = 100; directions or algorithm width = 90; height = 80; ellipse(x, y, width, height);
  • 10. DECLARATION VS INITIALISATION As in a recipe, ingredients need to be listed at the top so you know what to buy. In code, it’s so the compiler knows how much memory to reserve. This is called declaring.
  • 11. DECLARATION VS INITIALISATION As in a recipe, ingredients need to be listed at the top so you know what to buy. In code, it’s so the compiler knows how much memory to reserve. This is called declaring. int myInt; Reserve space for an int
  • 12. DECLARATION VS INITIALISATION As in a recipe, ingredients We don’t have to know need to be listed at the top what value will be stored in so you know what to buy. myInt right away. In code, it’s so the compiler We can choose a value knows how much memory to reserve. This is called later. This is called initialising. declaring. int myInt; Reserve space for an int
  • 13. DECLARATION VS INITIALISATION As in a recipe, ingredients We don’t have to know need to be listed at the top what value will be stored in so you know what to buy. myInt right away. In code, it’s so the compiler We can choose a value knows how much memory to reserve. This is called later. This is called initialising. declaring. int myInt; myInt = 15; Reserve space for Store the value 15 in the an int space reserved for myInt 15
  • 14. Need to declare before or at the same time as initialisation.
  • 15. Need to declare before or at the same time as initialisation. myInt = 3; int myInt;
  • 16. Need to declare before or at the same time as initialisation. myInt = 3; int myInt; int myInt; myInt = 3;
  • 17. Need to declare before or at the same time as initialisation. myInt = 3; int myInt; int myInt; myInt = 3; Can’t use a variable before it is initialised.
  • 18. Need to declare before or at the same time as initialisation. myInt = 3; int myInt; int myInt; myInt = 3; Can’t use a variable before it is initialised. int myInt; myInt = myInt + 7;
  • 19. Need to declare before or at the same time as initialisation. myInt = 3; int myInt; int myInt; myInt = 3; Can’t use a variable before it is initialised. int myInt; int myInt = 3; myInt = myInt + 7; myInt = myInt + 7;
  • 20. TO CREATE A VARIABLE 1. Decide what the data type should be. Usually the main decisions are between int, float and char. float int char
  • 21. TO CREATE A VARIABLE 1. Decide what the data type should be. Usually the main decisions are between int, float and char. to create a float type float int char
  • 22. TO CREATE A VARIABLE 1. Decide what the data type should be. Usually the main decisions are between int, float and char. to create a float type float to create an int type int char
  • 23. TO CREATE A VARIABLE 1. Decide what the data type should be. Usually the main decisions are between int, float and char. to create a float type float to create an int type int to create a char type char
  • 24. TO CREATE A VARIABLE 1. Decide what the data type should be. Usually the main decisions are between int, float and char. to create a float type float to create an int type int to create a char type char 2. Decide on a name for your variable. Remember the rules.
  • 25. TO CREATE A VARIABLE 1. Decide what the data type should be. Usually the main decisions are between int, float and char. to create a float type float to create an int type int to create a char type char 2. Decide on a name for your variable. Remember the rules. float scale; int redValue; char finalMark;
  • 26. TO CREATE A VARIABLE 1. Decide what the data type should be. Usually the main decisions are between int, float and char. to create a float type float to create an int type int to create a char type char 2. Decide on a name for your variable. Remember the rules. float scale; you get to choose int redValue; the name char finalMark;
  • 27. TO CREATE A VARIABLE 1. Decide what the data type should be. Usually the main decisions are between int, float and char. to create a float type float to create an int type int to create a char type char 2. Decide on a name for your variable. Remember the rules. float scale; you get to choose int redValue; the name char finalMark; 3. If you already know what the value of that variable is, then go ahead and set the value.
  • 28. TO CREATE A VARIABLE 1. Decide what the data type should be. Usually the main decisions are between int, float and char. to create a float type float to create an int type int to create a char type char 2. Decide on a name for your variable. Remember the rules. float scale; you get to choose int redValue; the name char finalMark; 3. If you already know what the value of that variable is, then go ahead and set the value. float scale = 0.5; int redValue = 199; char finalMark = ‘B’;
  • 29. TO CREATE A VARIABLE 1. Decide what the data type should be. Usually the main decisions are between int, float and char. to create a float type float to create an int type int to create a char type char 2. Decide on a name for your variable. Remember the rules. float scale; you get to choose int redValue; the name char finalMark; 3. If you already know what the value of that variable is, then go ahead and set the value. if you don’t know the float scale = 0.5; value yet, stop at step 2. int redValue = 199; but remember to end char finalMark = ‘B’; each line with a ;
  • 30. EXERCISE In Processing, draw a purple quadrilateral using the quad( ) function. quad(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) Use variables to represent corner of the quadrilateral.
  • 32. int x0 = 20; int y0 = 20; int x1 = 30; int y1 = 50; int x2 = 150; int y2 = 50; int x3 = 160; int y3 = 20; size(200, 200); quad(x0, y0, x1, y1, x2, y2, x3, y3);
  • 33. int x0 = 20; int y0 = 20; int x1 = 30; int y1 = 50; this is a pain to keep track of int x2 = 150; int y2 = 50; int x3 = 160; int y3 = 20; size(200, 200); quad(x0, y0, x1, y1, x2, y2, x3, y3);
  • 34. int x0 = 20; int y0 = 20; int x1 = 30; int y1 = 50; this is a pain to keep track of int x2 = 150; int y2 = 50; int x3 = 160; Wouldn’t it be easier to just int y3 = 20; have two lists, so only two variable names: “x” and “y”? size(200, 200); quad(x0, y0, x1, y1, x2, y2, x3, y3);
  • 35. What if had a list And a list called X called Y X Y 0.) 20 0.) 20 1.) 30 1.) 50 2.)150 2.) 50 3.)160 3.) 20
  • 36. What if had a list And a list called X called Y X Y 0.) 20 0.) 20 1.) 30 1.) 50 2.)150 2.) 50 3.)160 3.) 20 So if we just want the number at 2.) in the X list, we’d type x[2]
  • 37. What if had a list And a list called X called Y X Y 0.) 20 0.) 20 That’s all an array is: 1.) 30 1.) 50 a list of things, where we don’t have to name each thing, just the list. 2.)150 2.) 50 3.)160 3.) 20 So if we just want the number at 2.) in the X list, we’d type x[2]
  • 38. To create a new list (to declare it): int[] x = new int[4];
  • 39. To create a new list (to declare it): what kind of things are in the list? i.e. how much space needs to be reserved for each item int[] x = new int[4];
  • 40. To create a new list (to declare it): what kind of things are in the list? i.e. how much space needs to be reserved for each item int[] x = new int[4]; [ ] means the data type is an array
  • 41. To create a new list (to declare it): what kind of things are in the list? i.e. how much space needs to be reserved for each item int[] x = new int[4]; [ ] means the data type is an array what is the name of the list?
  • 42. To create a new list (to declare it): 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? int[] x = new int[4]; [ ] means the data type is an array what is the name of the list?
  • 43. To initialise a new list : x[0] = 20; x[1] = 30; x[2] = 150; x[3] = 160;
  • 44. To initialise a new list : what list are you referring to? x[0] = 20; x[1] = 30; x[2] = 150; x[3] = 160;
  • 45. To initialise a new list : what list are you referring to? x[0] = 20; x[1] = 30; x[2] = 150; x[3] = 160; which item from the list?
  • 46. To initialise a new list : what list are you referring to? what is the value x[0] = 20; of that item? x[1] = 30; x[2] = 150; x[3] = 160; which item from the list?
  • 47. int[] x = new int[4]; x[0] x[1] x[2] x[3]
  • 48. what kind of things are in the list? i.e. how much space needs to be reserved for each item int[] x = new int[4]; x[0] x[1] x[2] x[3]
  • 49. 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? int[] x = new int[4]; x[0] x[1] x[2] x[3]
  • 50. 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? int[] x = new int[4]; x[0] x[1] the length of the array and the data type determine x[2] how much memory is used x[3]
  • 51. You can declare and initialise a new list at the same time : int[] x = {20, 30, 150, 160};
  • 52. You can declare and initialise a new list at the same time : what kind of things are in the list? i.e. how much space needs to be reserved for each item int[] x = {20, 30, 150, 160};
  • 53. You can declare and initialise a new list at the same time : what kind of things are in the list? i.e. how much space needs to be reserved for each item int[] x = {20, 30, 150, 160}; [ ] means the data type is an array
  • 54. You can declare and initialise a new list at the same time : what kind of things are in the list? i.e. how much space needs to be reserved for each item int[] x = {20, 30, 150, 160}; [ ] means the data type is an array what is the name of the list?
  • 55. You can declare and initialise a new list at the same time : what kind of things are in the list? i.e. how much space needs to be what is the value reserved for each item of each item? int[] x = {20, 30, 150, 160}; [ ] means the data type is an array what is the name of the list?
  • 56. EXERCISE In Processing, rewrite this code so that it uses two arrays. int x0 = 20; int y0 = 20; int x1 = 30; int y1 = 50; int x2 = 150; int y2 = 50; int x3 = 160; int y3 = 20; size(200, 200); quad(x0, y0, x1, y1, x2, y2, x3, y3);
  • 58. 2 tbsp olive oil or sun-dried tomato oil from the jar 1 tsp dried oregano or a small handful of fresh leaves, chopped 6 rashers of smoked streaky bacon, chopped 1 tsp dried thyme or a small handful of fresh leaves, chopped 2 large onions, chopped Drizzle balsamic vinegar 3 garlic cloves, crushed 12-14 sun-dried tomato halves, in oil 1kg/2¼lb lean minced beef Salt and freshly ground black pepper 2 large glasses of red wine A good handful of fresh basil leaves, torn 2x400g cans chopped tomatoes into small pieces 1x290g jar antipasti marinated 800g-1kg/1¾-2¼lb dried spaghetti mushrooms, drained Lots of freshly grated parmesan, to serve 2 fresh or dried bay leaves 1. Heat the oil in a large, heavy-based saucepan and fry the bacon until golden over a medium heat. Add the onions and garlic, frying until softened. Increase the heat and add the minced beef. Fry it until it has browned, breaking down any chunks of meat with a wooden spoon. Pour in the wine and boil until it has reduced in volume by about a third. Reduce the temperature and stir in the tomatoes, drained mushrooms, bay leaves, oregano, thyme and balsamic vinegar. 2. Either blitz the sun-dried tomatoes in a small blender with a little of the oil to loosen, or just finely chop before adding to the pan. Season well with salt and pepper. Cover with a lid and simmer the Bolognese sauce over a gentle heat for 1-1½ hours until it's rich and thickened, stirring occasionally. At the end of the cooking time, stir in the basil and add any extra seasoning if necessary. 3. Remove from the heat to 'settle' while you cook the spaghetti in plenty of boiling salted water (for the time stated on the packet). Drain and divide between warmed plates. Scatter a little parmesan over the spaghetti before adding a good ladleful of the Bolognese sauce, finishing with a scattering of more cheese and a twist of black http://www.bbc.co.uk/food/recipes/spaghettibolognese_67868
  • 59. 2 tbsp olive oil or sun-dried tomato oil from the jar 1 tsp dried oregano or a small handful of fresh leaves, chopped 6 rashers of smoked streaky bacon, chopped 1 tsp dried thyme or a small handful of fresh leaves, chopped 2 large onions, chopped Drizzle balsamic vinegar 3 garlic cloves, crushed 12-14 sun-dried tomato halves, in oil 1kg/2¼lb lean minced beef Salt and freshly ground black pepper 2 large glasses of red wine A good handful of fresh basil leaves, torn 2x400g cans chopped tomatoes into small pieces 1x290g jar antipasti marinated 800g-1kg/1¾-2¼lb dried spaghetti mushrooms, drained Lots of freshly grated parmesan, to serve 2 fresh or dried bay leaves 1. Heat the oil in a large, heavy-based saucepan and fry the bacon until golden over a medium heat. Add the onions and garlic, frying until softened. Increase the heat and add the minced beef. Fry it until it has browned, breaking down any chunks of meat with a wooden spoon. Pour in the wine and boil until it has reduced in volume by about a third. Reduce the temperature and stir in the tomatoes, drained mushrooms, bay leaves, oregano, thyme and balsamic vinegar. 2. Either blitz the sun-dried tomatoes in a small blender with a little of the oil to loosen, or just finely chop before adding to the pan. Season well with salt and pepper. Cover with a lid and simmer the Bolognese sauce over a gentle heat for 1-1½ hours until it's rich and thickened, stirring occasionally. At the end of the cooking time, stir in the basil and add any extra seasoning if necessary. 3. Remove from the heat to 'settle' while you cook the spaghetti in plenty of boiling salted water (for the time stated on the packet). Drain and divide between warmed plates. Scatter a little parmesan over the spaghetti before adding a good ladleful of the Bolognese sauce, finishing with a scattering of more cheese and a twist of black http://www.bbc.co.uk/food/recipes/spaghettibolognese_67868
  • 60. 2 tbsp olive oil or sun-dried tomato oil from the jar 1 tsp dried oregano or a small handful of fresh leaves, chopped 6 rashers of smoked streaky bacon, chopped 1 tsp dried thyme or a small handful of fresh leaves, chopped 2 large onions, chopped Drizzle balsamic vinegar 3 garlic cloves, crushed 12-14 sun-dried tomato halves, in oil 1kg/2¼lb lean minced beef Salt and freshly ground black pepper 2 large glasses of red wine A good handful of fresh basil leaves, torn 2x400g cans chopped tomatoes into small pieces 1x290g jar antipasti marinated 800g-1kg/1¾-2¼lb dried spaghetti mushrooms, drained Lots of freshly grated parmesan, to serve 2 fresh or dried bay leaves 1. Heat the oil in a large, heavy-based saucepan and fry the bacon until golden over a medium heat. Add the onions and garlic, frying until softened. Increase the heat and add the minced beef. Fry it until it has browned, breaking down any chunks of meat with a wooden spoon. Pour in the wine and boil until it has reduced in volume by about a third. Reduce the temperature and stir in the tomatoes, drained mushrooms, bay leaves, oregano, thyme and balsamic vinegar. 2. Either blitz the sun-dried tomatoes in a small blender with a little of the oil to loosen, or just finely chop before adding to the pan. Season well with salt and pepper. Cover with a lid and simmer the Bolognese sauce over a gentle heat for 1-1½ hours until it's rich and thickened, stirring occasionally. At the end of the cooking time, stir in the basil and add any extra seasoning if necessary. 3. Remove from the heat to 'settle' while you cook the spaghetti in plenty of boiling salted water (for the time stated on the packet). Drain and divide between warmed plates. Scatter a little parmesan over the spaghetti before adding a good ladleful of the Bolognese sauce, finishing with a scattering of more cheese and a twist of black http://www.bbc.co.uk/food/recipes/spaghettibolognese_67868
  • 61. 2 tbsp olive oil or sun-dried tomato oil from the jar 1 tsp dried oregano or a small handful of fresh leaves, chopped 6 rashers of smoked streaky bacon, We’ve covered how to create 1 tsp dried thyme or a small handful of chopped 2 large onions, chopped ingredients or variables. fresh leaves, chopped Drizzle balsamic vinegar 3 garlic cloves, crushed 12-14 sun-dried tomato halves, in oil 1kg/2¼lb lean minced beef Salt and freshly ground black pepper 2 large glasses of red wine A good handful of fresh basil leaves, torn 2x400g cans chopped tomatoes into small pieces 1x290g jar antipasti marinated 800g-1kg/1¾-2¼lb dried spaghetti mushrooms, drained Lots of freshly grated parmesan, to serve 2 fresh or dried bay leaves 1. Heat the oil in a large, heavy-based saucepan and fry the bacon until golden over a medium heat. Add the onions and garlic, frying until softened. Increase the heat and add the minced beef. Fry it until it has browned, breaking down any chunks of meat with a wooden spoon. Pour in the wine and boil until it has reduced in volume by about a third. Reduce the temperature and stir in the tomatoes, drained mushrooms, bay leaves, oregano, thyme and balsamic vinegar. 2. Either blitz the sun-dried tomatoes in a small blender with a little of the oil to loosen, or just finely chop before adding to the pan. Season well with salt and pepper. Cover with a lid and simmer the Bolognese sauce over a gentle heat for 1-1½ hours until it's rich and thickened, stirring occasionally. At the end of the cooking time, stir in the basil and add any extra seasoning if necessary. 3. Remove from the heat to 'settle' while you cook the spaghetti in plenty of boiling salted water (for the time stated on the packet). Drain and divide between warmed plates. Scatter a little parmesan over the spaghetti before adding a good ladleful of the Bolognese sauce, finishing with a scattering of more cheese and a twist of black http://www.bbc.co.uk/food/recipes/spaghettibolognese_67868
  • 62. 2 tbsp olive oil or sun-dried tomato oil from the jar 1 tsp dried oregano or a small handful of fresh leaves, chopped 6 rashers of smoked streaky bacon, We’ve covered how to create 1 tsp dried thyme or a small handful of chopped 2 large onions, chopped ingredients or variables. fresh leaves, chopped Drizzle balsamic vinegar 3 garlic cloves, crushed 12-14 sun-dried tomato halves, in oil 1kg/2¼lb lean minced beef Salt and freshly ground black pepper 2 large glasses of red wine A good handful of fresh basil leaves, torn 2x400g cans chopped tomatoes into small pieces 1x290g jar antipasti marinated 800g-1kg/1¾-2¼lb dried spaghetti mushrooms, drained Lots of freshly grated parmesan, to serve 2 fresh or dried bay leaves 1. Heat the oil in a large, heavy-based saucepan and fry the bacon until golden over a medium heat. Add the onions and garlic, frying until softened. Increase the heat and add the minced beef. Fry it until it has browned, breaking down any chunks of meat with a wooden spoon. Pour in the wine and boil until it has reduced in volume by about a third. Reduce the temperature and stir in the tomatoes, drained mushrooms, bay leaves, oregano, thyme and balsamic vinegar. Now onto the basics of 2. Either blitz the sun-dried tomatoes in a small blender with a little of the oil to loosen, or just finely chop how to use those variables. before adding to the pan. Season well with salt and pepper. Cover with a lid and simmer the Bolognese sauce over a gentle heat for 1-1½ hours until it's rich and thickened, stirring occasionally. At the end of the cooking time, stir in the basil and add any extra seasoning if necessary. 3. Remove from the heat to 'settle' while you cook the spaghetti in plenty of boiling salted water (for the time stated on the packet). Drain and divide between warmed plates. Scatter a little parmesan over the spaghetti before adding a good ladleful of the Bolognese sauce, finishing with a scattering of more cheese and a twist of black http://www.bbc.co.uk/food/recipes/spaghettibolognese_67868
  • 63. HOW TO MAKE A DECISION
  • 64. HOW TO MAKE A DECISION Once we have some variables, we want to do things with those variables. The most basic step is to compare those variables to something else. This is done with comparators - questions that can be answered yes or no (or true or false).
  • 65. HOW TO MAKE A DECISION Once we have some variables, we want to do things with those variables. The most basic step is to compare those variables to something else. This is done with comparators - questions that can be answered yes or no (or true or false). <
  • 66. HOW TO MAKE A DECISION Once we have some variables, we want to do things with those variables. The most basic step is to compare those variables to something else. This is done with comparators - questions that can be answered yes or no (or true or false). less than <
  • 67. HOW TO MAKE A DECISION Once we have some variables, we want to do things with those variables. The most basic step is to compare those variables to something else. This is done with comparators - questions that can be answered yes or no (or true or false). less than 7 < 4
  • 68. HOW TO MAKE A DECISION Once we have some variables, we want to do things with those variables. The most basic step is to compare those variables to something else. This is done with comparators - questions that can be answered yes or no (or true or false). less than 7 < 4 FALSE
  • 69. HOW TO MAKE A DECISION Once we have some variables, we want to do things with those variables. The most basic step is to compare those variables to something else. This is done with comparators - questions that can be answered yes or no (or true or false).
  • 70. HOW TO MAKE A DECISION Once we have some variables, we want to do things with those variables. The most basic step is to compare those variables to something else. This is done with comparators - questions that can be answered yes or no (or true or false). >
  • 71. HOW TO MAKE A DECISION Once we have some variables, we want to do things with those variables. The most basic step is to compare those variables to something else. This is done with comparators - questions that can be answered yes or no (or true or false). greater than >
  • 72. HOW TO MAKE A DECISION Once we have some variables, we want to do things with those variables. The most basic step is to compare those variables to something else. This is done with comparators - questions that can be answered yes or no (or true or false). greater than 7 > 4
  • 73. HOW TO MAKE A DECISION Once we have some variables, we want to do things with those variables. The most basic step is to compare those variables to something else. This is done with comparators - questions that can be answered yes or no (or true or false). greater than 7 > 4 TRUE
  • 74. OTHER COMPARISONS greater than or equal to equal to >= == less than or equal to not equal to <= All of these result != in true or false.
  • 76. put in a comparison statement (like < or >) if ( ) { } else { }
  • 77. put in a comparison statement (like < or >) if ( ) what to do if our comparison { statement is true } else { }
  • 78. put in a comparison statement (like < or >) if ( ) what to do if our comparison { statement is true } else { } what to do if our comparison statement is false
  • 79. put in a comparison statement (like < or >) if ( ) what to do if our comparison { statement is true } we don’t have to always have an else else { statement, sometimes you only care if the } statement is true what to do if our comparison statement is false
  • 80. If something is true, do an action.
  • 81. If something is true, do an action. If something isn’t true, instead do a different action.
  • 82. If something is true, do an action. If the potatoes are too lumpy, keep mashing. If something isn’t true, instead do a different action.
  • 83. If something is true, do an action. If the potatoes are too lumpy, keep mashing. If something isn’t true, instead do a different action. If the potatoes are not too lumpy, stop mashing.
  • 84. If something is true, do an action. If the potatoes are too lumpy, keep mashing. We don’t have to test this twice. We know if If something isn’t true, instead do a the potatoes are either different action. too lumpy or not too lumpy. If the potatoes are not too lumpy, stop mashing.
  • 85. A NOTE ON AXES When graphing information, we are used to numbers
  • 86. A NOTE ON AXES When graphing information, we are used to numbers increasing as we move right
  • 87. A NOTE ON AXES When graphing information, we are used to numbers and increasing as we move up increasing as we move right
  • 88. A NOTE ON AXES This is different to how numbers work with programming graphics.
  • 89. A NOTE ON AXES Numbers start in the upper left corner at the origin (0, 0) This is different to how numbers work with programming graphics.
  • 90. A NOTE ON AXES Numbers start in the upper left corner at the origin (0, 0) This is different to how numbers work with programming graphics. and increase as we move right
  • 91. A NOTE ON AXES Numbers start in the upper left corner at the origin (0, 0) This is different to how numbers and increase as we work with programming graphics. move down and increase as we move right
  • 92. EXERCISE Create a Processing sketch which draws a green circle if the mouse is in the top half of the window and changes the circle’s colour to red if the mouse in the bottom half of the window. Start with the code below. void setup() { // create the window size(400, 400); } void draw() { // set the colour fill(10, 10, 255); // draw the circle ellipse(mouseX, mouseY, 100, 100); }
  • 93. What if we want to use multiple if statements? int counter; // some other code... if (counter < 10) { if (counter > 0 ) { counter++; } }
  • 94. What if we want to use multiple if statements? If counter is less than 10 and greater than 0, then int counter; increase counter by 1. // some other code... if (counter < 10) { if (counter > 0 ) { counter++; } }
  • 95. What if we want to use multiple if statements? If counter is less than 10 and greater than 0, then int counter; increase counter by 1. // some other code... if (counter < 10) { if (counter > 0 ) { counter++; } } counter is only increased if both if statements are true.
  • 96. What if we want to use multiple if statements? If counter is less than 10 and greater than 0, then int counter; increase counter by 1. // some other code... if (counter < 10) { if (counter > 0 ) { counter++; } } counter is only increased if These are called nested if both if statements are true. statements, because one is inside the { } of the other.
  • 97. What if we want to use multiple if statements? int counter; // some other code... if (counter > 10) { counter = 0; } if (counter < 0 ) { } counter = 0; }
  • 98. What if we want to use multiple if statements? If counter is greater than 10 or less than 0, then reset counter to 0. int counter; // some other code... if (counter > 10) { counter = 0; } if (counter < 0 ) { } counter = 0; }
  • 99. What if we want to use multiple if statements? If counter is greater than 10 or less than 0, then reset counter to 0. int counter; // some other code... if (counter > 10) { counter = 0; } if (counter < 0 ) { } counter = 0; } counter is reset if either if statements are true.
  • 100. BOOLEAN OPERATOR OR True OR False is False OR True is True OR True is False OR False is
  • 101. BOOLEAN OPERATOR OR True OR False is True False OR True is True OR True is False OR False is
  • 102. BOOLEAN OPERATOR OR True OR False is True False OR True is True True OR True is False OR False is
  • 103. BOOLEAN OPERATOR OR True OR False is True False OR True is True True OR True is True False OR False is
  • 104. BOOLEAN OPERATOR OR True OR False is True False OR True is True True OR True is True False OR False is False
  • 105. BOOLEAN OPERATOR OR True OR False is True False OR True is True When using OR in code, type || True OR True is True False OR False is False
  • 106. BOOLEAN OPERATOR AND True AND False is False AND True is True AND True is False AND False is
  • 107. BOOLEAN OPERATOR AND True AND False is False False AND True is True AND True is False AND False is
  • 108. BOOLEAN OPERATOR AND True AND False is False False AND True is False True AND True is False AND False is
  • 109. BOOLEAN OPERATOR AND True AND False is False False AND True is False True AND True is True False AND False is
  • 110. BOOLEAN OPERATOR AND True AND False is False False AND True is False True AND True is True False AND False is False
  • 111. BOOLEAN OPERATOR AND True AND False is False False AND True is False When using OR in code, type && True AND True is True False AND False is False
  • 112. BOOLEAN OPERATOR NOT NOT True is NOT False is
  • 113. BOOLEAN OPERATOR NOT NOT True is False NOT False is
  • 114. BOOLEAN OPERATOR NOT NOT True is False NOT False is True
  • 115. BOOLEAN OPERATOR NOT NOT True is False NOT False is True When using NOT in code, type !
  • 116. EXERCISE Modify your Processing sketch which draws a green circle if the mouse is in the top half of the window and changes the circle’s colour to red if the mouse in the bottom half of the window. Now using the AND statement, draw • a green circle in the upper left quadrant of the window, • a blue circle in the upper right quadrant, • a red circle in the lower left quadrant, • and a yellow circle in the lower right quadrant.
  • 117. LOOPS
  • 118. LOOPS There are two ways to repeat something: 1. Do this N number of times. 2. Keep doing this until something else happens.
  • 119. LOOPS There are two ways to repeat something: Repeat this event in 1. Do this N the calendar of number this times. many times. 2. Keep doing this until something else happens.
  • 120. LOOPS There are two ways to repeat something: Repeat this event in 1. Do this N the calendar of number this times. many times. 2. Keep doing this event in the Repeat this until calendar until a certain something else occurs. date happens.
  • 121. DO THIS N TIMES int i; for(i=0; i<4; i++) { }
  • 122. DO THIS N TIMES start with a number, in this case 0 int i; for(i=0; i<4; i++) { }
  • 123. DO THIS N TIMES start with a number, in if this statement is this case 0 true int i; for(i=0; i<4; i++) { }
  • 124. DO THIS N TIMES start with a number, in if this statement is this case 0 true int i; for(i=0; i<4; i++) { } then do whatever is written here
  • 125. DO THIS N TIMES start with a number, in if this statement is this case 0 true int i; for(i=0; i<4; i++) { } when you’ve done what’s then do whatever is in the { } once, do this, in written here this case add make i equal to its current value plus 1
  • 126. DO THIS N TIMES start with a number, in if this statement is true go back to see if the this case 0 middle statement is still int i; true for(i=0; i<4; i++) { } when you’ve done what’s then do whatever is in the { } once, do this, in written here this case add make i equal to its current value plus 1
  • 127. KEEP DOING THIS UNTIL SOMETHING ELSE HAPPENS while ( ) { }
  • 128. KEEP DOING THIS UNTIL SOMETHING ELSE HAPPENS if the statement here is true while ( ) { }
  • 129. KEEP DOING THIS UNTIL SOMETHING ELSE HAPPENS if the statement here is true while ( ) { } then do what is between { } once
  • 130. KEEP DOING THIS UNTIL SOMETHING ELSE HAPPENS if the statement here is true while ( ) { then repeat by checking the statement again } then do what is between { } once
  • 131. EXERCISE Write out each iteration of these loops and what the variables equal at the end of each loop. int i; int j = 15; int k = 100; for (i=0; i<12; i++) while ( k > 0 ) { { k = k -10; j = j * 2 - i; } }