18
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

6. Conditionals I

Embed Size (px)

Citation preview

Page 1: 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

Page 2: 6. Conditionals I

Office Hours

• http://www.cise.ufl.edu/class/cap3032sp14/!

• Joseph: CSE 410, Mon/Wed, before class!

• Yifan: CSE 309, Thurs, 2:00pm–3:00pm

Page 3: 6. Conditionals I

CAP 3032

Quiz 1!Pixels, Processing, & Interaction

Page 4: 6. Conditionals I

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

Page 5: 6. Conditionals I

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”

Page 6: 6. Conditionals I

HSB Color Model

• Hue, Saturation, Brightness!

• The “non-default” color mode!

• HSV is close, but Processing won’t understand

Page 7: 6. Conditionals I

CAP 3032

Conditionals I

Page 8: 6. Conditionals I

Relational Operatorsboolean!! true or false!> greater than

< less than

>= greater than OR equal to

<= less than OR equal to

== equality

!= inequality

Page 9: 6. Conditionals I

If

if (boolean expression) {

// do this if it’s true

}

Page 10: 6. Conditionals I

If / Else

if (boolean expression) {

// do this if it’s true

} else {

// do this if it’s not true

}

Page 11: 6. Conditionals I

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

}

Page 12: 6. Conditionals I

== versus =

== ! ! Checks for equality!

x == 3

=! ! ! Assigns a value!

x = 3

Page 13: 6. Conditionals I

Demo!Weighted Probabilities

Page 14: 6. Conditionals I

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

Page 15: 6. Conditionals I
Page 16: 6. Conditionals I

Logical Operators

&& AND if (x == 3 && y == 3) {}

|| OR if (x == 3 || x == 4) {}

! NOT if (x != 3) {}

if (!keyPressed) {}

if (keyPressed) {}

Page 17: 6. Conditionals I

Demo!Collision Detection

Page 18: 6. Conditionals I

For next time…

• I will return your proposals on Monday !

• Read Shiffman, p. 70–80 (Conditionals II)!

• Will hand out Homework 1 on Friday