DOC PREVIEW
GT LCC 6310 - Computation as an Expressive Medium

This preview shows page 1-2-3-4-5-6 out of 19 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

LCC 6310 Computation as an Expressive MediumOutlineDrawing a rocketNow I want to draw several rocketsFirst method for drawing a rocketDidn’t seem to help much…DrawRocket() with argumentsNow I’d like to specify rotationRocket centered around originNow add translation and rotationWorks fine for one call…Using pushMatrix() and popMatrix()ClassesParts of a classDefining the rocket classUsing the class to create instancesAdding a draw routine to our RocketCalling methods on objectsWhat else do we want to do to the Rocket?LCC 6310Computation as an Expressive MediumLCC 6310Computation as an Expressive MediumLecture 4Lecture 4OutlineOutline•Programming conceptsProgramming concepts•Methods•Classes•Discuss Schneiderman articleDiscuss Schneiderman article•Talk about Assignment 2Talk about Assignment 2Drawing a rocketDrawing a rocketbackground(0);background(0);fill(255);fill(255);triangle(10, 0, 0, 20, 20, 20);triangle(10, 0, 0, 20, 20, 20);rectMode(CORNERS);rectMode(CORNERS);rect(5, 20, 8, 23);rect(5, 20, 8, 23);rect(12, 20, 15, 23);rect(12, 20, 15, 23);Now I want to draw several rocketsNow I want to draw several rockets•Want several rockets in different locations Want several rockets in different locations on the screenon the screen•I could copy and paste the codeI could copy and paste the code•Need to adjust all the numbers for the new location•Or… define a methodOr… define a methodFirst method for drawing a rocketFirst method for drawing a rocketvoid drawRocket() {void drawRocket() { fill(255);fill(255); triangle(10, 0, 0, 20, 20, 20);triangle(10, 0, 0, 20, 20, 20); rectMode(CORNERS);rectMode(CORNERS); rect(5, 20, 8, 23);rect(5, 20, 8, 23); rect(12, 20, 15, 23);rect(12, 20, 15, 23);}}Gotcha! Once you start using methods, all code must be in Gotcha! Once you start using methods, all code must be in methods (can’t just directly call drawRocket() at the top of methods (can’t just directly call drawRocket() at the top of the file)the file)Didn’t seem to help much…Didn’t seem to help much…•Still just draws a rocket at one fixed locationStill just draws a rocket at one fixed location•Need arguments that allow me to tell the Need arguments that allow me to tell the program where I want the rocket!program where I want the rocket!•Must figure out the relationship between the position and the location of the rest of the parts•Argument variables are available within the Argument variables are available within the method, but not outside (method scope)method, but not outside (method scope)DrawRocket() with argumentsDrawRocket() with argumentsvoid drawRocket(int noseX, int noseY) {void drawRocket(int noseX, int noseY) { int bottomOfRocket = noseY + 20;int bottomOfRocket = noseY + 20; int leftOfRocket = noseX - 10;int leftOfRocket = noseX - 10; int rightOfRocket = noseX + 10;int rightOfRocket = noseX + 10; fill(255);fill(255); triangle(noseX, noseY, leftOfRocket, bottomOfRocket, rightOfRocket, triangle(noseX, noseY, leftOfRocket, bottomOfRocket, rightOfRocket, bottomOfRocket);bottomOfRocket); rectMode(CORNERS);rectMode(CORNERS); rect(leftOfRocket + 5, bottomOfRocket, leftOfRocket + 8, bottomOfRocket + 3);rect(leftOfRocket + 5, bottomOfRocket, leftOfRocket + 8, bottomOfRocket + 3); rect(rightOfRocket - 8, bottomOfRocket, rightOfRocket - 5, bottomOfRocket + 3);rect(rightOfRocket - 8, bottomOfRocket, rightOfRocket - 5, bottomOfRocket + 3);}}Now I’d like to specify rotation Now I’d like to specify rotation •Currently I specify the nose position and it draws a rocket that Currently I specify the nose position and it draws a rocket that faces straight upfaces straight up•To rotate the rocket, I’d need to figure out the new position of the To rotate the rocket, I’d need to figure out the new position of the verticesvertices•Too hard!•Instead of rotating the rocket, rotate the paperInstead of rotating the rocket, rotate the paper• As long as I’m rotating the paper, I may as well slide it around as well•To prepare for translating and rotating, first draw the rocket To prepare for translating and rotating, first draw the rocket centered around the origin (0,0)centered around the origin (0,0)Rocket centered around origin Rocket centered around origin void drawRocket(int x, int y, float rot) {void drawRocket(int x, int y, float rot) { final int halfHeight = 10;final int halfHeight = 10; final int halfWidth = 10; final int halfWidth = 10; triangle(0, -halfHeight, -halfWidth, halfHeight, halfWidth, halfHeight); triangle(0, -halfHeight, -halfWidth, halfHeight, halfWidth, halfHeight); rectMode(CORNERS);rectMode(CORNERS); rect(-halfWidth + 5, halfHeight, -halfWidth + 8, halfHeight + 3);rect(-halfWidth + 5, halfHeight, -halfWidth + 8, halfHeight + 3); rect(halfWidth - 8, halfHeight, halfWidth - 5, halfHeight + 3);rect(halfWidth - 8, halfHeight, halfWidth - 5, halfHeight + 3);}}We’re purposely ignoring the arguments for nowWe’re purposely ignoring the arguments for nowNow add translation and rotation Now add translation and rotation void drawRocket(int x, int y, float rot) {void drawRocket(int x, int y, float rot) { final int halfHeight = 10;final int halfHeight = 10; final int halfWidth = 10; final int halfWidth = 10; translate(x, y);translate(x, y); rotate(rot);rotate(rot); triangle(0, -halfHeight, -halfWidth, halfHeight, halfWidth, halfHeight); triangle(0, -halfHeight, -halfWidth, halfHeight, halfWidth, halfHeight); rectMode(CORNERS);rectMode(CORNERS); rect(-halfWidth + 5, halfHeight, -halfWidth + 8, halfHeight + 3);rect(-halfWidth + 5, halfHeight, -halfWidth + 8, halfHeight + 3); rect(halfWidth - 8, halfHeight, halfWidth - 5, halfHeight + 3);rect(halfWidth - 8, halfHeight, halfWidth - 5, halfHeight + 3);}}Let’s try drawing several rocketsLet’s try drawing several rocketsWorks fine for one call…Works fine for one call…•But when we call it twice, it doesn’t seem to workBut when we call it twice, it doesn’t seem to work•Looks like first call messes up subsequent calls•What happening is that, when you move the paper (translate, rotate) the What happening is that, when you move the paper (translate, rotate) the paper stays movedpaper stays moved•Subsequent paper moves (additional translates and rotates) build on top Subsequent paper moves (additional translates and rotates) build on top of the previous onesof the previous ones•What we want is to move the paper, draw, and move it back What


View Full Document

GT LCC 6310 - Computation as an Expressive Medium

Documents in this Course
Load more
Download Computation as an Expressive Medium
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Computation as an Expressive Medium and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Computation as an Expressive Medium 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?