180 likes | 263 Views
Intro to Java & Processing. Review . CS is about problem-solving To write programs you must Be able to solve the problem yourself Be able to describe the solution to another Be able to describe the solution to the computer (programming). Programming.
E N D
Review • CS is about problem-solving • To write programs you must • Be able to solve the problem yourself • Be able to describe the solution to another • Be able to describe the solution to the computer (programming)
Programming • Programs: how to tell a computer what to do • Each line is a command to the computer • The computer is stupid, so you have to type everything in exactly • If you make a mistake, you get an error and have to fix it • In this class, we use a programming language called Java • Java is called an Object-Oriented language
About Programming • Java is Case-SENsITivE! • Punctuation matters • Spelling matters • File names matter • Spaces don’t matter much • Be careful! • Follow the examples…
The tool… • IDE: Integrated Development Environment • A Program that does it all together, and it’s PRETTY… • One IDE is Eclipse
Fun with Graphics • We use a Java library called Processing that makes graphics easy. • Just open a new Processing project and check out the src folder. • Pixels! • Color (RGB, 0-255, Additive model, think LIGHT!) • x,y value
How it works • 2 sections: setup & draw • Setup: stuff that happens when the window opens (once) • Draw: stuff that happens many times a second
Processing commands • background(255,0,0); • size(800,450);
Shapes • triangle(Ax,Ay,Bx,By,Cx,Cy); • rect(ULx, ULy, w, h); • ellipse(Cx,Cy,w,h); • What’s the difference in putting these in setup() vs draw()? Try it. • What’s the difference between drawing a rectangle then a triangle or the triangle then a rectangle? Try it.
Circles & Arcs • Angles done in radians & clockwise • You must put the smaller number before the larger number. AddTWO_PI if you need to to get a bigger number.
Shape Attributes • fill(R,G,B); • stroke(R,G,B); • noFill(); • noStroke(); • strokeWeight(n);
Comments • Don’t do too much without comments! • // - one line comment • /* • paragraph */
ERROR!! • Sometimes it just doesn’t work… • Types of errors: • Compiler error • No semicolon • public Class Program{ • Logic error • answer = 2+3; • “The anser is “ • Fatal or Runtime error • answer = 2/0;
And then what? • Fix the program, save it, recompile, re-execute until everything works • The error is often called a “bug” • Fixing it is called debugging
There’s lots more… • You get a cheat sheet and the API!
PW0 • Make a face • Turn it in