Download presentation
Presentation is loading. Please wait.
Published byAlexina Garrison Modified over 9 years ago
1
2D Graphics Basics Chapter 2
2
Bird’s Eye View Overview of Computer Graphics 2D Graphics: Basics –Basic 2D graphics, rendering pipeline, geometry, equations of primitives, and Java 2D programming 2D Graphics: Rendering Details 2D Graphics: Advanced topics 2
3
Objectives To understand the architecture and operations of a 2D graphics system To understand 2D coordinate systems and equations of graphs To be able to identify the various coordinate spaces in a rendering pipeline To understand Java 2D program structure and the Graphics2D object To graph equations with Java programs To use basic 2D geometric primitives To construct custom shapes using GeneralPath class To construct geometric shapes through constructive area geometry 3
4
Rendering Pipeline 1. Construct the 2D objects. 2. Apply transformations to the objects. 3. Apply color and other rendering properties. 4. Render the scene on a graphics device. 4
5
2D Coordinate System 5
6
Line 6
7
Ellipse 7
8
Parametric Equation 8 Parametric equation of an ellipse
9
Java 2D Coordinate System 9 y-axis pointing downward
10
The Graphics2D Class F Java 2D rendering engine F Extends the Graphics class F Encapsulates all rendering functions 10 void paintComponent(Graphics g){ } Graphics getGraphics()
11
Methods of Graphics Class 11 void setColor(Color c) void setFont(Font f) void setXORMode(Color c) void setPaintMode() void translate(int x, int y) void drawLine(int x1, int y1, int x2, int y2) void drawRect(int x1, int y1, int width, int height) void drawOval(int x1, int y1, int width, int height) void drawArc(int x1, int y1, int width, int height, int start, int arc) void drawRoundRect(int x1, int y1, int width, int height, int arcW, int arcH) void drawPolygon(int[] xPoints, int[] yPoints, int nPoints) void fillRect(int x1, int y1, int width, int height) void fillOval(int x1, int y1, int width, int height) void fillArc(int x1, int y1, int width, int height, int start, int arc) void fillRoundRect(int x1, int y1, int width, int height, int arcW, int arcH) void fillPolygon(int[] xPoints, int[] yPoints, int nPoints) void drawString(String str, int x, int y)
12
Methods of Graphics2D Class 12 void draw(Shape s) void fill(Shape s) void setTransform(AffineTransform Tx) void transform(AffineTransform Tx) void setPaint(Paint p) void setStroke(Stroke s) void clip(Shape s) void setComposite(Composite c) void addRenderingHints(Map hints)
13
A Simple Java 2D Program 13 Source public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D)g; g2.setColor(Color.blue); Ellipse2D e = new Ellipse2D.Double(-100, -50, 200, 100); AffineTransform tr = new AffineTransform(); tr.rotate(Math.PI / 6.0); Shape shape = tr.createTransformedShape(e); g2.translate(300,200); g2.scale(2,2); g2.draw(shape); g2.drawString("Hello 2D", 0, 0); }
14
Graphing a Spirograph 14 Source The parametric equation
15
The Shape Interface 15
16
Draw Shapes Line Rectangle Round rectangle Ellipse 16 Arc Quadratic curve Cubic curve Polygon Source
17
Constructive Area Geometry Set-theoretic operations –Intersect –Add –Subtract –Exclusive or 17 Source
18
GeneralPath Five segment types –SEG_MOVETO –SEG_LINETO –SEG_QUADTO –SEG_CUBICTO –SEG_CLOSE 18 GeneralPath methods –moveTo –lineTo –quadTo –curveTo –closePath
19
Winding Rules To determine interior regions Crossing number Even-odd rule Non-zero rule 19 Source
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.