2D Graphics. Shape Models, Drawing, Selection. CS d Graphics 1

Similar documents
2D Graphics. Shape Models, Drawing, Selection. CS d Graphics 1

Java 2D Graphics. Drawing Primitives, Affine Transformations, Scene Graphs, Hit Tests. Drawing Primitives 2/9/2014. Using it is simple.

Graphics Hit-testing. Shape Models Selecting Lines and Shapes. 2.7 Graphics Hit-testing 1

Graphics and Painting

Object-Oriented Programming Design. Topic : Graphics Programming GUI Part I

CIS 162 Project 1 Business Card Section 04 (Kurmas)

Affine Transformations. Transforming shape models Combining affine transformations Scene graphs, interactor trees Hit tests on transformed shapes

Graphics. Lecture 18 COP 3252 Summer June 6, 2017

Heavyweight with platform-specific widgets. AWT applications were limited to commonfunctionality that existed on all platforms.

public void paintcomponent(graphics g) { Graphics2D g2 = (Graphics2D)g;... }

Building Java Programs

Building Java Programs

Software System Components 1 Graphics

Java How to Program, 9/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Garfield AP CS. Graphics

Graphics programming. COM6516 Object Oriented Programming and Design Adam Funk (originally Kirill Bogdanov & Mark Stevenson)

Assignment 2. Application Development

G51PRG: Introduction to Programming Second semester Applets and graphics

Generating Vectors Overview

Using Graphics. Building Java Programs Supplement 3G

Building Java Programs

Topic 8 graphics. -mgrimes, Graphics problem report 134

Programmierpraktikum

Lecture 5: Java Graphics

Topic 8 Graphics. Margaret Hamilton

Building Java Programs

IT101. Graphical User Interface

Introduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008

Agenda. Programming Seminar. By: dr. Amal Khalifa. Coordinate systems Colors Fonts Drawing shapes Graphics2D API

Graphic User Interfaces. - GUI concepts - Swing - AWT

Lecture 3: Java Graphics & Events

Question 1. Show the steps that are involved in sorting the string SORTME using the quicksort algorithm given below.

Topic 9 More Graphics. Based on slides bu Marty Stepp and Stuart Reges from

Week 4 Part 2. Introduction to 2D Graphics & Java 2D

CS 201 Advanced Object-Oriented Programming Lab 1 - Improving Your Image Due: Feb. 3/4, 11:30 PM

Chapter 1 Introduction to Java

Java Programming. Computer Science 112

Graphic Interface Programming II Using Swing and OOP more advanced issues. Uppsala universitet

ICOM 4015 Advanced Programming Laboratory. Chapter 3 Introduction to Graphical Applications in Java using Swing

Programming Graphics (P1 2006/2007)

Graphics Transformations

AP CS Unit 12: Drawing and Mouse Events

User interfaces and Swing

TWO-DIMENSIONAL FIGURES

1. Create a map of the layer and attribute that needs to be queried

Overview. Java2D. Graphics in Java2D: Colour Images Fonts. The bigger picture of Java Graphics: Java Advanced Imaging (JAI) API Java3D

Dr. Hikmat A. M. AbdelJaber

COMP-202 Unit 10: Basics of GUI Programming (Non examinable) (Caveat: Dan is not an expert in GUI programming, so don't take this for gospel :) )

Packages: Putting Classes Together

Getting Started with Silo

Programming: You will have 6 files all need to be located in the dir. named PA4:

CompSci 230 S Programming Techniques. Basic GUI Components

Chapter 2 Using Objects

CSC 160 LAB 8-1 DIGITAL PICTURE FRAME. 1. Introduction

CP122 Computer Science I. Chapter 2: Using Objects

Exam: Applet, Graphics, Events: Mouse, Key, and Focus

We will start our journey into Processing with creating static images using commands available in Processing:

Topic Notes: Java and Objectdraw Basics

Java Coordinate System

CS/ENGRD 2110 SPRING Lecture 2: Objects and classes in Java

CSCI 201L Midterm Written Fall % of course grade

Introduction to Computer Science I

Class Meeting 05 (Lecture 04) Objectives for this class meeting. Conduct vote on basic style of game for class project

Solutions to Chapter Exercises. GUI Objects and Event-Driven Programming

ILLUSTRATOR. Introduction to Adobe Illustrator. You will;

Ai Adobe. Illustrator. Creative Cloud Beginner

AP CS Unit 11: Graphics and Events

Illustrator Domains 1-4: Getting to Know Your Workspace. Dreamweaver Domain 3

Chapter 24. Graphical Objects The GraphicalObject Class

CISC 1600 Lecture 3.1 Introduction to Processing

Output models Drawing Rasterization Color models

Paint Tutorial (Project #14a)

Final Examination Semester 2 / Year 2012

Reviewing OO Concepts

Windows and Events. created originally by Brian Bailey

Graphical User Interface (GUI)

CS 2110 Fall Instructions. 1 Installing the code. Homework 4 Paint Program. 0.1 Grading, Partners, Academic Integrity, Help

Phase 2: Due 05/02/18 The Gui now stores and displays a graph in response to user mouse clicks on the screen.

CSE 331. Model/View Separation and Observer Pattern

CSE wi Final Exam 3/12/18. Name UW ID#

Structural & Thermal Analysis Using the ANSYS Workbench Release 12.1 Environment

Graphical User Interfaces (GUIs)

UI Software Organization

Graphical User Interface (GUI)

Previously, we have seen GUI components, their relationships, containers, layout managers. Now we will see how to paint graphics on GUI components

CS 101 Computer Science I Fall Instructor Muller. stddraw API. (DRAFT of 1/15/2013)

Programming graphics

Word 2007: Flowcharts Learning guide

Software Paradigms (Lesson 3) Object-Oriented Paradigm (2)

Lecture 7 A First Graphic Program And Data Structures & Drawing

CSCI 201L Midterm Written SOLUTION Fall % of course grade

CSE115 Lab 4 Fall 2016

8/23/2011. Chapter Goals

2/9/2012. Chapter Two: Using Objects. Chapter Goals

SAZ4A/SAE4A/BPC41 PROGRAMMING IN JAVA Unit : I - V

+! Today. Lecture 3: ArrayList & Standard Java Graphics 1/26/14! n Reading. n Objectives. n Reminders. n Standard Java Graphics (on course webpage)

Chapter 14: Applets and More

8/23/2014. Chapter Topics. Introduction to Applets. Introduction to Applets. Introduction to Applets. Applet Limitations. Chapter 14: Applets and More

1.00/1.001 Introduction to Computers and Engineering Problem Solving Spring Quiz 2

SHAPES & TRANSFORMS. Chapter 12 of Pro WPF : By Matthew MacDonald Assist Lect. Wadhah R. Baiee. College of IT Univ.

Transcription:

2D Graphics Shape Models, Drawing, Selection 1

Graphic Models vs. Images Computer Graphics: the creation, storage, and manipulation of images and their models Model: a mathematical representation of an image containing the important properties of an object (location, size, orientation, color, texture, etc.) in data structures Rendering: Using the properties of the model to create an image to display on the screen Image: the rendered model Model Rendering Image 2

Example Shape Models A shape model is a type of model that includes all of the data that we need to draw a particular shape. An array of points: {P1, P2,, Pn Can be open, closed, filled Includes any other data that we need to draw Allows for reuse of shape models in code Java supports primitive shapes (Lines, Ellipses, Rectangles) with tools for building others (CubicCurves, Paths, drawpolygon, drawpolyline, fillpolygon) 3

Example Shape Models We can also think of widgets as shape models Consist of an array of points {P1, P2,, Pn Properties describing how to draw it e.g. Button Points (0,0), (10,0), (5,0), (10,5) Properties Text: OK Border width: 1 pixel Border color: blue 0,5 10,5 OK 5 0,0 10,0 10 4

Typical Interaction What do we need to support interaction with user interfaces? Ability to draw shapes/widgets on the screen at specified position, size, orientation perhaps draw many copies, each different from the others Ability to test when a shape/widget is selected or clicked could be a filled or outlined polygon or a polyline selections that just miss the shape should snap to shape Programmer tasks: create a model of the shape draw it choose a selection paradigm implement shape hit tests and/or inside tests (with snapping) respond to events Now: what we did in X, in Java Next: 2D transformations 5

SimpleDraw: Drawing in Java package twod_graphics; import javax.swing.*; import java.awt.*; import java.awt.geom.path2d; public class SimpleDraw { public static void main(string[] args) { JFrame f = new JFrame("SimpleDraw"); // jframe is the window f.setdefaultcloseoperation(jframe.exit_on_close); f.setsize(400, 400); // window size f.setcontentpane(new Canvas()); // add canvas to jframe f.setvisible(true); // show the window // JComponent is a base class for custom components class Canvas extends JComponent { // custom graphics drawing public void paintcomponent(graphics g) { 6

SimpleDraw: Drawing in Java package twod_graphics; import javax.swing.*; import java.awt.*; import java.awt.geom.path2d; public class SimpleDraw { // JComponent is a base class for custom components class Canvas extends JComponent { // custom graphics drawing public void paintcomponent(graphics g) { super.paintcomponent(g); Graphics2D g2 = (Graphics2D) g; g2.setstroke(new BasicStroke(32)); g2.setcolor(color.blue); g2.drawline(0, 0, getwidth(), getheight()); // draw line g2.setcolor(color.red); g2.drawline(getwidth(), 0, 0, getheight()); g2.setcolor(color.black); g2.setstroke(new BasicStroke(1)); g2.draw(new Star()); // cast to get 2D drawing funcs // 32 pixel thick stroke // make it blue 7

SimpleDraw: Drawing in Java package twod_graphics; import javax.swing.*; import java.awt.*; import java.awt.geom.path2d; public class SimpleDraw { class Canvas extends JComponent { class Star extends Path2D.Double { public Star() { super(wind_even_odd); this.moveto(0, 0); this.lineto(-1.5, 5); this.lineto(-7, 5); this.lineto(-2.5, 8); this.lineto(-4.2, 13); this.lineto(0, 10); this.lineto(4.2, 13); this.lineto(2.5, 8); this.lineto(7, 5); this.lineto(1.5, 5); this.lineto(0, 0); How do you get the star where you want it and the size you want? 8

Selection Paradigms Users need to be able to interact with drawn shapes. e.g. Selecting or manipulating drawings Interaction with widgets Approach that we ll use Click selection Works differently for lines vs. closed shapes Example of each Alternate approaches not covered Rubberband rectangle Lasso (e.g. Chapter 14 of Olsen) 9

Closest Shape to Mouse Test Check distance from every line segment of every shape to mouse position (can be optimized ) Check distance from mouse to line segment using vector projection ClosestPointDemo.java 10 http://en.wikipedia.org/wiki/distance_from_a_point_to_a_line

NOTE ON ClosestPointDemo EXAMPLE The ClosestPointDemo example will NOT RUN ON YOUR MACHINE USING THE STANDARD INSTALL!!!! Need vecmath.jar Download it online, place it in your directory, and use the cp command line switch to include it Or try installing java3d ymmv. javac -cp vecmath.jar ClosestPointDemo.java java cp.;vecmath.jar ClosestPointDemo NOTE THE.; IN THE SECOND COMMAND The makefile included the samples will build and run it properly 11

Distance from Line to Point TestLine.java 12

Simplest : Selection of regular shapes The easiest thing to detect is a selection within a regular, closed shape. e.g. imagine that these are widgets, and the mouse is clicked at point (x,y) 0,0 100,0 0, 50 100, 50 Point (x, y) is contained within the circular region if: distance (center, point) < d Point (x, y) is contained within the rectangular region if: 0 < x < 100 and 0 < y < 50 d 13

Harder: Selection of arbitrary shapes Polygons are harder. Is a point inside or outside a polygon? P4 P1 P2 See Polygon class in java.awt See TestClick.java P3 14