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

16
LINES

< > BotCompany Repo | #1007281 // renderImage - render a BufferedImage pixel by pixel

JavaX fragment (include)

1  
// f: func(int x, int y) -> bool/Color/RGB
2  
static BufferedImage renderImage(int w, int h, O f) {
3  
  RGBImage rgb = new RGBImage(w, h, Color.black);
4  
  for y to h: for x to w: {
5  
    O o = callF(f, x, y);
6  
    if (o instanceof Bool) rgb.setPixel(x, y, isTrue(o) ? Color.white : Color.black);
7  
    else if (o instanceof RGB) rgb.setPixel(x, y, (RGB) o);
8  
    else if (o instanceof Color) rgb.setPixel(x, y, (Color) o);
9  
    else if (o != null) fail("Woot?! " + _getClass(o));
10  
  }
11  
  ret rgb.getBufferedImage();
12  
}
13  
14  
static BufferedImage renderImage(int w, int h default w, IF2_Int f) {
15  
  ret imageFromFunction(w, h, f);
16  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1007281
Snippet name: renderImage - render a BufferedImage pixel by pixel
Eternal ID of this version: #1007281/5
Text MD5: abcaf02d8983c0cb2b1177225bae3390
Author: stefan
Category: javax / imaging
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-08-23 04:05:22
Source code size: 624 bytes / 16 lines
Pitched / IR pitched: No / No
Views / Downloads: 491 / 526
Version history: 4 change(s)
Referenced in: [show references]