Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

40
LINES

< > BotCompany Repo | #660 // vsplit v1

JavaX source code - run with: x30.jar

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  
}

Author comment

Began life as a copy of #659

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, qbtsjoyahagl, tslmcundralx, tvejysmllsmz, vouqrxazstgt

Comments [hide]

ID Author/Program Comment Date
889 #1000604 (pitcher) 2015-08-20 15:28:24
888 #1000610 (pitcher) 2015-08-18 00:07:07

add comment

Snippet ID: #660
Snippet name: vsplit v1
Eternal ID of this version: #660/1
Text MD5: e594f21134cc57e5d35c1692987e1d15
Author: stefan
Category:
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-07-13 04:49:44
Source code size: 1155 bytes / 40 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 1031 / 932
Referenced in: [show references]