Commit f61439cf authored by Daniel Vogel's avatar Daniel Vogel

simplified Shape.java, more applicable to A2 now

parent 866a65cf
......@@ -76,16 +76,10 @@ class Shape {
this.strokeThickness = strokeThickness;
}
// the model to world transform (default is identity)
AffineTransform transform = new AffineTransform();
// shape's transform
public AffineTransform getTransform() {
return transform;
}
public void setTransform(AffineTransform transform) {
this.transform = transform;
}
// quick hack, get and set would be better
float scale = 1.0f;
// some optimization to cache points for drawing
Boolean pointsChanged = false; // dirty bit
......@@ -118,14 +112,16 @@ class Shape {
AffineTransform M = g2.getTransform();
// multiply in this shape's transform
g2.transform(transform);
// (uniform scale)
g2.scale(scale, scale);
// call drawing functions
g2.setColor(colour);
if (isFilled) {
g2.fillPolygon(xpoints, ypoints, npoints);
} else {
g2.setStroke(new BasicStroke(strokeThickness));
// can adjust stroke size using scale
g2.setStroke(new BasicStroke(strokeThickness / scale));
if (isClosed)
g2.drawPolygon(xpoints, ypoints, npoints);
else
......
......@@ -27,16 +27,8 @@ public class ShapeDemo extends JPanel {
// shape.setIsFilled(true);
shape.setColour(Color.BLUE);
// try uncommenting this block ...
// // remember transformations are post-multipied ...
// // let's mirror the shape ...
// AffineTransform T = new AffineTransform();
// // then scale
// T.concatenate(AffineTransform.getScaleInstance(-1, 1));
// // translate first
// T.concatenate(AffineTransform.getTranslateInstance(-300,0));
// shape.setTransform(T);
// try setting scale to something other than 1
shape.scale = 1.0f;
repaint();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment