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

21
LINES

< > BotCompany Repo | #1020217 // tilesToImage - TODO: varying tile sizes

JavaX fragment (include)

1  
static BufferedImage tilesToImage(L<BufferedImage> tiles, int columns) {
2  
  if (empty(tiles)) null;
3  
  int rows = idiv_ceil(l(tiles), columns);
4  
  int tw = first(tiles).getWidth(), th = first(tiles).getHeight();
5  
  int w = tw*columns, h = th*rows;
6  
  BufferedImage img = newBufferedImage(w, h);
7  
  
8  
  int i = 0, yy = 0;
9  
  for y to rows: {
10  
    int xx = 0;
11  
    for x to columns: {
12  
      if (i >= l(tiles)) break;
13  
      BufferedImage tile = tiles.get(i++);
14  
      copyBufferedImage(tile, img, xx, yy);
15  
      xx += tile.getWidth();
16  
      th = tile.getHeight();
17  
    }
18  
    yy += th;
19  
  }
20  
  ret img;
21  
}

Author comment

Began life as a copy of #1016032

download  show line numbers  debug dex  old transpilations   

Travelled to 8 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1020217
Snippet name: tilesToImage - TODO: varying tile sizes
Eternal ID of this version: #1020217/6
Text MD5: 7dcba2048bafbaaf3a8332470f402e61
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-12-30 21:06:32
Source code size: 606 bytes / 21 lines
Pitched / IR pitched: No / No
Views / Downloads: 279 / 324
Version history: 5 change(s)
Referenced in: [show references]