2D Graphics Basics Chapter 2. Bird’s Eye View  Overview of Computer Graphics  2D Graphics: Basics –Basic 2D graphics, rendering pipeline, geometry,

Slides:



Advertisements
Similar presentations
IT300: Introduction to Computer Graphics
Advertisements

CHAPTER 20 CREATING SVG GRAPHICS. LEARNING OBJECTIVES How to embed a graphic stored within a.SVG file in an HTML page How to use the and tag pair to specify.
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 1 Chapter 2 2D Graphics: Basics.
Advanced Manufacturing Laboratory Department of Industrial Engineering Sharif University of Technology Session # 7.
CSC1401 Drawing in Java - 2. Reminder from last class How do you save your modified picture? String filename = …; Picture stevePicture = new Picture(filename);
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 14 Graphics.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 13 Graphics.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L01 (Chapter 13) Graphics.
Graphics Outline Graphical Coodinate Systems The Graphics Class Drawing Strings, Lines, Rectangles, and Ovals Drawing Polygons.
1 L38 Graphics and Java 2D™ (3). 2 OBJECTIVES In this chapter you will learn:  To understand graphics contexts and graphics objects.  To understand.
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 1 Chapter 2 2D Graphics: Basics F The architecture.
May 13, 1998CS102-02Lecture 7-2 The End of Graphics in Java CS Lecture 7-2 A picture's worth a thousand words.
Swing Graphics ● Empty Swing containers have no visual appearance except for a background color ● Every JComponent must have a paintComponent method that.
Java Concepts Chapter 2 – Graphical Applications Mr. Smith AP Computer Science A.
CS324e - Elements of Graphics and Visualization Java2D Graphics.
Basic 3D Graphics Chapter 5. Bird’s Eye View  Basic 3D Graphics –Basic concepts of 3D graphics, rendering pipeline, Java 3D programming, scene graph,
1 Review of COMPSCI 221  Chapters 1-11 in text  User Interfaces will be addressed as a take- home question.
Java On The Web Session 15. Memory Upload JAVA Applets Colors Fonts Drawing Methods Posting your Applet.
2D Graphics: Rendering Details
(C) 2010 Pearson Education, Inc. All rights reserved. Omer Boyaci.
Abstract Window Toolkit (AWT) The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include:  A rich set.
CompSci Graphics. CompSci The Plan  Hardware  Coordinate System  Built-in Shapes  User-defined Shapes  Sprites and Shapes  Making a.
Advanced User Interfaces with Java SD’98 - Session 3206 Ted Faison Faison Computing Inc.
Java Graphics Swing Graphics
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved COS240 Object-Oriented Languages.
J McQuillan SE204: 2004/2005: Lecture 4slide 1 The Graphics Class Used when we need to draw to the screen Two graphics classes –Graphics –Graphics2D.
-Sai Phalgun Tatavarthy. Outline What is a “Graphing Calculator”? Graphics, Graphics2D classes Methods of Graphics object Custom Painting The paintComponent()
2D Graphics: Advanced Topics Chapter 4. Bird’s Eye View  Overview of Computer Graphics  2D Graphics: Basics  2D Graphics: Rendering Details  2D Graphics:
Chapter 18 產生驗證碼. No Cache 防止在 JSP 或 SERVLET 中的輸出不被 BROWSER 保存在 CACHE 中.
CPS Today’s topics Java Applications Graphics Upcoming Review for Midterm Exam Reading Great Ideas, Chapters 5.
Creating Your Own Widgets CompSci 230 S Software Construction.
Agenda Java Coordinate Systems. Graphics Class. Drawing on Panels. Drawing Shapes.
Graphics basic 1. 2 Objectives Understand Java coordinate systems. Draw things using the methods in the Graphics class. Override the paintComponent method.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved COS240 O-O Languages AUBG,
עקרונות תכנות מונחה עצמים תרגול 6 - GUI. Outline  Game of Life  Painting.
Graphics and Java2D Chapter Java Coordinate System Origin is in _____________ corner –Behind title bar of window X values increase to the ________.
Georgia Institute of Technology Drawing in Java – part 3 Barb Ericson Georgia Institute of Technology September 2006.
CSI 3125, Preliminaries, page 1 Applet. CSI 3125, Preliminaries, page 2 Graphics Methods public abstract void drawString(String str, int x, int y): is.
CSI 3125, Preliminaries, page 1 AWT. CSI 3125, Preliminaries, page 2 AWT Java AWT (Abstract Windowing Toolkit) is an API to develop GUI or window-based.
Image Panel & Image Navigator. Review Graphics2D class for drawing shapes in a component – paintComponent(Graphics g) – Graphics2D g2 = (Graphics2D)g;
Lecture 15: Raster Graphics and Scan Conversion
CS Lecture 03 Drawing & Displaying Images Lynda Thomas
Getting Started with GUI Programming Chapter 10 CSCI 1302.
AWT Java AWT (Abstract Windowing Toolkit) is an API to develop GUI or window-based application in java. Java AWT components are platform-dependent i.e.
Advanced Java Screen Update Techniques SD’98 - Session 4406 Ted Faison Faison Computing Inc.
Basic Graphics 03/03/16 & 03/07/16 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
Projects: not limited to spec Error checking File filters Create multiple file formats Polygons Filled shapes Etc.
6.1 Coordinates The screen of a computer is a grid of little squares called pixels. The color of each pixel can be set individually, and drawing on the.
Georgia Institute of Technology Drawing in Java – part 2 Dr Usman Saeed Assistant Professor Faculty of Computing and Information Technology North Jeddah.
Barb Ericson Georgia Institute of Technology September 2005
Advanced AWT The Rendering Pipeline
Graphics Applets By Mr. Dave Clausen
12 Graphics and Java 2D™.
Lecture 5 Basic geometric objects
Creating Your Own Widgets
Java Graphics.
Java Graphics CS 2511.
Graphics.
Applets In Java Visit for more Learning Resources 1.
Graphics Applets By Mr. Dave Clausen
Today’s topics Java Applications Upcoming Reading Graphics
Java Applets.
Java Graphics The basic rendering mechanism is the drawing system that controls when and how programs can draw on a graphics component. When a component.
עקרונות תכנות מונחה עצמים
Points of intersection of linear graphs an quadratic graphs
Chapter 49 Java 2D.
Chapter 13 Graphics.
Barb Ericson Georgia Institute of Technology September 2005
Chapter 13 Graphics.
Presentation transcript:

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 2

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

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

2D Coordinate System 5

Line 6

Ellipse 7

Parametric Equation 8 Parametric equation of an ellipse

Java 2D Coordinate System 9 y-axis pointing downward

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

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)

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)

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

Graphing a Spirograph 14 Source The parametric equation

The Shape Interface 15

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

Constructive Area Geometry  Set-theoretic operations –Intersect –Add –Subtract –Exclusive or 17 Source

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

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