1 / 19

2D Graphics Basics

2D Graphics Basics. Chapter 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. Objectives.

orien
Download Presentation

2D Graphics Basics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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

  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

  4. Rendering Pipeline • Construct the 2D objects. • Apply transformations to the objects. • Apply color and other rendering properties. • Render the scene on a graphics device.

  5. 2D Coordinate System

  6. Line

  7. Ellipse

  8. Parametric Equation Parametric equation of an ellipse

  9. Java 2D Coordinate System y-axis pointing downward

  10. The Graphics2D Class • Java 2D rendering engine • Extends the Graphics class • Encapsulates all rendering functions void paintComponent(Graphics g){ } Graphics getGraphics()

  11. Methods of Graphics Class 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, intarcW, intarcH) void drawPolygon(int[] xPoints, int[] yPoints, intnPoints) 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, intarcW, intarcH) void fillPolygon(int[] xPoints, int[] yPoints, intnPoints) void drawString(String str, int x, int y)

  12. Methods of Graphics2D Class void draw(Shape s) void fill(Shape s) void setTransform(AffineTransformTx) void transform(AffineTransformTx) 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 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); AffineTransformtr = 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); } Source

  14. Graphing a Spirograph The parametric equation Source

  15. The Shape Interface

  16. Arc Quadratic curve Cubic curve Polygon Draw Shapes • Line • Rectangle • Round rectangle • Ellipse Source

  17. Constructive Area Geometry • Set-theoretic operations • Intersect • Add • Subtract • Exclusive or Source

  18. GeneralPath methods moveTo lineTo quadTo curveTo closePath GeneralPath • Five segment types • SEG_MOVETO • SEG_LINETO • SEG_QUADTO • SEG_CUBICTO • SEG_CLOSE

  19. Winding Rules • To determine interior regions • Crossing number • Even-odd rule • Non-zero rule Source

More Related