Polygons, Transformations, and Arrays

Slides:



Advertisements
Similar presentations
18/2/00SEM107 - © Kamin & Reddy Class 7 - LineList - 1 Class 7 - Line Drawings  The LineList data type r Recursive methods to construct line drawings.
Advertisements

This terms course Last term we both worked on learning 2 things –Processing –The concepts of graphics etc. This term will focus more on the basic concepts.
Programming in Processing Taught by Ms. Madsen Assistants: Ms. Fischer and Ms. Yen Winsor School, 2/13/08.
A Quick Introduction to Processing
IAT 334 Lab 2 Computer Graphics: Rocket, PImage. June 4, 2010IAT 3342 Outline  Programming concepts –Programming Computer Graphics –Transformations –Methods.
Translate, Rotate, Matrix Pages Function Function Definition Calling a function Parameters Return type and return statement.
Translation and Rotation in 2D and 3D David Meredith Aalborg University.
FUNDAMENTALS OF PROGRAMMING SM1204 Semester A 2011.
, Fall 2006IAT 800 Lab 2: Polygons, Transformations, and Arrays.
IAT 800 Lecture 4. Sept 18, Fall 2006IAT 8002 Outline  Programming concepts –Methods –Classes  Talk about project 1  Reading: Read Chapters 1-4 of.
CS 206 Introduction to Computer Science II 10 / 26 / 2009 Instructor: Michael Eckmann.
13.2 Angles and Angle Measure
IAT 355 Lecture 4 Computer Graphics: Rocket. May 9, 2014IAT 3552 Outline  Programming concepts –Programming Computer Graphics –Transformations –Methods.
CSE 381 – Advanced Game Programming Basic 3D Graphics
Image Synthesis Rabie A. Ramadan, PhD 2. 2 Java OpenGL Using JOGL: Using JOGL: Wiki: You can download JOGL from.
Element. The element Used to dynamically draw graphics using javascript. Capable of drawing paths, circles, rectangles, text, and images.
Transforming Geometry Groundhog Day. Drawing Quads In a 300 by 200 window, draw two quads of different colors. Don’t show the grey grid.
5-Min Check Triangle ABC is reflected over X = -2 A’,-5,4 B’-1,6 C’ 3,6 What are the coordinates of the pre-image? A. 1,4 B. -3,6 C -7,6.
 Students will be able… › Identify reflections, rotations, and translations. › Graph transformations in the coordinate plane.
Graphics Matrices. Today’s Lecture Brought to you by the integer 6 and letter ‘K’; 2D and 3D points Matrices Rotations Translation Putting it all together.
Section 6.1 Notes Special Angles of the Unit Circle in degrees and radians.
CGDD 4003 THE MATH LECTURE (BOILED DOWN, YET LIGHTLY SALTED)
Basic 3D Concepts. Overview 1.Coordinate systems 2.Transformations 3.Projection 4.Rasterization.
Computation as an Expressive Medium Lab 2: Polygons, Transformations, and Arrays Evan.
Step One Draw a square on your paper. Step Two Beginning in the top left corner of the square, measure to the right about a half inch and place a dot.
______________________________________________________________________________________ SCHOOL OF INTERACTIVE ARTS + TECHNOLOGY [SIAT] |
FUNDAMENTALS OF PROGRAMMING SM1204 SEMESTER A 2012.
Honors Geometry.  We learned how to set up a polygon / vertex matrix  We learned how to add matrices  We learned how to multiply matrices.
Computation as an Expressive Medium Lab 2: Polygons, Transformations, and Arrays (Oh My) Micah.
In the last several lessons, you have described translations using coordinates. You have also developed strategies for determining where an object started.
Programming in Processing Taught by Ms. Madsen Assistants: Ms. Fischer and Ms. Yen Winsor School, 2/20/08.
The Unit Circle. Right now… Get a scissors, and one copy of each circle (blue, green, yellow, white). Sit down and take everything BUT that stuff & your.
12-3 Rotations Warm Up Lesson Presentation Lesson Quiz Holt Geometry.
ROTATIONS LESSON 30.
Interior Angle Measure Lesson and Questions
Animation and Flexboxes
Some of Chap 17.
Pixels, Colors and Shapes
- Introduction - Graphics Pipeline
Transforms.
Computer Graphics: Rocket, Java: Class
Summary of Properties of 3D Affine Transformations
ANGLE MEASURES PREACALCULUS LESSON 2 – 1.
Chapter 14, Translate & Rotate
11.4 Rotations 1/12/17.
Computer Graphics Index Buffers
LCC 6310 Computation as an Expressive Medium
Stacks A stack is a data structure that is similar in spirit to a pile of cafeteria trays. Think about the trays in the dining halls: when the dining staff.
Stacks Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Working with Text and Numbers in Java
Sprite Animation An exercise on filling circles and polygons to create the animated sprite used in ‘Pac Man’
Space and Shape.
Transformations for GCSE Maths
The YELLOW Face Lesson 5: The Yellow Face Lesson 5.
Projection in 3-D Glenn G. Chappell
Bellringer Work on the Warm Up Sheet NEED: Graphing Sheet Protractor.
Transformations for GCSE Maths
IAT 265 Lecture 2: Java Loops, Arrays Processing setup, draw, mouse Shapes Transformations, Push/Pop.
9.3: Rotations.
5-Min Check Triangle ABC is reflected over X = -2 A’,-5,4 B’-1,6
Translate, Rotate, Matrix
Animation Pages
Transformations for GCSE Maths
Computation as an Expressive Medium
Graphical Interface Commands
Lets shape up! Pages:
Transformations with Matrices
Objective Identify and draw rotations..
Lets shape up! Pages:
Presentation transcript:

Polygons, Transformations, and Arrays IAT 265 Polygons, Transformations, and Arrays May 12, 2016 IAT 265

Next Arrays Building Complex Shapes Translation and Rotation Pushing and Popping May 12, 2016 IAT 265

Arrays Arrays store lists of values Access items by index number May 12, 2016 IAT 265

Building Special Shapes The beginShape() and endShape() functions allow us to draw irregular shapes from any number of points we define. Many types of Shape: POINTS, LINES, TRIANGLES, TRIANGLE_STRIP, TRIANGLE_FAN, QUADS, QUAD_STRIP, POLYGON POLYGON will be the most useful. May 12, 2016 … IAT 265

Building Polygons beginShape( POLYGON ); vertex(x, y); Tells the program to start the polygon. vertex(x, y); Make as many calls to this as you have vertices in your polygon. endShape( CLOSE ); Finishes the shape, connecting the last vertex to the first vertex to close the polygon, then colors it with the current fill() color. May 12, 2016 IAT 265

Building Polygons beginShape(); vertex(10, 50); (starts a new polygon, and begins at point (10, 50).) May 12, 2016 IAT 265

Building Polygons vertex(20, 10); vertex(30, 40); vertex(80, 60); (adds 4 more points to the polygon, and connects them in the order they are called.) May 12, 2016 IAT 265

Building Polygons endShape(CLOSE); (connects the last point to the first point, and fills the polygon.) May 12, 2016 IAT 265

Let’s Use Arrays Let’s store the points that we’re drawing. int[] xvals = {10, 20, 30, 80, 40}; int[] yvals = {50, 10, 40, 60, 80}; beginShape(); for(int i = 0; i < xvals.length; i++) { vertex( xvals[i], yvals[i] ); } endShape(CLOSE); May 12, 2016 IAT 265

Arrays Use xvals and yvals arrays to draw the shape elsewhere beginShape(); for(int i = 0; i < xvals.length; i++) { vertex( xvals[i] +10, yvals[i] +10 ); } endShape(CLOSE); May 12, 2016 IAT 265

Not very general What if you wanted to move by some other value? What if you wanted multiple copies of the same shape? Need a general method of moving polygons of some given shape May 12, 2016 IAT 265

Translation Translation gives us another way of drawing in a new location. It in essence, moves the point (0, 0) in our window. (0, 0) beginShape(); for(int i = 0; i < xvals.length; i++) { vertex(xvals[i], yvals[i]); } endShape(CLOSE); May 12, 2016 IAT 265

Translation After the call to translate(), any drawing functions called will treat our new orange point as if it were (0, 0). (0, 0) translate( 10, 10 ); (10, 10) May 12, 2016 IAT 265

Translation Draw same polygon again Now located x+10, y+10 (0, 0) (10, 10) beginShape(); for(int i = 0; i < xvals.length; i++) { vertex(xvals[i], yvals[i]); } endShape(CLOSE); May 12, 2016 IAT 265

Rotation Much like Translation, Rotation moves our drawing space, so that we can draw at different angles. Most of the time, you’ll want to use Rotation in conjunction with Translation, because rotate() rotates the drawing window around the point (0, 0). May 12, 2016 IAT 265

Rotation Let’s look at an example without translation: (0, 0) rect(10, 10, 50, 50); May 12, 2016 IAT 265

Rotation Make a variable with the value for 45 degrees in Radians. (0, 0) float angle = radians(45); radians() takes an int or float degree value and returns a float radian value. May 12, 2016 IAT 265

Rotation Rotate our drawing canvas 45 degrees around the origin. (0, 0) rotate(angle); May 12, 2016 IAT 265

Rotation Draw the same square, now on our rotated coordinate system (0, 0) rect(10, 10, 50, 50); (We only get to see about half of our square, and it isn’t really rotated in any satisfactory way.) May 12, 2016 IAT 265

Rotation Let’s try this from the start, using translation. Where should we translate to? The point around which we want to rotate. So let’s try and rotate around the center of the square. This means moving the origin, and drawing the square around it. May 12, 2016 IAT 265

Rotation Let’s start with setting our rotation point: (0, 0) translate(35, 35); (35, 35) May 12, 2016 IAT 265

Rotation Now let’s draw a square with this point at its center. (0, 0) rect( -25, -25, 50, 50); (35, 35) May 12, 2016 IAT 265

Rotation Then let’s do the same rotate we did last time. (0, 0) float angle = radians(45); rotate(angle); (35, 35) May 12, 2016 IAT 265

Rotation Now when we draw the same square as before, it will have the same center point. (0, 0) float angle = radians(45); rotate(angle); (35, 35) May 12, 2016 IAT 265

Rotation Try applying rotation to your animations using draw(). What variable will you want to iterate to make a shape rotate over time? Try making a custom polygon rotate instead of a square. May 12, 2016 IAT 265

Wait! How do I get back to normal?! If you plan to do a lot of translations and rotations, it helps to know about the concepts of push and pop… (0, 0) (35, 35) (60, 15) I just want to go back to where I started before this! May 12, 2016 IAT 265

Pushing and Popping Pushing is a way to say: Popping is a way to say: “Remember this orientation!” pushMatrix(); Popping is a way to say: “Take me back to the way things once were!” popMatrix(); May 12, 2016 IAT 265

Push & Pop If we want to remember the original orientation… pushMatrix(); translate(35,35); rotate( radians(45) ); rect(-25,-25,50,50); popMatrix(); rect(-25,-25,50,50); (0, 0) (35, 35) You can push and pop as many times as you want. It’s like you’re writing an address for the way things were on a card, and putting it on a stack each time you push… and pop just takes the first card off the top of the stack. IAT 265

Stack pushMatrix() and popMatrix() control a stack A stack stores chunks of data like a stack of plates in a cafeteria Last-In, First-out (LIFO) The graphics matrix stack lets you pushMatrix(), draw stuff, popMatrix() Returns drawing to state before pushMatrix May 12, 2016 IAT 265

Stack Push A Push B Push C Pop -> yields C Pop -> yields B Pop -> yields A C B A Stack Base May 12, 2016 IAT 265

How is this useful? You don’t have to remember the math to reverse all the translations and rotations you’ve done! You can make spiral shapes, then go back to normal! You can make drawings with limbs! (You don’t want to have to calculate the angles of every finger, do you?) May 12, 2016 IAT 265

Review Arrays Drawing Polygons Translation and Rotation pushMatrix and popMatrix May 12, 2016 IAT 265