6. Conditionals I
-
Upload
joseph-murphy -
Category
Education
-
view
59 -
download
4
Transcript of 6. Conditionals I
From last time…• We talked about variables, random(), and casting!
• Please write a number from 1–5 on your proposal and turn it in!
! 1 – little/no prior programming experience!
! 5 – extensive prior programming experience
Office Hours
• http://www.cise.ufl.edu/class/cap3032sp14/!
• Joseph: CSE 410, Mon/Wed, before class!
• Yifan: CSE 309, Thurs, 2:00pm–3:00pm
CAP 3032
Quiz 1!Pixels, Processing, & Interaction
Stats• 38 students took the quiz!
• 91.3% average score!
• Just about 75% of the class was above average!
• Read my notes, answer key online
Pixel Grid Questions
Pg. 6
• The first grid row & column is 0!
• The upper left hand corner is the origin!
• The width & height are total, not “from center”
HSB Color Model
• Hue, Saturation, Brightness!
• The “non-default” color mode!
• HSV is close, but Processing won’t understand
CAP 3032
Conditionals I
Relational Operatorsboolean!! true or false!> greater than
< less than
>= greater than OR equal to
<= less than OR equal to
== equality
!= inequality
If
if (boolean expression) {
// do this if it’s true
}
If / Else
if (boolean expression) {
// do this if it’s true
} else {
// do this if it’s not true
}
If, Else If, Elseif (boolean expression A) {
// do this if A is true
} else if (boolean expression B) {
// do this if B is true
} else {
// do this if neither A nor B is true
}
== versus =
== ! ! Checks for equality!
x == 3
=! ! ! Assigns a value!
x = 3
Demo!Weighted Probabilities
constrain()• Takes three integer or float arguments!
• Returns an integer or float!
• constrain(amount, low, high);
• Great for color or size:!
! float redColor = constrain(290, 0, 255);
! redColor will be equal to 255
Logical Operators
&& AND if (x == 3 && y == 3) {}
|| OR if (x == 3 || x == 4) {}
! NOT if (x != 3) {}
if (!keyPressed) {}
if (keyPressed) {}
Demo!Collision Detection
For next time…
• I will return your proposals on Monday !
• Read Shiffman, p. 70–80 (Conditionals II)!
• Will hand out Homework 1 on Friday