1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
/* Listing2501.java */
import java.awt.*;
import java.awt.event.*;
public class Listing2501
extends Frame
{
public static void main(String[] args)
{
Listing2501 wnd = new Listing2501();
}
public Listing2501()
{
super("Der Farbenkreis");
addWindowListener(new WindowClosingAdapter(true));
setSize(300,200);
setVisible(true);
}
public void paint(Graphics g)
{
int top = getInsets().top;
int left = getInsets().left;
int maxX = getSize().width-left-getInsets().right;
int maxY = getSize().height-top-getInsets().bottom;
Color col;
int[] arx = {130,160,190};
int[] ary = {60,110,60};
int[] arr = {50,50,50};
int[] arcol = {0,0,0};
boolean paintit;
int dx, dy;
for (int y = 0; y < maxY; ++y) {
for (int x = 0; x < maxX; ++x) {
paintit = false;
for (int i = 0; i < arcol.length; ++i) {
dx = x - arx[i];
dy = y - ary[i];
arcol[i] = 0;
if ((dx*dx+dy*dy) <= arr[i]*arr[i]) {
arcol[i] = 255;
paintit = true;
}
}
if (paintit) {
col = new Color(arcol[0],arcol[1],arcol[2]);
g.setColor(col);
g.drawLine(x+left,y+top,x+left+1,y+top+1);
}
}
}
}
}
|