Skip to content

Commit

Permalink
Merge pull request #4 from jennyvien/master
Browse files Browse the repository at this point in the history
Added Melon and MelonWithSeeds classes under jennyvien directory
  • Loading branch information
jcneally committed Mar 7, 2014
2 parents 19475a4 + d6f9594 commit 0233885
Show file tree
Hide file tree
Showing 14 changed files with 1,021 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/edu/ucsb/cs56/W14/drawings/jennyvien/SimpleGui1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package edu.ucsb.cs56.w14.drawings.jennyvien;
import javax.swing.*;

/** SimpleGui1 comes from Head First Java 2nd Edition p. 355.
It illustrates a simple GUI with a Button that doesn't do anything yet.
@author Head First Java, 2nd Edition p. 355
@author P. Conrad (who only typed it in and added the Javadoc comments)
@author Jenny Vien
@version CS56, Winter 2014, UCSB
*/

public class SimpleGui1 {

/** main method to fire up a JFrame on the screen
@param args not used
*/

public static void main (String[] args) {
JFrame frame = new JFrame() ;
JButton button = new JButton("click me please");
java.awt.Color myColor = new java.awt.Color(237,129,245);
button.setBackground(myColor);
button.setOpaque(true);
frame. setDefaultCloseOperation(JFrame. EXIT_ON_CLOSE) ;
frame. getContentPane() . add(button) ;
frame. setSize(300,300) ;
frame. setVisible(true) ;
}
}
76 changes: 76 additions & 0 deletions src/edu/ucsb/cs56/W14/drawings/jennyvien/advanced/#Melon.java#
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package edu.ucsb.cs56.w14.drawings.jennyvien.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 melon.

@author Phill Conrad
@author Jenny Vien
@version for CS56, W14, UCSB, 02/22/2014

*/
public class Melon extends GeneralPathWrapper implements Shape {


/**
* Constructor for objects of class Melon
*/
final double ORIG_ULX = 0.0;
final double ORIG_ULY = 0.0;
final double ORIG_HEIGHT = 350.0;
final double ORIG_WIDTH = 500.0;
public Melon(double x, double y, double width, double height)
{
GeneralPath leftSide = new GeneralPath();

leftSide.moveTo(150,350);
leftSide.lineTo(50,300);
leftSide.lineTo(0,150);
leftSide.lineTo(0,0);

GeneralPath topAndBottom = new GeneralPath();

topAndBottom.moveTo(0,0);
topAndBottom.lineTo(500,0); // top of melon

topAndBottom.moveTo(150,350);
topAndBottom.lineTo(350,350); // bottom of melon

Shape rightSide = ShapeTransforms.horizontallyFlippedCopyOf(leftSide);
rightSide = ShapeTransforms.translatedCopyOf(rightSide, 500, 0.0);


GeneralPath wholeMelon = new GeneralPath ();
wholeMelon.append(topAndBottom, false);
wholeMelon.append(leftSide, false);
wholeMelon.append(rightSide, false);

Shape wholeMelon2 = ShapeTransforms.scaledCopyOf(wholeMelon,
(ORIG_WIDTH * 0.80)/ORIG_WIDTH,
(ORIG_HEIGHT * 0.80)/ORIG_HEIGHT) ;
wholeMelon2 = ShapeTransforms.translatedCopyOf(wholeMelon2, 50,0.0 );
wholeMelon.append(wholeMelon2,false);


Shape s = ShapeTransforms.translatedCopyOf(wholeMelon, ORIG_ULX + x, ORIG_ULY + y);
s = ShapeTransforms.scaledCopyOf(s,
width/ORIG_WIDTH,
height/ORIG_HEIGHT) ;


this.set(new GeneralPath(s));

}

}
130 changes: 130 additions & 0 deletions src/edu/ucsb/cs56/W14/drawings/jennyvien/advanced/AllMyDrawings.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package edu.ucsb.cs56.w14.drawings.jennyvien.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 Jenny Vien
* @version for CS56, lab06, Winter 2014
*/


public class AllMyDrawings {
/**
* Draw a picture with a few melons.
*/

public static void drawPicture1(Graphics2D g2) {

Melon m1 = new Melon(100,250,50,75);
g2.setColor(Color.CYAN); g2.draw(m1);

Shape m2 = ShapeTransforms.scaledCopyOfLL(m1,0.5,0.5);
m2 = ShapeTransforms.translatedCopyOf(m2,150,0);
g2.setColor(Color.BLACK); g2.draw(m2);

m2 = ShapeTransforms.scaledCopyOfLL(m2,4,4);
m2 = ShapeTransforms.translatedCopyOf(m2,150,0);

Stroke thick = new BasicStroke (4.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL);

Stroke orig=g2.getStroke();
g2.setStroke(thick);
g2.setColor(new Color(0x002FA7));
g2.draw(m2);

MelonWithSeeds ms1 = new MelonWithSeeds(50,350,40,75);
MelonWithSeeds ms2 = new MelonWithSeeds(200,350,200,100);

g2.draw(ms1);
g2.setColor(new Color(0x8F00FF)); g2.draw(ms2);

g2.setStroke(orig);
g2.setColor(Color.BLACK);
g2.drawString("A few melons by Jenny Vien", 20,20);
}

/**
* Draw another picture with a few melons.
*/
public static void drawPicture2(Graphics2D g2) {

Melon large = new Melon(100,50,225,150);
Melon smallMelon = new Melon(20,50,40,30);
Melon tallSkinny = new Melon(20,150,20,40);
Melon shortFat = new Melon(20,250,40,20);

g2.setColor(Color.RED); g2.draw(large);
g2.setColor(Color.GREEN); g2.draw(smallMelon);
g2.setColor(Color.BLUE); g2.draw(tallSkinny);
g2.setColor(Color.MAGENTA); g2.draw(shortFat);

Melon m1 = new Melon(100,250,50,75);
g2.setColor(Color.CYAN); g2.draw(m1);

Shape m2 = ShapeTransforms.scaledCopyOfLL(m1,0.5,0.5);
m2 = ShapeTransforms.translatedCopyOf(m2,150,0);
g2.setColor(Color.BLACK); g2.draw(m2);

m2 = ShapeTransforms.scaledCopyOfLL(m2,4,4);
m2 = ShapeTransforms.translatedCopyOf(m2,150,0);

Stroke thick = new BasicStroke (4.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL);

Stroke orig=g2.getStroke();
g2.setStroke(thick);
g2.setColor(new Color(0x002FA7));
g2.draw(m2);

MelonWithSeeds ms1 = new MelonWithSeeds(50,350,40,75);
MelonWithSeeds ms2 = new MelonWithSeeds(200,350,200,100);

g2.draw(ms1);
g2.setColor(new Color(0x8F00FF));

Shape ms3 = ShapeTransforms.rotatedCopyOf(ms2, Math.PI/4.0);

g2.draw(ms3);

g2.setStroke(orig);
g2.setColor(Color.BLACK);
g2.drawString("A bunch of melons by Jenny Vien", 20,20);
}

/**
* Draw a different picture with a few melons.
*/

public static void drawPicture3(Graphics2D g2) {

g2.drawString("A few Melons by Jenny Vien", 20,20);

Melon large = new Melon(100,50,225,150);
Melon smallMelon = new Melon(20,50,40,30);
Shape rotatedMelon = ShapeTransforms.rotatedCopyOf(large, Math.PI/2.0);
rotatedMelon = ShapeTransforms.translatedCopyOf(rotatedMelon, 300,0.0 );
g2.setColor(Color.RED); g2.draw(large);
g2.setColor(Color.GREEN); g2.draw(smallMelon);
g2.setColor(Color.BLUE); g2.draw(rotatedMelon);


}


}
96 changes: 96 additions & 0 deletions src/edu/ucsb/cs56/W14/drawings/jennyvien/advanced/CoffeeCup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package edu.ucsb.cs56.w14.drawings.jennyvien.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
@version for CS56, W11, UCSB, 02/23/2011
*/
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));

}

}
Loading

0 comments on commit 0233885

Please sign in to comment.