Created
February 28, 2018 15:44
-
-
Save leafi/e3788913616bfd07b6a96b8431578b6e to your computer and use it in GitHub Desktop.
binpack_example.lua for binpack.lua MAXRECTS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local binpack_new = require('binpack') | |
local bp = binpack_new(2048, 2048) | |
local rect1 = bp:insert(32, 64) | |
-- (rect1 has .x, .y, .w, .h, :clone(), :contains(rect), .right, .bottom) | |
print('rect1:', rect1) -- rect1: {x=0,y=0,w=32,h=64} | |
local rect2 = bp:insert(100, 101) | |
print('rect2:', rect2) -- rect2: {x=0,y=64,w=100,h=101} | |
print('\n20 250x200 rects: '); for i = 1,20 do print(bp:insert(250, 200)) end | |
print('\nClearing; changing binpack instance to 1024x1024') | |
bp:clear(1024, 1024) -- you MUST provide w,h again | |
print('10 370x430 rects in 1024x1024:'); for i = 1,10 do print(bp:insert(370, 430)) end | |
-- you can call binpack_new(w, h) again if you want 2 binpackers simultaneously. it's not an issue. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment