1 | !636
|
2 | !629 // standard functions
|
3 | !658 // image classes
|
4 |
|
5 | import java.awt.*;
|
6 | import java.awt.image.*;
|
7 | import java.util.List;
|
8 |
|
9 | public class main {
|
10 | public static void main(String[] args) {
|
11 | JFrame frame = new JFrame("A JavaX Frame");
|
12 |
|
13 | RGBImage image = new RGBImage(100, 100, Color.white);
|
14 | double splitPoint = random();
|
15 | RGB col1 = new RGB(Color.green), col2 = new RGB(Color.blue);
|
16 | vsplit(image, splitPoint, col1, col2);
|
17 | ImageSurface panel = new ImageSurface(image);
|
18 |
|
19 | frame.add(panel);
|
20 | frame.setBounds(100, 100, 500, 400);
|
21 | frame.setVisible(true);
|
22 | exitOnFrameClose(frame);
|
23 | }
|
24 |
|
25 | static Random _random = new Random();
|
26 | static double random() {
|
27 | return _random.nextInt(50001)/50000.0;
|
28 | }
|
29 |
|
30 | static void vsplit(RGBImage img, double splitPoint, RGB col1, RGB col2) {
|
31 | int w = img.getWidth(), h = img.getHeight();
|
32 | for (int yy = 0; yy < h; yy++)
|
33 | for (int xx = 0; xx < w; xx++) {
|
34 | double x = ((double) xx)/(w-1);
|
35 | double y = ((double) yy)/(h-1);
|
36 | RGB col = y <= splitPoint ? col1 : col2;
|
37 | img.setPixel(xx, yy, col);
|
38 | }
|
39 | }
|
40 | }
|