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

13
LINES

< > BotCompany Repo | #1009956 // paintTiledBackground_centered

JavaX fragment (include)

static void paintTiledBackground_centered(Component c, Graphics g, BufferedImage image) {
  int w = c.getWidth();  
  int h = c.getHeight();  
  int tw = image.getWidth(), th = image.getHeight();
  
  // center of tile should be in center of image
  int shiftX = (w-tw)/2, shiftY = (h-th)/2;
  
  int y1 = mod(shiftY-1, th)-th+1;
  for (int x = mod(shiftX-1, tw)-tw+1; x < w; x += tw)
    for (int y = y1; y < h; y += th)
      g.drawImage(image, x, y, c);
}

Author comment

Began life as a copy of #1009941

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: #1009956
Snippet name: paintTiledBackground_centered
Eternal ID of this version: #1009956/1
Text MD5: da3ae165758d1c272163b8138de2887b
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-08-27 17:42:10
Source code size: 470 bytes / 13 lines
Pitched / IR pitched: No / No
Views / Downloads: 439 / 438
Referenced in: [show references]