SlideShare a Scribd company logo
1 of 16
Download to read offline
Introduction to Programming
Class 5
Paul Brebner
Exercises Revision
• Textbook
– Page 42ff
– Example 4.6 to 4.13
– Then go back to fruit bowl problem
– Save your fruit bowl problem to work on later
– Monday Robot 2 Page 49
• How far did you get?
– Who managed to get fruit bowl working?
– If you did keep working on it next time if you have
time – try “surreal” version
Today Chapter 5 textbook – mouse
• Page 51ff
// declare global variables
int anIntToRuleTheWorld = 1; // can be used anywhere
void setup() {
// do stuff once only
frameRate(60); // default frameRate
println(anIntToRuleTheWorld++);
}
void draw() {
// repeat forever
Println(“frame number “ + frameCount); // frameCount is global variable, incremented each time
draw runs
println(anIntToRuleTheWorld++);
}
mouse
• mouseX and mouseY are global variables for
current mouse position
• background(value) clears screen
• pmouseX and pmouseY – mouseX and
mouseY in the previous frame
• dist(x1,y1,x2,y2) – length of line from (x1,y1)
to (x2,y2)
dist(mouseX,mouseY,pmouseX,pmouseY) is speed
of the mouse
Mouse button
• mousePressed global variable
– Boolean so can only be true or false
– So don’t need the “==“
• if (mousePressed == true)
println(“button!”)
else println(“no button”);
• if (mousePressed)
println(“button!”)
else println(“no button”);
Mouse button – bugs
“=“ (assignment) is legal but...
• if (mousePressed = true)
println(“button!”)
else println(“no button”);
• if (mousePressed = false)
println(“button!”)
else println(“no button”);
Mouse buttons
if (mousePressed)
{
If (mouseButton == LEFT)
println(“Left button”);
else if (mouseButton == CENTER)
println(“Center button”);
else if (mouseButton == RIGHT)
println(“Right button”);
}
else println(“NO button”);
Mouse buttons – same as
if (mousePressed)
If (mouseButton == LEFT)
println(“Left button”);
else if (mouseButton == CENTER)
println(“Center button”);
else if (mouseButton == RIGHT)
println(“Right button”);
else println(“NO button”);
Mouse buttons – same as
if (mousePressed)
If (mouseButton == LEFT)
println(“Left button”);
else if (mouseButton == CENTER)
println(“Center button”);
else if (mouseButton == RIGHT)
println(“Right button”);
else println(“NO button”);
Mouse buttons – same as
if (mousePressed && mouseButton == LEFT)
println("Left button");
else if (mousePressed && mouseButton == CENTER)
println("Center button");
else if (mousePressed && mouseButton == RIGHT)
println("Right button");
else println(“NO button”);
Mouse buttons – same as???
Not sure – seems to be lag
if (mouseButton == LEFT)
println("Left button");
else if (mouseButton == CENTER)
println("Center button");
else if (mouseButton == RIGHT)
println("Right button");
else println(“NO button”);
switch statement – for lots of values
switch (mouseButton) // a variable
{
case LEFT: println("Left Button"); break;
case CENTER: println(“Center Button”); break;
case RIGHT: println("Right Button"); break;
default: println("No button"); break;
// default matches if none of the other case values match
(it’s a “catch all”)
}
// case X is true if (mouseButton == X)
// break exits the “block” (curly brackets) to here
// don’t need the last break as exits automatically
Keys and text
• keyPressed – global boolean variable, true or
false if key pressed or not
• key – global char variable remembers the last key
typed (until a new key is hit)
– Char is a single character ‘a’, ‘b’, ‘c’, ‘1’, ‘!’ etc
• “a” and a are not chars
– Some char values are not printable
• Need to check if CODED as follows
• if (key == CODED)
if (keyCode == LEFT) // check if left arrow pressed etc
• textSize(n) – sets font size (in pixels)
• text(char, x, y) – draws char at (x,y) location
Exercises
• Examples 5-1 etc
– Don’t worry about easing and map examples
– Leave Example 5-16 and 5-17 (boundaries) until
next time

More Related Content

More from Paul Brebner

Scaling Open Source Big Data Cloud Applications is Easy/Hard
Scaling Open Source Big Data Cloud Applications is Easy/HardScaling Open Source Big Data Cloud Applications is Easy/Hard
Scaling Open Source Big Data Cloud Applications is Easy/Hard
Paul Brebner
 
OPEN Talk: Scaling Open Source Big Data Cloud Applications is Easy/Hard
OPEN Talk: Scaling Open Source Big Data Cloud Applications is Easy/HardOPEN Talk: Scaling Open Source Big Data Cloud Applications is Easy/Hard
OPEN Talk: Scaling Open Source Big Data Cloud Applications is Easy/Hard
Paul Brebner
 
Melbourne Big Data Meetup Talk: Scaling a Real-Time Anomaly Detection Applica...
Melbourne Big Data Meetup Talk: Scaling a Real-Time Anomaly Detection Applica...Melbourne Big Data Meetup Talk: Scaling a Real-Time Anomaly Detection Applica...
Melbourne Big Data Meetup Talk: Scaling a Real-Time Anomaly Detection Applica...
Paul Brebner
 
Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...
Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...
Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...
Paul Brebner
 
ApacheCon2019 Talk: Kafka, Cassandra and Kubernetes at Scale – Real-time Ano...
ApacheCon2019 Talk: Kafka, Cassandra and Kubernetesat Scale – Real-time Ano...ApacheCon2019 Talk: Kafka, Cassandra and Kubernetesat Scale – Real-time Ano...
ApacheCon2019 Talk: Kafka, Cassandra and Kubernetes at Scale – Real-time Ano...
Paul Brebner
 
ApacheCon2019 Talk: Improving the Observability of Cassandra, Kafka and Kuber...
ApacheCon2019 Talk: Improving the Observability of Cassandra, Kafka and Kuber...ApacheCon2019 Talk: Improving the Observability of Cassandra, Kafka and Kuber...
ApacheCon2019 Talk: Improving the Observability of Cassandra, Kafka and Kuber...
Paul Brebner
 

More from Paul Brebner (20)

The Impact of Hardware and Software Version Changes on Apache Kafka Performan...
The Impact of Hardware and Software Version Changes on Apache Kafka Performan...The Impact of Hardware and Software Version Changes on Apache Kafka Performan...
The Impact of Hardware and Software Version Changes on Apache Kafka Performan...
 
Apache ZooKeeper and Apache Curator: Meet the Dining Philosophers
Apache ZooKeeper and Apache Curator: Meet the Dining PhilosophersApache ZooKeeper and Apache Curator: Meet the Dining Philosophers
Apache ZooKeeper and Apache Curator: Meet the Dining Philosophers
 
Spinning your Drones with Cadence Workflows and Apache Kafka
Spinning your Drones with Cadence Workflows and Apache KafkaSpinning your Drones with Cadence Workflows and Apache Kafka
Spinning your Drones with Cadence Workflows and Apache Kafka
 
Change Data Capture (CDC) With Kafka Connect® and the Debezium PostgreSQL Sou...
Change Data Capture (CDC) With Kafka Connect® and the Debezium PostgreSQL Sou...Change Data Capture (CDC) With Kafka Connect® and the Debezium PostgreSQL Sou...
Change Data Capture (CDC) With Kafka Connect® and the Debezium PostgreSQL Sou...
 
Scaling Open Source Big Data Cloud Applications is Easy/Hard
Scaling Open Source Big Data Cloud Applications is Easy/HardScaling Open Source Big Data Cloud Applications is Easy/Hard
Scaling Open Source Big Data Cloud Applications is Easy/Hard
 
OPEN Talk: Scaling Open Source Big Data Cloud Applications is Easy/Hard
OPEN Talk: Scaling Open Source Big Data Cloud Applications is Easy/HardOPEN Talk: Scaling Open Source Big Data Cloud Applications is Easy/Hard
OPEN Talk: Scaling Open Source Big Data Cloud Applications is Easy/Hard
 
A Visual Introduction to Apache Kafka
A Visual Introduction to Apache KafkaA Visual Introduction to Apache Kafka
A Visual Introduction to Apache Kafka
 
Massively Scalable Real-time Geospatial Anomaly Detection with Apache Kafka a...
Massively Scalable Real-time Geospatial Anomaly Detection with Apache Kafka a...Massively Scalable Real-time Geospatial Anomaly Detection with Apache Kafka a...
Massively Scalable Real-time Geospatial Anomaly Detection with Apache Kafka a...
 
Building a real-time data processing pipeline using Apache Kafka, Kafka Conne...
Building a real-time data processing pipeline using Apache Kafka, Kafka Conne...Building a real-time data processing pipeline using Apache Kafka, Kafka Conne...
Building a real-time data processing pipeline using Apache Kafka, Kafka Conne...
 
Grid Middleware – Principles, Practice and Potential
Grid Middleware – Principles, Practice and PotentialGrid Middleware – Principles, Practice and Potential
Grid Middleware – Principles, Practice and Potential
 
Grid middleware is easy to install, configure, secure, debug and manage acros...
Grid middleware is easy to install, configure, secure, debug and manage acros...Grid middleware is easy to install, configure, secure, debug and manage acros...
Grid middleware is easy to install, configure, secure, debug and manage acros...
 
Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...
Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...
Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...
 
Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...
Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...
Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...
 
Melbourne Big Data Meetup Talk: Scaling a Real-Time Anomaly Detection Applica...
Melbourne Big Data Meetup Talk: Scaling a Real-Time Anomaly Detection Applica...Melbourne Big Data Meetup Talk: Scaling a Real-Time Anomaly Detection Applica...
Melbourne Big Data Meetup Talk: Scaling a Real-Time Anomaly Detection Applica...
 
Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...
Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...
Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...
 
0b101000 years of computing: a personal timeline - decade "0", the 1980's
0b101000 years of computing: a personal timeline - decade "0", the 1980's0b101000 years of computing: a personal timeline - decade "0", the 1980's
0b101000 years of computing: a personal timeline - decade "0", the 1980's
 
ApacheCon Berlin 2019: Kongo:Building a Scalable Streaming IoT Application us...
ApacheCon Berlin 2019: Kongo:Building a Scalable Streaming IoT Application us...ApacheCon Berlin 2019: Kongo:Building a Scalable Streaming IoT Application us...
ApacheCon Berlin 2019: Kongo:Building a Scalable Streaming IoT Application us...
 
ApacheCon2019 Talk: Kafka, Cassandra and Kubernetes at Scale – Real-time Ano...
ApacheCon2019 Talk: Kafka, Cassandra and Kubernetesat Scale – Real-time Ano...ApacheCon2019 Talk: Kafka, Cassandra and Kubernetesat Scale – Real-time Ano...
ApacheCon2019 Talk: Kafka, Cassandra and Kubernetes at Scale – Real-time Ano...
 
ApacheCon2019 Talk: Improving the Observability of Cassandra, Kafka and Kuber...
ApacheCon2019 Talk: Improving the Observability of Cassandra, Kafka and Kuber...ApacheCon2019 Talk: Improving the Observability of Cassandra, Kafka and Kuber...
ApacheCon2019 Talk: Improving the Observability of Cassandra, Kafka and Kuber...
 
How to Improve the Observability of Apache Cassandra and Kafka applications...
How to Improve the Observability of Apache Cassandra and Kafka applications...How to Improve the Observability of Apache Cassandra and Kafka applications...
How to Improve the Observability of Apache Cassandra and Kafka applications...
 

Recently uploaded

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 

Recently uploaded (20)

80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 

Introduction to programming - class 5

  • 2. Exercises Revision • Textbook – Page 42ff – Example 4.6 to 4.13 – Then go back to fruit bowl problem – Save your fruit bowl problem to work on later – Monday Robot 2 Page 49 • How far did you get? – Who managed to get fruit bowl working? – If you did keep working on it next time if you have time – try “surreal” version
  • 3.
  • 4.
  • 5. Today Chapter 5 textbook – mouse • Page 51ff // declare global variables int anIntToRuleTheWorld = 1; // can be used anywhere void setup() { // do stuff once only frameRate(60); // default frameRate println(anIntToRuleTheWorld++); } void draw() { // repeat forever Println(“frame number “ + frameCount); // frameCount is global variable, incremented each time draw runs println(anIntToRuleTheWorld++); }
  • 6. mouse • mouseX and mouseY are global variables for current mouse position • background(value) clears screen • pmouseX and pmouseY – mouseX and mouseY in the previous frame • dist(x1,y1,x2,y2) – length of line from (x1,y1) to (x2,y2) dist(mouseX,mouseY,pmouseX,pmouseY) is speed of the mouse
  • 7. Mouse button • mousePressed global variable – Boolean so can only be true or false – So don’t need the “==“ • if (mousePressed == true) println(“button!”) else println(“no button”); • if (mousePressed) println(“button!”) else println(“no button”);
  • 8. Mouse button – bugs “=“ (assignment) is legal but... • if (mousePressed = true) println(“button!”) else println(“no button”); • if (mousePressed = false) println(“button!”) else println(“no button”);
  • 9. Mouse buttons if (mousePressed) { If (mouseButton == LEFT) println(“Left button”); else if (mouseButton == CENTER) println(“Center button”); else if (mouseButton == RIGHT) println(“Right button”); } else println(“NO button”);
  • 10. Mouse buttons – same as if (mousePressed) If (mouseButton == LEFT) println(“Left button”); else if (mouseButton == CENTER) println(“Center button”); else if (mouseButton == RIGHT) println(“Right button”); else println(“NO button”);
  • 11. Mouse buttons – same as if (mousePressed) If (mouseButton == LEFT) println(“Left button”); else if (mouseButton == CENTER) println(“Center button”); else if (mouseButton == RIGHT) println(“Right button”); else println(“NO button”);
  • 12. Mouse buttons – same as if (mousePressed && mouseButton == LEFT) println("Left button"); else if (mousePressed && mouseButton == CENTER) println("Center button"); else if (mousePressed && mouseButton == RIGHT) println("Right button"); else println(“NO button”);
  • 13. Mouse buttons – same as??? Not sure – seems to be lag if (mouseButton == LEFT) println("Left button"); else if (mouseButton == CENTER) println("Center button"); else if (mouseButton == RIGHT) println("Right button"); else println(“NO button”);
  • 14. switch statement – for lots of values switch (mouseButton) // a variable { case LEFT: println("Left Button"); break; case CENTER: println(“Center Button”); break; case RIGHT: println("Right Button"); break; default: println("No button"); break; // default matches if none of the other case values match (it’s a “catch all”) } // case X is true if (mouseButton == X) // break exits the “block” (curly brackets) to here // don’t need the last break as exits automatically
  • 15. Keys and text • keyPressed – global boolean variable, true or false if key pressed or not • key – global char variable remembers the last key typed (until a new key is hit) – Char is a single character ‘a’, ‘b’, ‘c’, ‘1’, ‘!’ etc • “a” and a are not chars – Some char values are not printable • Need to check if CODED as follows • if (key == CODED) if (keyCode == LEFT) // check if left arrow pressed etc • textSize(n) – sets font size (in pixels) • text(char, x, y) – draws char at (x,y) location
  • 16. Exercises • Examples 5-1 etc – Don’t worry about easing and map examples – Leave Example 5-16 and 5-17 (boundaries) until next time