summaryrefslogtreecommitdiff
path: root/ws2015
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2015-11-17 10:07:41 +0100
committerGregor Kleen <gkleen@yggdrasil.li>2015-11-17 10:07:41 +0100
commitccae5511ecab15475cea250f8bd4bc5f75d8397b (patch)
treee995ffcce84460af3fde18a7f48fb296a4745ffc /ws2015
parent0b67e8b618f8e0351c27dd3533aa42ebffd722d7 (diff)
downloaduni-ccae5511ecab15475cea250f8bd4bc5f75d8397b.tar
uni-ccae5511ecab15475cea250f8bd4bc5f75d8397b.tar.gz
uni-ccae5511ecab15475cea250f8bd4bc5f75d8397b.tar.bz2
uni-ccae5511ecab15475cea250f8bd4bc5f75d8397b.tar.xz
uni-ccae5511ecab15475cea250f8bd4bc5f75d8397b.zip
"Solution" for eip 04 - H4-2
Diffstat (limited to 'ws2015')
-rw-r--r--ws2015/eip/blaetter/04/Schleife.java43
1 files changed, 35 insertions, 8 deletions
diff --git a/ws2015/eip/blaetter/04/Schleife.java b/ws2015/eip/blaetter/04/Schleife.java
index 05e791b..a693cb0 100644
--- a/ws2015/eip/blaetter/04/Schleife.java
+++ b/ws2015/eip/blaetter/04/Schleife.java
@@ -1,20 +1,47 @@
1import java.awt.Rectangle; 1import java.awt.Rectangle;
2import java.awt.Color;
3import java.awt.Point;
2 4
3public class Schleife { 5public class Schleife {
4 6
5 public static void main(String[] args) { 7 public static void main(String[] args) {
6 int margin = 25;
7 int box_height = 50;
8 int box_width = 150;
9 Rectangle r1 = new Rectangle(margin, margin + box_width, box_width, box_height);
10 GraphicsWindow gw = new GraphicsWindow(); 8 GraphicsWindow gw = new GraphicsWindow();
11 gw.fill(r1);
12 9
13 // ... TODO ... 10 drawGradient(gw);
14 11
15 gw.setText("Klicken Sie zum Beenden.");
16 gw.mouseClick(); 12 gw.mouseClick();
17 System.exit(0); 13 System.exit(0);
18 } 14 }
19 15
16 private static void drawGradient(GraphicsWindow gw) {
17 Color fg = gw.getColor();
18 for (Point p = new Point(0,0); p.y <= 480; p.move(0, p.y + 1)) // gw.GetWidth would have been nice
19 {
20 for (;p.x <= 640; p.move(p.x + 1, p.y))
21 {
22 gw.setColor(f(p.x, p.y) <= 0 ? Color.red : color(p.x, p.y));
23 // System.out.format("%s in %s\n", p.toString(), gw.getColor().toString()); // DEBUG
24 gw.drawPoint(p);
25 }
26 }
27 gw.setColor(fg);
28 }
29
30 private static double f(int x, int y) {
31 double xprime = (x - 200) / 120;
32 double yprime = (200 - y) / 100;
33 return Math.pow(xprime * xprime + yprime * yprime - 1, 3) - (xprime * xprime * yprime * yprime * yprime);
34 // pow is comparatively expensive (at least it would be if this were C ;) )
35 }
36
37 private static Color color(int x, int y) {
38 // System.out.format("(%d, %d)\n", x, y); // DEBUG
39 double g = 0.15 * (1200 - x - y);
40 double b = 0.15 * (x + y);
41 return new Color((int) 0, (int) g, (int) b);
42 /* Why can’t we have nice things? Like proper type signatures?
43 * We introduce some error by truncating to integer -- We deemed this to be of no moment.
44 */
45 }
46
20} 47}