Graphics.

Slides:



Advertisements
Similar presentations
The Three-Dimensional Coordinate System 11.1
Advertisements

Graphics Shapes. Setup for using graphics You have to import the graphics library You can use either “import graphics” or “from graphics import *” or.
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 1 Chapter 2 2D Graphics: Basics.
ENS 207 engineering graphics
The Cartesian Coordinate System
GUI and Swing, part 2 The illustrated edition. Scroll bars As we have previously seen, a JTextArea has a fixed size, but the amount of text that can be.
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.
1 Python Programming: An Introduction to Computer Science Chapter 3 Objects and Graphics.
Swing Graphics ● Empty Swing containers have no visual appearance except for a background color ● Every JComponent must have a paintComponent method that.
Polar Coordinates Definition, Conversions, and Integration.
Do Now - #18 on p.558 Graph the set of points whose polar coordinates satisfy the given equations and inequalities.
CS324e - Elements of Graphics and Visualization Java2D Graphics.
Copyright - Planchard 2012 History of Engineering Graphics Stephen H. Simmons TDR 200.
Interactive Input Methods & Graphical User Input
3D Objects Subject:T0934 / Multimedia Programming Foundation Session:12 Tahun:2009 Versi:1/0.
1 Graphical User Components (II) Outline JTextArea Creating a Customized Subclass of JPanel JPanel Subclass that Handles Its Own Events Windows: Additional.
1.00 Lecture 18 Geometric Transformations in the 2D API.
Chapter 15 Graphics and Java 2D™ Java How to Program, 8/e (C) 2010 Pearson Education, Inc. All rights reserved.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 28 - Java Graphics and Java2D Outline 28.1Introduction.
Chapter 28 - Java Graphics and Java2D Outline 28.1Introduction 28.2Graphics Contexts and Graphics Objects 28.3Color Control 28.4Font Control 28.5Drawing.
 Pearson Education, Inc. All rights reserved. 1 Ch 12 Graphics and Java 2D In this chapter you will learn:  To understand graphics contexts.
(C) 2010 Pearson Education, Inc. All rights reserved. Omer Boyaci.
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.
Geometric Modeling. Volumetric o Collection device obtains regular grid of measurement values Examples: CT, MRI, PET, Ultrasound o Values are interpreted/visualized.
2D Graphics Basics Chapter 2. Bird’s Eye View  Overview of Computer Graphics  2D Graphics: Basics –Basic 2D graphics, rendering pipeline, geometry,
Drawing and Filling Geometric Shapes. Java comes with more than just points and lines. Within the Graphics2D class, there are also methods for drawing.
INT 840E Computer graphics Introduction & Graphic’s Architecture.
Computer Graphics Chapter 6 Andreas Savva. 2 Interactive Graphics Graphics provides one of the most natural means of communicating with a computer. Interactive.
Digital Media Dr. Jim Rowan ITEC So far… We have compared bitmapped graphics and vector graphics We have discussed bitmapped images, some file formats.
Basic 3D Concepts. Overview 1.Coordinate systems 2.Transformations 3.Projection 4.Rasterization.
Introduction to Java Chapter 8 - Introduction to Java Graphics1 Chapter 8 Introduction to Java Graphics.
Graphics and Java2D Chapter Java Coordinate System Origin is in _____________ corner –Behind title bar of window X values increase to the ________.
Java Graphics Opening Discussion zWhat did we talk about last class? zDo you have any questions about the assignment? zOffset between class.
8.1 The Rectangular Coordinate System and Circles Part 2: Circles.
Digital Media Lecture 5: Vector Graphics Georgia Gwinnett College School of Science and Technology Dr. Jim Rowan.
Graphics in Java Opening Discussion zDo you have any questions about the quiz? zWhat did we talk about last class? zDo you have any questions.
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.
Computer Graphics CC416 Lecture 04: Bresenham Line Algorithm & Mid-point circle algorithm Dr. Manal Helal – Fall 2014.
IS502:M ULTIMEDIA D ESIGN FOR I NFORMATION S YSTEM D IGITAL S TILL I MAGES Presenter Name: Mahmood A.Moneim Supervised By: Prof. Hesham A.Hefny Winter.
8.1 The Rectangular Coordinate System and Circles Part 2: Circles.
10/20/2005week71 Graphics, mouse and mouse motion events, KeyEvent Agenda Classes in AWT for graphics Example java programs –Graphics –Mouse events –Mouse.
IS502:M ULTIMEDIA D ESIGN FOR I NFORMATION S YSTEM D IGITAL S TILL I MAGES Presenter Name: Mahmood A.Moneim Supervised By: Prof. Hesham A.Hefny Winter.
12 Graphics and Java 2D™.
Parametric equations Parametric equation: x and y expressed in terms of a parameter t, for example, A curve can be described by parametric equations x=x(t),
What is a Function Expression?
Java Graphics CS 2511.
Introduction to Geometry – Transformations and Constructions
Coordinate Reference Frames
Chapter 3 Drawing In the World.
Engineering Geometry Engineering geometry is the basic geometric elements and forms used in engineering design. Engineering and technical graphics are.
Basic Graphics Drawing Shapes 1.
Computer Graphics.
Interactive Input Methods & Graphical User Input
CSE 381 – Advanced Game Programming Terrain
Area & Riemann Sums Chapter 5.1
Digital Media Dr. Jim Rowan ITEC 2110.
topics object oriented design objects and classes properties
Interactive Input Methods & Graphical User Input
Geometry Equations of Circles.
POLAR COORDINATES Dr. Shildneck.
Coordinate Systems Dr. Midori Kitagawa.
The coordinate system Susan Ibach | Technical Evangelist
Straight Lines and Linear Functions
Mathematics for Computer Graphics
Area and Volume How to … Calculate the area of a square or rectangle
Mathematics for Computer Graphics
Presentation transcript:

Graphics

The Plan Hardware Coordinate System Built-in Shapes User-defined Shapes Sprites and Shapes Making a Sprite

Hardware Monitor Video Card Resolutions (640x480, 800x600, 1280x1024) Bit depth (8, 15, 16, 24, 32) Refresh rate (75-85 Hz) Video Card Assists monitor Optimizes graphics

Coordinate Systems Cartesian Polar Screen (Graphics) Java 2D (Graphics2D)

Coordinate Systems Cartesian y x Rectangular X increases to the right Y increases as you go up Origin typically at center Real valued y x

Coordinate Systems . Polar r r increases as distance from the origin increases theta increases in the counterclockwise direction grid lines make concentric circles and sectors Origin typically at center r is real valued theta is from 0 to 2*PI . r theta

Coordinate Systems Conversion between Cartesian and Polar [x, y] = [r*cos(theta), r*sin(theta)] r = sqrt(x*x+y*y) theta = acos(x/r) if y>0 theta = - acos(x/r) if y<=0 No need to memorize this, but you may see it in the code

Coordinate Systems Screen (Graphics) Rectangular X increases to the right Y increases as you go down Origin at upper left Non-negative integer valued x y

Coordinate Systems Java 2D (Graphics2D) Rectangular X increases to the right Y increases as you go down Origin at upper left Real valued (approximated) x y

Coordinate Systems Java2D to Screen conversion Simple – round the floating point to an integer (or just truncate) Screen to Java2D conversion None needed because integers are approximated by reals

Coordinate Systems Why use Java2D coordinate system? Smoother motion Integer values often need to be rounded which can lead to more calculation error Simpler to rotate and expand

Built-in Shapes In java.awt.geom package Ellipse2D.Double Rectangle2D.Double RoundRectangle2D.Double All constructed with (x, y, width, height) What about circles and squares?

User-defined Shapes Also in java.awt.geom GeneralPath Area Lines Curves Quadratic Cubic Can be transformed via AffineTransform Area Constructive Area Geometry Useful tool for finding intersections

Shapes All classes so far are all Shapes Can draw them using a Graphics2D Can get boundary information Can be used to make a Sprite…

Sprites and Shapes Sprites have Size Shape Orientation Location Color Optionally a Tracker

Making a Sprite How to make a Sprite: Extend Sprite In the constructor Call super() Make any Shape Call setShape(yourShape)

Making a Sprite How to make a Sprite: Extend Sprite In the constructor Call super() Make any Shape Call setShape(yourShape) package tipgame.game.test.sprite; import java.awt.geom.*; public class SquareSprite extends Sprite { public SquareSprite() super(); Rectangle2D.Double rectangle; rectangle=new Rectangle2D.Double(0, 0, 1, 1); setShape(rectangle); }

Making a Sprite See the video game engine web site for the source code examples that follow http://www.cs.duke.edu/~cjj1/professional/tipgame/

In the constructor of LightSprite: Making a Sprite In the constructor of LightSprite: super(); Area area=new Area(); Rectangle2D.Double box=new Rectangle2D.Double(0, 0, 0.2, 0.6); area.add(new Area(box)); Ellipse2D.Double circle=new Ellipse2D.Double(0.02, 0.02, 0.16, 0.16); area.subtract(new Area(circle)); circle=new Ellipse2D.Double(0.02, 0.22, 0.16, 0.16); circle=new Ellipse2D.Double(0.02, 0.42, 0.16, 0.16); setShape(area); What does this look like?

In the constructor of TriangleSprite: Making a Sprite In the constructor of TriangleSprite: super(); GeneralPath path=new GeneralPath(); path.moveTo(0.0f, 0.0f); path.lineTo(1.0f, (float)Math.sqrt(3)); path.lineTo(-1.0f, (float)Math.sqrt(3)); path.closePath(); setShape(path); How could you make a space ship shape?