1
2 package org.freehep.graphicsio.test;
3
4 import java.awt.Color;
5 import java.awt.Graphics;
6
7 import org.freehep.graphics2d.VectorGraphics;
8
9
10
11
12
13 public class TestColors extends TestingPanel {
14
15 public TestColors(String[] args) throws Exception {
16 super(args);
17 setName("Colors");
18 }
19
20 public void paintComponent(Graphics g) {
21
22 VectorGraphics vg = VectorGraphics.create(g);
23
24 vg.setColor(Color.WHITE);
25 vg.fillRect(0, 0, getWidth(), getHeight() / 3);
26
27 vg.setColor(Color.BLACK);
28 vg.fillRect(0, getHeight() / 3, getWidth(), getHeight() / 3);
29
30 int radius = 55;
31
32 int dx = getWidth() / 4;
33 int dy = getHeight() / 6;
34 int x = dx;
35 int y = dy;
36
37 drawRGB(x, y, radius, vg);
38
39 x += (dx * 2);
40 drawCMY(x, y, radius, vg);
41
42 x = dx;
43 y += (dy * 2);
44 drawRGB(x, y, radius, vg);
45
46 x += (dx * 2);
47 drawCMY(x, y, radius, vg);
48
49 x = dx;
50 y += (dy * 2);
51 drawRGB(x, y, radius, vg);
52
53 x += (dx * 2);
54 drawCMY(x, y, radius, vg);
55 }
56
57 private void drawRGB(int x, int y, int radius, VectorGraphics g) {
58 int circleWidth = radius * 2;
59 int radius53 = 5 * radius / 3;
60 int radius3 = radius / 3;
61
62 g.setColor(new Color(255, 0, 0, 128));
63 g.fillOval(x - radius53, y - radius53, circleWidth, circleWidth);
64
65 g.setColor(new Color(0, 255, 0, 128));
66 g.fillOval(x - radius3, y - radius53, circleWidth, circleWidth);
67
68 g.setColor(new Color(0, 0, 255, 128));
69 g.fillOval(x - radius, y - radius3, circleWidth, circleWidth);
70 }
71
72 private void drawCMY(int x, int y, int radius, VectorGraphics g) {
73 int circleWidth = radius * 2;
74 int radius53 = 5 * radius / 3;
75 int radius3 = radius / 3;
76
77 g.setColor(new Color(0, 255, 255, 128));
78 g.fillOval(x - radius53, y - radius53, circleWidth, circleWidth);
79
80 g.setColor(new Color(255, 0, 255, 128));
81 g.fillOval(x - radius3, y - radius53, circleWidth, circleWidth);
82
83 g.setColor(new Color(255, 255, 0, 128));
84 g.fillOval(x - radius, y - radius3, circleWidth, circleWidth);
85 }
86
87 public static void main(String[] args) throws Exception {
88 new TestColors(args).runTest();
89 }
90 }