Computation as an Expressive MediumLab HoursWhat have you gone over?What will we go over?VariablesSlide 6More info on drawing primitivesJava Control FlowJava Control Flow: LoopingSlide 10Java Control Flow: While LoopsSlide 12Java Control Flow: For LoopsJava Control Flow: Nested LoopsSlide 15Slide 16Slide 17Slide 18Slide 19Slide 20Slide 21Slide 22Slide 23Slide 24The draw() functionSlide 26Slide 27Slide 28Slide 29The setup() functionTracking Mouse PositionReacting to Mouse ClicksThat’s It For Today!Computation as an Computation as an Expressive MediumExpressive MediumLab 1: Loops, Animation, and Lab 1: Loops, Animation, and Simple User InteractionSimple User InteractionJason AldermanJason Alderman*Slides blatantly stolen from Mayhew Seavey. Yoinks!*Slides blatantly stolen from Mayhew Seavey. Yoinks!Lab HoursLab HoursThanks for your responses! Thanks for your responses! I’ll send out an e-mail by the end of I’ll send out an e-mail by the end of the day with with lab hours.the day with with lab hours.And always feel free to e-mail me if And always feel free to e-mail me if you have questions. I’m at you have questions. I’m at [email protected]@mail.gatech.edu . . (If you forget, it’ll be on the whiteboard (If you forget, it’ll be on the whiteboard in here.)in here.)http://www.lcc.gatech.edu/~mateas/courses/LCC6310-Fall2005/Syllabus2005.htmlWhat have you gone over?What have you gone over?Window size and coordinate systemWindow size and coordinate systemCommenting codeCommenting codeVariablesVariablesDrawing primitivesDrawing primitivespointpointlinelinerectrectellipseellipsetriangletriangleprint() and println()print() and println()if(boolean){ do something }else{ do something} logicif(boolean){ do something }else{ do something} logic(0,0)xyWhat will we go over?What will we go over?Courseware!Courseware!Variables: A RecapVariables: A RecapDrawing primitives (more info)Drawing primitives (more info)Java Control Flow: LoopingJava Control Flow: LoopingThe Processing “draw()” looping The Processing “draw()” looping function for animationfunction for animationSimple mouse interactionSimple mouse interactionVariablesVariablesVariables are placeholders for your data.Variables are placeholders for your data.int i; // declares a new variable ii = 1; // assigns the value of 1 to the new variableint j = i + 1; // declares a new variable j, and assigns it to i + 1, which is 2.VariablesVariablesTwo main types: Primitives and ObjectsTwo main types: Primitives and ObjectsPrimitives:Primitives:BooleanBoolean, , CharChar, Byte, Short, , Byte, Short, IntInt, Long, , Long, FloatFloat, , DoubleDoubleObjects:Objects:Everything else. Everything else. Constructed with primitives as a base. For Constructed with primitives as a base. For example, a “String” object is a series of Char example, a “String” object is a series of Char variables.variables.More info on drawing More info on drawing primitivesprimitivesZooooom on over to the reference Zooooom on over to the reference pages…pages…Java Control FlowJava Control FlowIf-Then-Else: Conditional LogicIf-Then-Else: Conditional Logicint i = 5;if(i > 10) {save_the_kitten();}else if(i > 3) {throw_the_kitten();}else {paint_the_kitten();}Java Control Flow: LoopingJava Control Flow: LoopingWant to draw ten lines, evenly-Want to draw ten lines, evenly-spaced apart?spaced apart?line(10, 10, 10, 200);line(20, 10, 20, 200);line(30, 10, 30, 200);...This can get old, fast. Also would be tedious if you This can get old, fast. Also would be tedious if you wanted to change all of the lines to start 5 pixels wanted to change all of the lines to start 5 pixels higher, instead.higher, instead.Java Control Flow: LoopingJava Control Flow: LoopingWant to draw ten lines, evenly-Want to draw ten lines, evenly-spaced apart?spaced apart?line(10, 10, 10, 200);line(20, 10, 20, 200);line(30, 10, 30, 200);...This can get old, fast. Also would be tedious if you This can get old, fast. Also would be tedious if you wanted to change all of the lines to start 5 pixels wanted to change all of the lines to start 5 pixels higher, instead.higher, instead.What if we could run this What if we could run this same line of code multiple same line of code multiple times, only changing these times, only changing these two numbers?two numbers?Java Control Flow: While Java Control Flow: While LoopsLoopsHoly Toledo! We can! Let’s use a while loop!Holy Toledo! We can! Let’s use a while loop!line(10, 10, 10, 200);line(20, 10, 20, 200);line(30, 10, 30, 200);...int i = 10;while(i <= 100) { line(i, 10, i, 200); i = i + 10;}A while loop will run the code inside the brackets repeatedly A while loop will run the code inside the brackets repeatedly until the condition in the parentheses is false.until the condition in the parentheses is false.Java Control Flow: While Java Control Flow: While LoopsLoopsBe careful with loops. Make sure the Be careful with loops. Make sure the condition will eventually return false, or else condition will eventually return false, or else it will go forever.it will go forever.while(true) { ...}int i = 10;while(i > 0) { line(i, 10, i, 200); i = i + 10;}Both of these loops are valid, will compile, Both of these loops are valid, will compile, and run infinitely.and run infinitely.Java Control Flow: For LoopsJava Control Flow: For LoopsFor Loops are just like While loops, but a For Loops are just like While loops, but a bit more compact for simple incrementing, bit more compact for simple incrementing, like in our last example.like in our last example.These two loops are functionally the same:These two loops are functionally the same:int i = 10;while(i <= 100) { line(i, 10, i, 200); i += 10;}for(int i = 10; i <= 100; i += 10) { line(i, 10, i, 200);}(i += 10 is equivalent to i = i + 10)Java Control Flow: Nested Java Control Flow: Nested LoopsLoopsNesting of loops refers to putting one Nesting of loops refers to putting one loop inside the brackets of another.loop inside the brackets of another.for(int i = 10; i <= 100; i += 10) { for(int j = 10; j <= 100; j += 10) { point(i, j); }}What does this mean? It means that the inside What does this mean? It means that the inside loop will run all the way through, then loop will run all the way through, then ii will will increment, and the inside loop
View Full Document