Introductory Graphics Chapter Three
Computer Graphics §Full motion pictures (“Star Wars”) l animated films §Virtual reality §Games §Simulators (air craft etc.)
“A first Picture” §import java.awt.*; §import java.applet.Applet; §public class FirstLine extends Applet { l public void paint (Graphics g) { g.drawLine (0,0,100,100); }
Alter old HTML or Write New One §<applet “code = FirstLine.class” l can use same width and height…..> 0,0 0, ,0 100, ,330 START ENDING G.drawLine(0,0,100,100);
g.drawLine(0,0,100,100) “parameters” §doSomething( ); No parameters
The Paint Method §“Signiture Line” l public void paint (Graphics g) { security return Method name type Variable name
§Security = who can “see” modify method §void = return “nothing” this time… §paint = name of method (could be anything) §(Graphics = type variable g = name of particular variable) { begin/start of content of method
Methods for Drawing §Rectangles, ovals, arcs, polygons l 3D rectangles l filled shapes l polygons l rounded corners §drawArc( ) or drawOval, Rect,Line
drawArc ( 6 parameters) §X position §Y position §Width §Height §Starting point (360 degree of Clock) §Total Angle of Arc
0 degree (3:00 o’clock position 90 degree (12:00 o’clock) degree or 6:00 o’clock position 100,200,200,150,180,90 G.drawArc() 90
COLORS STANDARD 13 §256 * 256 * 256 (Lots of possible) l blackbluecyan darkgray l graygreenlightgray magenta l orangepinkredwhite l yellow
§ g.setBackground(Color.lightgray) ; §g.setColor.red; l SOLID FIGURES §fillRect §fillArc §fillOval
Sequence of “Graphics” Applet §Import java.awt.*; §import java applet.Applet; l public class FirstShapes extends Applet { public void paint (Graphics g) { g.drawRect (30,30,80,40); g.drawOval(120,30,50,50); setColor(Color.black); fillRect(30,100,80,40);
§drawLine (30,160,130,170); §drawArc (30,180,50,50,60,40); §fillArc(120,180,50,50,60,40); §} }
Add some text… §G.drawString (“ Hello World “, 30, 40); Horizontal X Y position
Concatenation + operator §G.drawString(“Hi” + “There” + “Mike”,100,100);
Comments (Types) §// single line comments §/* This is l an example of a multi line comment */ l /** Special JDK comment used for manuals not in J++ JBuilder */
Some comments are required for this class (All programs) §Your name §What function of program §The course you are in §Other comments as needed to help explain logic of program OR add needed detail l // draws a stickman // head //legs //arms