intro to java & processing. review cs is about problem-solving cs is about problem-solving to...

17
Intro to Java & Intro to Java & Processing Processing

Upload: abraham-greer

Post on 29-Dec-2015

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Intro to Java & Processing. Review CS is about problem-solving CS is about problem-solving To write programs you must To write programs you must –Be able

Intro to Java & ProcessingIntro to Java & Processing

Page 2: Intro to Java & Processing. Review CS is about problem-solving CS is about problem-solving To write programs you must To write programs you must –Be able

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)

Page 3: Intro to Java & Processing. Review CS is about problem-solving CS is about problem-solving To write programs you must To write programs you must –Be able

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

Page 4: Intro to Java & Processing. Review CS is about problem-solving CS is about problem-solving To write programs you must To write programs you must –Be able

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…

Page 5: Intro to Java & Processing. Review CS is about problem-solving CS is about problem-solving To write programs you must To write programs you must –Be able

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

Page 6: Intro to Java & Processing. Review CS is about problem-solving CS is about problem-solving To write programs you must To write programs you must –Be able

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

Page 7: Intro to Java & Processing. Review CS is about problem-solving CS is about problem-solving To write programs you must To write programs you must –Be able

Computer GraphicsComputer Graphics

Page 8: Intro to Java & Processing. Review CS is about problem-solving CS is about problem-solving To write programs you must To write programs you must –Be able

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

Page 9: Intro to Java & Processing. Review CS is about problem-solving CS is about problem-solving To write programs you must To write programs you must –Be able

Processing commandsProcessing commands

• background(255,0,0);background(255,0,0);

• size(800,450);size(800,450);

Page 10: Intro to Java & Processing. Review CS is about problem-solving CS is about problem-solving To write programs you must To write programs you must –Be able

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.

Page 11: Intro to Java & Processing. Review CS is about problem-solving CS is about problem-solving To write programs you must To write programs you must –Be able

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.

Page 12: Intro to Java & Processing. Review CS is about problem-solving CS is about problem-solving To write programs you must To write programs you must –Be able

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);

Page 13: Intro to Java & Processing. Review CS is about problem-solving CS is about problem-solving To write programs you must To write programs you must –Be able

CommentsComments

• Don’t do too much without Don’t do too much without comments!comments!

• // - one line comment// - one line comment

• /* /* – paragraphparagraph

*/*/

Page 14: Intro to Java & Processing. Review CS is about problem-solving CS is about problem-solving To write programs you must To write programs you must –Be able

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;

Page 15: Intro to Java & Processing. Review CS is about problem-solving CS is about problem-solving To write programs you must To write programs you must –Be able

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

Page 16: Intro to Java & Processing. Review CS is about problem-solving CS is about problem-solving To write programs you must To write programs you must –Be able

There’s lots more…There’s lots more…

• You get a cheat sheet and the API!You get a cheat sheet and the API!

Page 17: Intro to Java & Processing. Review CS is about problem-solving CS is about problem-solving To write programs you must To write programs you must –Be able

PW0PW0

• Make a faceMake a face

• Turn it inTurn it in