intro to java & processing. review cs is about problem-solving cs is about problem-solving to...
TRANSCRIPT
Intro to Java & ProcessingIntro to Java & Processing
ReviewReview
• CS is about problem-solvingCS is about problem-solving
• To write programs you must To write programs you must – Be able to solve the problem yourselfBe able to solve the problem yourself– Be able to describe the solution to Be able to describe the solution to
anotheranother– Be able to describe the solution to the Be able to describe the solution to the
computer (programming)computer (programming)
ProgrammingProgramming• Programs: how to tell a computer what to Programs: how to tell a computer what to
dodo– Each line is a command to the computerEach line is a command to the computer– The computer is stupid, so you have to type The computer is stupid, so you have to type
everything in exactly everything in exactly – If you make a mistake, you get an error and If you make a mistake, you get an error and
have to fix ithave to fix it
• In this class, we use a programming In this class, we use a programming language called Javalanguage called Java– Java is called an Object-Oriented languageJava is called an Object-Oriented language
About ProgrammingAbout Programming
• Java is Case-SENsITivE!Java is Case-SENsITivE!
• Punctuation mattersPunctuation matters
• Spelling mattersSpelling matters
• File names matterFile names matter
• Spaces donSpaces don’’t matter mucht matter much
• Be careful!Be careful!
• Follow the examples…Follow the examples…
The tool…The tool…
• IDE: Integrated Development IDE: Integrated Development EnvironmentEnvironment
• A Program that does it all together, A Program that does it all together, and itand it’’s PRETTY…s PRETTY…
• One IDE is EclipseOne IDE is Eclipse
Fun with GraphicsFun with Graphics
• We use a Java library called We use a Java library called Processing that makes graphics easy.Processing that makes graphics easy.
• Just open a new Processing project Just open a new Processing project and check out the src folder.and check out the src folder.
• Pixels!Pixels!– Color (RGB, 0-255, Additive model, think Color (RGB, 0-255, Additive model, think
LIGHT!)LIGHT!)– x,y valuex,y value
Computer GraphicsComputer Graphics
How it worksHow it works
• 2 sections: setup & draw2 sections: setup & draw
• Setup: stuff that happens when the Setup: stuff that happens when the window opens (once)window opens (once)
• Draw: stuff that happens many times Draw: stuff that happens many times a seconda second
Processing commandsProcessing commands
• background(255,0,0);background(255,0,0);
• size(800,450);size(800,450);
ShapesShapes
• triangle(Ax,Ay,Bx,By,Cx,Cy);triangle(Ax,Ay,Bx,By,Cx,Cy);
• rect(ULx, ULy, w, h);rect(ULx, ULy, w, h);
• ellipse(Cx,Cy,w,h);ellipse(Cx,Cy,w,h);
• What’s the difference in putting these in What’s the difference in putting these in setup() vs draw()? Try it.setup() vs draw()? Try it.
• What’s the difference between drawing What’s the difference between drawing a rectangle then a triangle or the a rectangle then a triangle or the triangle then a rectangle? Try it.triangle then a rectangle? Try it.
Circles & ArcsCircles & Arcs• Angles done in radians & clockwiseAngles done in radians & clockwise
• You must put the smaller number You must put the smaller number before the larger number. Add before the larger number. Add TWO_PI if you need to to get a bigger TWO_PI if you need to to get a bigger number.number.
Shape AttributesShape Attributes
• fill(R,G,B);fill(R,G,B);
• stroke(R,G,B);stroke(R,G,B);
• noFill();noFill();
• noStroke();noStroke();
• strokeWeight(n);strokeWeight(n);
CommentsComments
• Don’t do too much without Don’t do too much without comments!comments!
• // - one line comment// - one line comment
• /* /* – paragraphparagraph
*/*/
ERROR!!ERROR!!• Sometimes it just doesnSometimes it just doesn’’t work…t work…• Types of errors:Types of errors:
– Compiler errorCompiler error•No semicolonNo semicolon•public Class Program{public Class Program{
– Logic errorLogic error•answer = 2+3;answer = 2+3;•““The anser is The anser is ““
– Fatal or Runtime errorFatal or Runtime error•answer = 2/0;answer = 2/0;
And then what?And then what?
• Fix the program, save it, recompile, Fix the program, save it, recompile, re-execute until everything worksre-execute until everything works
• The error is often called a The error is often called a ““bugbug””• Fixing it is called debuggingFixing it is called debugging
There’s lots more…There’s lots more…
• You get a cheat sheet and the API!You get a cheat sheet and the API!
PW0PW0
• Make a faceMake a face
• Turn it inTurn it in