forked from UCSB-CS56-W14/CS56-W14-lab06
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7edf435
commit aeaf0b6
Showing
12 changed files
with
907 additions
and
0 deletions.
There are no files selected for viewing
148 changes: 148 additions & 0 deletions
148
src/edu/ucsb/cs56/W14/drawings/chrisluo/advanced/AllMyDrawings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
package edu.ucsb.cs56.w14.drawings.chrisluo.advanced; | ||
|
||
import java.awt.Graphics2D; | ||
import java.awt.geom.Line2D; // single lines | ||
import java.awt.geom.Ellipse2D; // ellipses and circles | ||
import java.awt.geom.Rectangle2D; // for the bounding box | ||
import java.awt.Rectangle; // squares and rectangles | ||
import java.awt.geom.GeneralPath; // combinations of lines and curves | ||
import java.awt.geom.AffineTransform; // translation, rotation, scale | ||
import java.awt.Shape; // general class for shapes | ||
import java.awt.Color; // class for Colors | ||
import java.awt.Stroke; | ||
import java.awt.BasicStroke; | ||
|
||
|
||
import edu.ucsb.cs56.w14.drawings.utilities.ShapeTransforms; | ||
import edu.ucsb.cs56.w14.drawings.utilities.GeneralPathWrapper; | ||
|
||
/** | ||
* A class with static methods for drawing various pictures | ||
* | ||
* @author Phill Conrad | ||
*@author Chris Luo | ||
* @version for CS56, lab06, W14 | ||
*/ | ||
|
||
|
||
public class AllMyDrawings | ||
{ | ||
|
||
public static void drawPicture1(Graphics2D g2) { | ||
|
||
Pumpkin p1 = new Pumpkin(20,200,50,50); | ||
g2.setColor(Color.ORANGE); g2.draw(p1); | ||
|
||
Shape p2 = ShapeTransforms.scaledCopyOfLL(p1,0.5,0.5); | ||
p2 = ShapeTransforms.translatedCopyOf(p2,150,0); | ||
g2.setColor(Color.ORANGE); g2.draw(p2); | ||
|
||
p2 = ShapeTransforms.scaledCopyOfLL(p2,4,4); | ||
p2 = ShapeTransforms.translatedCopyOf(p2,150,0); | ||
|
||
// We'll draw this with a thicker stroke | ||
Stroke thick = new BasicStroke (4.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL); | ||
|
||
// for hex colors, see (e.g.) http://en.wikipedia.org/wiki/List_of_colors | ||
// #002FA7 is "International Klein Blue" according to Wikipedia | ||
// In HTML we use #, but in Java (and C/C++) its 0x | ||
|
||
Stroke orig=g2.getStroke(); | ||
g2.setStroke(thick); | ||
g2.setColor(new Color(0xFF7518)); | ||
g2.draw(p2); | ||
|
||
|
||
PumpkinJack pj1 = new PumpkinJack(25,25,50,50); | ||
PumpkinJack pj2 = new PumpkinJack(50,50,75,50); | ||
|
||
g2.draw(pj1); | ||
g2.setColor(new Color(0xFF7518)); g2.draw(pj2); | ||
|
||
// @@@ FINALLY, SIGN AND LABEL YOUR DRAWING | ||
|
||
g2.setStroke(orig); | ||
g2.setColor(Color.BLACK); | ||
g2.drawString("A few pumpkins by Chris Luo", 20,20); | ||
} | ||
|
||
|
||
/** Draw a picture with pumpkins and jack o lanterns | ||
*/ | ||
public static void drawPicture2(Graphics2D g2) { | ||
|
||
// Draw some pumpkins | ||
|
||
Pumpkin large = new Pumpkin(100,50,225,150); | ||
Pumpkin smallCC = new Pumpkin(20,50,40,30); | ||
Pumpkin tallSkinny = new Pumpkin(20,150,20,40); | ||
Pumpkin shortFat = new Pumpkin(20,250,40,20); | ||
|
||
g2.setColor(Color.RED); g2.draw(large); | ||
g2.setColor(Color.GREEN); g2.draw(smallCC); | ||
g2.setColor(Color.BLUE); g2.draw(tallSkinny); | ||
g2.setColor(Color.MAGENTA); g2.draw(shortFat); | ||
|
||
Pumpkin p1 = new Pumpkin(100,250,50,75); | ||
g2.setColor(Color.CYAN); g2.draw(p1); | ||
|
||
Shape p2 = ShapeTransforms.scaledCopyOfLL(p1,0.5,0.5); | ||
p2 = ShapeTransforms.translatedCopyOf(p2,150,0); | ||
g2.setColor(Color.BLACK); g2.draw(p2); | ||
|
||
p2 = ShapeTransforms.scaledCopyOfLL(p2,4,4); | ||
p2 = ShapeTransforms.translatedCopyOf(p2,150,0); | ||
|
||
// We'll draw this with a thicker stroke | ||
Stroke thick = new BasicStroke (4.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL); | ||
|
||
// for hex colors, see (e.g.) http://en.wikipedia.org/wiki/List_of_colors | ||
// #002FA7 is "International Klein Blue" according to Wikipedia | ||
// In HTML we use #, but in Java (and C/C++) its 0x | ||
|
||
Stroke orig=g2.getStroke(); | ||
g2.setStroke(thick); | ||
g2.setColor(new Color(0x002FA7)); | ||
g2.draw(p2); | ||
|
||
PumpkinJack pj1 = new PumpkinJack(50,350,40,75); | ||
PumpkinJack pj2 = new PumpkinJack(200,350,200,100); | ||
|
||
g2.draw(pj1); | ||
g2.setColor(new Color(0x8F00FF)); | ||
|
||
// Rotate the second house 45 degrees around its center. | ||
Shape pj3 = ShapeTransforms.rotatedCopyOf(pj2, Math.PI/4.0); | ||
|
||
g2.draw(pj3); | ||
|
||
// @@@ FINALLY, SIGN AND LABEL YOUR DRAWING | ||
|
||
g2.setStroke(orig); | ||
g2.setColor(Color.BLACK); | ||
g2.drawString("Pumpkins and Jack-o-lanterns by Chris Luo", 20,20); | ||
} | ||
|
||
/** Draw a different picture with pumpkins | ||
*/ | ||
|
||
public static void drawPicture3(Graphics2D g2) { | ||
|
||
// label the drawing | ||
|
||
g2.drawString("A bunch of Pumpkins by Chris Luo", 20,20); | ||
|
||
|
||
// Draw some pumpkins. | ||
|
||
Pumpkin large = new Pumpkin(100,50,225,150); | ||
Pumpkin smallCC = new Pumpkin(20,50,40,30); | ||
|
||
g2.setColor(Color.RED); g2.draw(large); | ||
g2.setColor(Color.GREEN); g2.draw(smallCC); | ||
|
||
|
||
} | ||
|
||
|
||
} |
97 changes: 97 additions & 0 deletions
97
src/edu/ucsb/cs56/W14/drawings/chrisluo/advanced/CoffeeCup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package edu.ucsb.cs56.w14.drawings.chrisluo.advanced; | ||
import java.awt.geom.GeneralPath; // combinations of lines and curves | ||
import java.awt.geom.AffineTransform; // translation, rotation, scale | ||
import java.awt.Shape; // general class for shapes | ||
|
||
// all imports below this line needed if you are implementing Shape | ||
import java.awt.geom.Point2D; | ||
import java.awt.geom.Rectangle2D; | ||
import java.awt.Rectangle; | ||
import java.awt.geom.PathIterator; | ||
import java.awt.geom.AffineTransform; | ||
|
||
import edu.ucsb.cs56.w14.drawings.utilities.ShapeTransforms; | ||
import edu.ucsb.cs56.w14.drawings.utilities.GeneralPathWrapper; | ||
|
||
/** | ||
A Coffee Cup (wrapper around a General Path, implements Shape) | ||
This provides an example of how you can start with the coordinates | ||
of a hard coded object, and end up with an object that can be | ||
drawn anywhere, with any width or height. | ||
@author Phill Conrad | ||
@author Chris Luo | ||
@version for CS56, W14, UCSB, 02/28/2014 | ||
*/ | ||
public class CoffeeCup extends GeneralPathWrapper implements Shape | ||
{ | ||
|
||
|
||
/** | ||
* Constructor for objects of class CoffeeCup | ||
*/ | ||
public CoffeeCup(double x, double y, double width, double height) | ||
{ | ||
|
||
// Specify the upper left corner, and the | ||
// width and height of the original points used to | ||
// plot the *hard-coded* coffee cup | ||
|
||
final double ORIG_ULX = 100.0; | ||
final double ORIG_ULY = 100.0; | ||
final double ORIG_HEIGHT = 300.0; | ||
final double ORIG_WIDTH = 400.0; | ||
|
||
GeneralPath leftSide = new GeneralPath(); | ||
|
||
// left side of cup | ||
|
||
leftSide.moveTo(200,400); | ||
leftSide.lineTo(160,360); | ||
leftSide.lineTo(130,300); | ||
leftSide.lineTo(100,200); | ||
leftSide.lineTo(100,100); | ||
|
||
GeneralPath topAndBottom = new GeneralPath(); | ||
|
||
topAndBottom.moveTo(100,100); | ||
topAndBottom.lineTo(500,100); // top of cup | ||
|
||
topAndBottom.moveTo(200,400); | ||
topAndBottom.lineTo(400,400); // bottom of cup | ||
|
||
Shape rightSide = ShapeTransforms.horizontallyFlippedCopyOf(leftSide); | ||
|
||
// after flipping around the upper left hand corner of the | ||
// bounding box, we move this over to the right by 400 pixels | ||
|
||
rightSide = ShapeTransforms.translatedCopyOf(rightSide, 400.0, 0.0); | ||
|
||
// now we put the whole thing together ino a single path. | ||
|
||
GeneralPath wholeCup = new GeneralPath (); | ||
wholeCup.append(topAndBottom, false); | ||
wholeCup.append(leftSide, false); | ||
wholeCup.append(rightSide, false); | ||
|
||
// translate to the origin by subtracting the original upper left x and y | ||
// then translate to (x,y) by adding x and y | ||
|
||
Shape s = ShapeTransforms.translatedCopyOf(wholeCup, -ORIG_ULX + x, -ORIG_ULY + y); | ||
|
||
// scale to correct height and width | ||
s = ShapeTransforms.scaledCopyOf(s, | ||
width/ORIG_WIDTH, | ||
height/ORIG_HEIGHT) ; | ||
|
||
// Use the GeneralPath constructor that takes a shape and returns | ||
// it as a general path to set our instance variable cup | ||
|
||
this.set(new GeneralPath(s)); | ||
|
||
} | ||
|
||
} |
77 changes: 77 additions & 0 deletions
77
src/edu/ucsb/cs56/W14/drawings/chrisluo/advanced/House.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package edu.ucsb.cs56.w14.drawings.chrisluo.advanced; | ||
import java.awt.geom.GeneralPath; // combinations of lines and curves | ||
import java.awt.geom.AffineTransform; // translation, rotation, scale | ||
import java.awt.Shape; // general class for shapes | ||
|
||
// all imports below this line needed if you are implementing Shape | ||
import java.awt.geom.Point2D; | ||
import java.awt.geom.Line2D; | ||
import java.awt.geom.Rectangle2D; | ||
import java.awt.Rectangle; | ||
import java.awt.geom.PathIterator; | ||
import java.awt.geom.AffineTransform; | ||
|
||
import edu.ucsb.cs56.w14.drawings.utilities.ShapeTransforms; | ||
import edu.ucsb.cs56.w14.drawings.utilities.GeneralPathWrapper; | ||
|
||
/** | ||
A vector drawing of a house that implements | ||
the Shape interface, and so can be drawn, as well as | ||
rotated, scaled, etc. | ||
@author Phill Conrad | ||
@author Chris Luo | ||
@version for CS56, Winter 14, UCSB | ||
*/ | ||
public class House extends GeneralPathWrapper implements Shape | ||
{ | ||
/** | ||
Constructor | ||
@param x x coord of lower left corner of house | ||
@param y y coord of lower left corner of house | ||
@param width width of the house | ||
@param height of house (including first story and second story) | ||
*/ | ||
public House(double x, double y, double width, double height) | ||
{ | ||
|
||
// Rather than having to scale at the end, we can just | ||
// draw things the right way to begin with, using the | ||
// x, y, width and height. If you haven't already | ||
// hard coded a particular drawing, this may be an easier | ||
// way. | ||
|
||
double firstStoryHeight = .75 * height; | ||
double roofHeight = height - firstStoryHeight; | ||
|
||
double firstStoryUpperLeftY = y + roofHeight; | ||
|
||
// Make the first story | ||
|
||
Rectangle2D.Double firstStory = | ||
new Rectangle2D.Double(x, firstStoryUpperLeftY , | ||
width, firstStoryHeight); | ||
|
||
// make the roof. Remember that y goes DOWN the page, | ||
// so we ADD to y to get a "lower" value on the screen | ||
|
||
Line2D.Double leftRoof = | ||
new Line2D.Double (x, y + roofHeight, | ||
x + width/2.0, y); | ||
|
||
Line2D.Double rightRoof = | ||
new Line2D.Double (x + width/2.0, y, | ||
x + width, y + roofHeight); | ||
|
||
// put the whole house together | ||
|
||
GeneralPath wholeHouse = this.get(); | ||
wholeHouse.append(firstStory, false); | ||
wholeHouse.append(leftRoof, false); | ||
wholeHouse.append(rightRoof, false); | ||
|
||
} | ||
|
||
} |
67 changes: 67 additions & 0 deletions
67
src/edu/ucsb/cs56/W14/drawings/chrisluo/advanced/HouseWithWindows.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package edu.ucsb.cs56.w14.drawings.chrisluo.advanced; | ||
import java.awt.geom.GeneralPath; // combinations of lines and curves | ||
import java.awt.geom.AffineTransform; // translation, rotation, scale | ||
import java.awt.Shape; // general class for shapes | ||
|
||
// all imports below this line needed if you are implementing Shape | ||
import java.awt.geom.Point2D; | ||
import java.awt.geom.Line2D; | ||
import java.awt.geom.Rectangle2D; | ||
import java.awt.Rectangle; | ||
import java.awt.geom.PathIterator; | ||
import java.awt.geom.AffineTransform; | ||
|
||
import edu.ucsb.cs56.w14.drawings.utilities.ShapeTransforms; | ||
import edu.ucsb.cs56.w14.drawings.utilities.GeneralPathWrapper; | ||
/** | ||
A House | ||
@author Phill Conrad | ||
@author Chris Luo | ||
@version for CS56, W14, UCSB, 02/28/2014 | ||
*/ | ||
public class HouseWithWindows extends House implements Shape | ||
{ | ||
/** | ||
* Constructor for objects of class CoffeeCup | ||
*/ | ||
public HouseWithWindows(double x, double y, double width, double height) | ||
{ | ||
// construct the basic house shell | ||
super(x,y,width,height); | ||
|
||
// get the GeneralPath that we are going to append stuff to | ||
GeneralPath gp = this.get(); | ||
|
||
// Make three windows, spaced like this, where w=width/10.0; | ||
// | +--+ +--+ +--+ | | ||
// | | | | | | | | | ||
// | +--+ +--+ +--+ | | ||
// |w 2w w 2w w w2 w| | ||
// | ||
// The top of window will be at y + 0.5*height and the | ||
// height of the window is 0.25height; | ||
|
||
double w = 0.10 * width; | ||
double winTop = y + 0.5 * height; | ||
double winHt = 0.25 * height; | ||
|
||
Rectangle2D.Double win1 = | ||
new Rectangle2D.Double(x + w, winTop, 2.0 * w, winHt); | ||
Rectangle2D.Double win2 = | ||
new Rectangle2D.Double(x + 4.0*w, winTop, 2.0 * w, winHt); | ||
Rectangle2D.Double win3 = | ||
new Rectangle2D.Double(x + 7.0*w, winTop, 2.0 * w, winHt); | ||
|
||
// add the windows to the house | ||
// Look up the meaning of the second parameter of append | ||
// (Hint--is a method of "GeneralPath") | ||
|
||
GeneralPath wholeHouse = this.get(); | ||
wholeHouse.append(win1, false); | ||
wholeHouse.append(win2, false); | ||
wholeHouse.append(win3, false); | ||
} | ||
|
||
} |
Oops, something went wrong.