1 /*
2 *
3 * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * - Neither the name of Oracle nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32 package java2d.demos.Arcs_Curves;
33
34
35 import java.awt.*;
36 import java.awt.geom.Arc2D;
37 import java.awt.geom.AffineTransform;
38 import java2d.AnimatingSurface;
39 import static java.awt.Color.*;
40
41
42 /**
43 * Arc2D Open, Chord & Pie arcs; Animated Pie Arc.
44 */
45 @SuppressWarnings("serial")
46 public class Arcs extends AnimatingSurface {
47
48 private static String types[] = { "Arc2D.OPEN", "Arc2D.CHORD", "Arc2D.PIE" };
49 private static final int CLOSE = 0;
50 private static final int OPEN = 1;
51 private static final int FORWARD = 0;
52 private static final int BACKWARD = 1;
53 private static final int DOWN = 2;
54 private static final int UP = 3;
55 private int aw, ah; // animated arc width & height
56 private int x, y;
57 private int angleStart = 45;
58 private int angleExtent = 270;
59 private int mouth = CLOSE;
60 private int direction = FORWARD;
61
62 public Arcs() {
63 setBackground(WHITE);
64 }
65
66 @Override
67 public void reset(int w, int h) {
68 x = 0;
142 // Draw Animated Pie Arc
143 Arc2D pieArc = new Arc2D.Float(Arc2D.PIE);
144 pieArc.setFrame(0, 0, aw, ah);
145 pieArc.setAngleStart(angleStart);
146 pieArc.setAngleExtent(angleExtent);
147 AffineTransform at = AffineTransform.getTranslateInstance(x, y);
148 switch (direction) {
149 case DOWN:
150 at.rotate(Math.toRadians(90));
151 break;
152 case BACKWARD:
153 at.rotate(Math.toRadians(180));
154 break;
155 case UP:
156 at.rotate(Math.toRadians(270));
157 }
158 g2.setColor(BLUE);
159 g2.fill(at.createTransformedShape(pieArc));
160 }
161
162 public static void main(String argv[]) {
163 createDemoFrame(new Arcs());
164 }
165 }
|
1 /*
2 *
3 * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * - Neither the name of Oracle nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32 package java2d.demos.Arcs_Curves;
33
34
35 import java.awt.*;
36 import java.awt.geom.Arc2D;
37 import java.awt.geom.AffineTransform;
38 import java2d.AnimatingSurface;
39 import static java.awt.Color.*;
40
41
42 /**
43 * Arc2D Open, Chord & Pie arcs; Animated Pie Arc.
44 */
45 @SuppressWarnings("serial")
46 public class Arcs extends AnimatingSurface {
47
48 private static String[] types = { "Arc2D.OPEN", "Arc2D.CHORD", "Arc2D.PIE" };
49 private static final int CLOSE = 0;
50 private static final int OPEN = 1;
51 private static final int FORWARD = 0;
52 private static final int BACKWARD = 1;
53 private static final int DOWN = 2;
54 private static final int UP = 3;
55 private int aw, ah; // animated arc width & height
56 private int x, y;
57 private int angleStart = 45;
58 private int angleExtent = 270;
59 private int mouth = CLOSE;
60 private int direction = FORWARD;
61
62 public Arcs() {
63 setBackground(WHITE);
64 }
65
66 @Override
67 public void reset(int w, int h) {
68 x = 0;
142 // Draw Animated Pie Arc
143 Arc2D pieArc = new Arc2D.Float(Arc2D.PIE);
144 pieArc.setFrame(0, 0, aw, ah);
145 pieArc.setAngleStart(angleStart);
146 pieArc.setAngleExtent(angleExtent);
147 AffineTransform at = AffineTransform.getTranslateInstance(x, y);
148 switch (direction) {
149 case DOWN:
150 at.rotate(Math.toRadians(90));
151 break;
152 case BACKWARD:
153 at.rotate(Math.toRadians(180));
154 break;
155 case UP:
156 at.rotate(Math.toRadians(270));
157 }
158 g2.setColor(BLUE);
159 g2.fill(at.createTransformedShape(pieArc));
160 }
161
162 public static void main(String[] argv) {
163 createDemoFrame(new Arcs());
164 }
165 }
|