15
LIZ RUTLEDGE [email protected] [email protected] cell phone: 415.828.4865 THE TEAL EDITION DAY 4 August 4, 2011

Bootcamp - Team TEAL - Day 4

Embed Size (px)

DESCRIPTION

Slides from in-class lecture

Citation preview

LIZ [email protected]@gmail.comcell phone: 415.828.4865

THE TEAL EDITION

DAY 4August 4, 2011

CODE bootcamp 2011

DAY 4 Tuesday, 4 Aug 2011

agenda.

Review:Homework+,-,*,%Data Types - String, int, floatVariables - assigning and good labelling practices

Learn:Drawing CurvesOperators - &&, ||, !=, ==, >Conditionals - if, and, or, random, noiseDisplaying text in the sketch window - PFont, Create/Load Font, text()PImage

Do: PsuedoCodeLogic for Ball Bounce

CODE bootcamp 2011

DAY 4 Tuesday, 4 Aug 2011

now wasn’t that fun?review.

homework:questions?let’s put that bad boy together

topics we covered yesterday:+,-,*,%Data Types - String, int, floatVariables - assigning and good labelling practices

CODE bootcamp 2011

DAY 4 Tuesday, 4 Aug 2011

like using the Illustrator pen tool...wearing a blindfold.curves.

Curves Example:http://www.openprocessing.org/visuals/?visualID=2124

CODE bootcamp 2011

DAY 4 Tuesday, 4 Aug 2011

the tool that allows you to do anything of any actual interest...tever.conditionals!

the operators:> greater than<= less than or equal to< less than== equality>= greater than or equal to!= inequality

what do they do?return a boolean value of whether or not the expression is in fact true

examples:println(3 > 5); // Prints what?

println(3 >= 5); // Prints what?

println(5 >= 3); // Prints what?

println(3 == 5); // Prints what?

println(5 == 5); // Prints what?

println(5 != 5); // Prints what?

CODE bootcamp 2011

DAY 4 Tuesday, 4 Aug 2011

if statements.

sample code:if (test) { statements}

examples:int x = 150;if (x > 100) { // If x is greater than 100, ellipse(50, 50, 36, 36); // draw this ellipse}if (x < 100) { // If x is less than 100 rect(35, 35, 30, 30); // draw this rectangle}line(20, 20, 80, 80);

1. The test must be an expression that resolves to true or false.

2. When the test expression evaluates to true, the code inside the brackets is run. If the expression is false, the code is ignored.

3. Code inside a set of braces is called a block.

CODE bootcamp 2011

DAY 4 Tuesday, 4 Aug 2011

adding complexity.if-else statements.

if (test) { statements;}else { statements 2;}

if (test) { statements;}else if (test2) { statements 2;}

= a tree diagram made of code.

else = execute only if first test is not met

else if = execute only if first test is not met AND second test IS met

CODE bootcamp 2011

DAY 4 Tuesday, 4 Aug 2011

sometimes one condition just isn’t enough.logical operators.

&& = AND

|| = OR

! = NOT

examples:int a = 10;int b = 20;

if ((a > 5) || (b < 30)) { line(20, 50, 80, 50); }// Will the code in the block run?

if ((a > 15) || (b < 30)) { ellipse(50, 50, 36, 36); }// Will the code in the block run?

CODE bootcamp 2011

DAY 4 Tuesday, 4 Aug 2011

the “NOT” operator.

The logical NOT operator is an exclamation mark. It inverts the logical value of the associated boolean variables. It changes true to false, and false to true. The logical NOT operator can be applied only to boolean variables.

examples:boolean b = true; // Assign true to bprintln(b); // Prints “true”println(!b); // Prints “false”println(!x); // ERROR! It’s only possible to ! a boolean variable

CODE bootcamp 2011

DAY 4 Tuesday, 4 Aug 2011

sometimes you just need some random values.random.

The random() function creates unpredictable values within the range specified by its parameters.random(high) => returns a random number between 0 and the high parameterrandom(low, high) => returns a random number between the low and the high parameter

examples:float f = random(5.2); // Assign f a float value from 0 to 5.2int i = random(5.2); // ERROR! Why?int j = int(random(0,5.2)); // Assign j an int value from 0 to 5println(j);

Use random sparingly and be conscious of the math and algorithm of a range of numbers, rather than choosing random. Often used for color...but hey, let’s make our ranges specific!

CODE bootcamp 2011

DAY 4 Tuesday, 4 Aug 2011

finally, something other than shapes!text and images!

PFont()

How to use it:createFont();loadFont();text();

PImage()How to use it:image();

CODE bootcamp 2011

DAY 4 Tuesday, 4 Aug 2011

organize your thoughts to make the coding part faster, easier and more accurate.pseudocode.

example:

if(stomach grumbling){ eat something, stupid!}else if (sleepy) { just go to bed;}else { keep watching tv like a lazy bum;}

CODE bootcamp 2011

DAY 4 Tuesday, 4 Aug 2011

more pseudocode.

example:if ((mouse position is in left half of canvas) AND (mouse position is in top half of canvas)) { draw a orange rectangle in top left quarter of screen;}

else { draw a yellow rectangle in bottom right quarter of screen;}

CODE bootcamp 2011

DAY 4 Tuesday, 4 Aug 2011

let’s try out our sweet new pseudocode skillz.a bouncing ball.

in-class activity: go over logic of a bouncing ball as a class.

CODE bootcamp 2011

DAY 4 Tuesday, 4 Aug 2011

optional subheading goes here.homework.

do:1) Write pseudocode for bouncing balls 2) Add label/text to drawing from the green painting tiles in an interesting way (i.e. not just a line of text in the middle of the screen)

extra credit:3) Write pseudocode for bouncing balls that respond realistically. Think the physics of a billards table.