Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Bootcamp - Team TEAL - Day 5
1. TEA M TEAL
LIZ RUTLEDGE
DAY 5 rutle173@newschool.edu
August 5, 2011 esrutledge@gmail.com
2. agenda.
Review: Learn:
ALL THE THINGS! displaying an image file:
PImage
variables createImage()
how to declare them, when to loadImage()
use them image()
conditionals
making things move:
operators — &&, ||, !=, ==, >, <
background + draw() as animation tool
if-statements — if, else if, else
incrementing variables in the draw() loop
DAY 5
Tuesday, 5 Aug 2011
CODE
bootcamp 2011
3. homework part 1.
now wasn’t that fun?
displaying text homework:
questions?
let’s put that bad boy together
review:
PFont
loadFont()
createFont()
textFont()
text()
DAY 5
Tuesday, 5 Aug 2011
CODE
bootcamp 2011
4. images.
exactly the same as fonts. (because fonts
are just a collection of images.)
displaying an image file:
PImage
createImage()
loadImage()
image()
example:
PImage sweetPhoto; // declare the variable
sweetPhoto = loadImage(“sweet-photo.jpg”); // load the image into the variable
image(sweetPhoto, 0, 0); // place the image at point (0, 0) (top left)
DAY 5
Tuesday, 5 Aug 2011
CODE
bootcamp 2011
5. bouncing ball homework.
questions?
go over logic of a bouncing ball as a class.
DAY 5
Tuesday, 5 Aug 2011
CODE
bootcamp 2011
6. making things move.
the concepts.
using background() and the loop to simulate movement
the techniques.
incrementing with each loop
using conditional statements to change movement based on
certain criteria.
the syntax.
incrementing variables (++, - -, +=, -=):
ex: x = x+1 is equivalent to x += 1
DAY 5
Tuesday, 5 Aug 2011
CODE
bootcamp 2011
7. conditionals!
the tool that allows you to do anything of
any actual interest...
the operators: examples:
> greater than
println(3 > 5); // Prints what?
>= greater than or equal to
< less than println(5 >= 3); // Prints what?
<= less than or equal to println(5 == 5); // Prints what?
== equals
println(5 != 5); // Prints what?
!= does NOT equal
(hint: it’s either true or false!)
what do they do?
return a boolean value of whether or
not the expression is in fact true
DAY 5
Tuesday, 5 Aug 2011
CODE
bootcamp 2011
8. if statements.
1. The test must be an expression that resolves to true or false.
sample code: 2. When the test expression evaluates to true, the code inside the
if (test) { brackets is run. If the expression is false, the code is ignored.
statements 3. Code inside a set of braces is called a block.
}
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);
DAY 5
Tuesday, 5 Aug 2011
CODE
bootcamp 2011
9. if-else statements.
adding complexity.
= a tree diagram made of code.
if (test) {
statements;
}
else { else = execute only if first test
statements 2; is not met
}
if (test) {
statements;
}
else if (test2) { else if = execute only if first test is
statements 2; not met AND second test IS met
}
DAY 5
Tuesday, 5 Aug 2011
CODE
bootcamp 2011
10. logical operators.
sometimes one condition just
isn’t enough.
examples:
int a = 10;
int b = 20;
&& = AND if ((a > 5) || (b < 30)) {
line(20, 50, 80, 50);
|| = OR }
// Will the code in the block run?
! = NOT if ((a > 15) || (b < 30)) {
ellipse(50, 50, 36, 36);
}
// Will the code in the block run?
DAY 5
Tuesday, 5 Aug 2011
CODE
bootcamp 2011
11. 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 b
println(b); // Prints “true”
println(!b); // Prints “false”
println(!x); // ERROR! It’s only possible to ! a boolean variable
DAY 5
Tuesday, 5 Aug 2011
CODE
bootcamp 2011
12. homework.
do:
create a sketch with at least one bouncing ball using the logic and functions that
we’ve learned this week. include an image file and/or text in your sketch.
extra credit options:
use an image instead of a simple shape for the bouncing ball
include more than one ball in your sketch
extra extra credit options:
include rotation in your ball behavior
include realistic bouncing behavior (whether just collision behavior or gravity/
friction)
DAY 5
Tuesday, 5 Aug 2011
CODE
bootcamp 2011
13. final project.
final project:
create some kind of drawing tool, the less conventional the better
this weekend:
think about some ideas for your project—blue sky/crazy ideas are fine,
i can help you scale it down next week. it’s better to dream big and
translate great ideas into doable projects than to limit yourself from the
start.
DAY 5
Tuesday, 5 Aug 2011
CODE
bootcamp 2011