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
|
import java.awt.Rectangle;
import java.awt.Color;
import java.awt.Point;
public class Schleife {
public static void main(String[] args) {
GraphicsWindow gw = new GraphicsWindow();
drawGradient(gw);
gw.mouseClick();
System.exit(0);
}
private static void drawGradient(GraphicsWindow gw) {
Color fg = gw.getColor();
for (Point p = new Point(0,0); p.y <= 480; p.move(0, p.y + 1)) // gw.GetWidth would have been nice
{
for (;p.x <= 640; p.move(p.x + 1, p.y))
{
gw.setColor(f(p.x, p.y) <= 0 ? Color.red : color(p.x, p.y));
// System.out.format("%s in %s\n", p.toString(), gw.getColor().toString()); // DEBUG
gw.drawPoint(p);
}
}
gw.setColor(fg);
}
private static double f(int x, int y) {
double xprime = (x - 200) / 120.0;
double yprime = (200 - y) / 100.0;
return Math.pow(xprime * xprime + yprime * yprime - 1, 3) - (xprime * xprime * yprime * yprime * yprime);
// pow is comparatively expensive (at least it would be if this were C ;) )
}
private static Color color(int x, int y) {
// System.out.format("(%d, %d)\n", x, y); // DEBUG
double g = 0.15 * (1200 - x - y);
double b = 0.15 * (x + y);
return new Color((int) 0, (int) g, (int) b);
/* Why can’t we have nice things? Like proper type signatures?
* We introduce some error by truncating to integer -- We deemed this to be of no moment.
*/
}
}
|