Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Daniel Vogel
cs349-code
Commits
f61439cf
Commit
f61439cf
authored
Oct 13, 2017
by
Daniel Vogel
Browse files
simplified Shape.java, more applicable to A2 now
parent
866a65cf
Changes
2
Hide whitespace changes
Inline
Side-by-side
java/6-graphics/shapemodel/Shape.java
View file @
f61439cf
...
...
@@ -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
...
...
java/6-graphics/shapemodel/ShapeDemo.java
View file @
f61439cf
...
...
@@ -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
();
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment