Tile images in a grid

Let us know if you have a nice R.U.B.E script to share!
Post Reply
iforce2d
Site Admin
Posts: 860
Joined: Sat Dec 22, 2012 7:20 pm

Tile images in a grid

Post by iforce2d » Tue Oct 29, 2013 10:59 pm

This script will duplicate selected images based on their size and angle, so that the new copies form a tiled grid.

Code: Select all

//change as necessary
int repeatX = 5;
int repeatY = 3;

image[] imgs = si();
for (int i = 0; i < imgs.length; i++) {

	image img = imgs[i];	

	//find translation to exactly fit neighbor tiles
	float h = img.getScale();
	float aspectRatio = img.getAspectScale() * img.getPixelWidth() / img.getPixelHeight();
	float w = h * aspectRatio;
	print(w+" "+h);

	//rotate translation 
	float angle = img.getAngle();
	vec2 right = mv( cos(angle) * w, sin(angle) * w );
	vec2 up = mv( -sin(angle) * h, cos(angle) * h );

	//duplicate
	for (int x = 0; x < repeatX; x++) {
		for (int y = 0; y < repeatY; y++) {
			if ( x == 0 && y == 0 )
				continue;
			translate( duplicate( img ), x * right + y * up );
		}
	}

}
Example, before and after:
Selection_119.png
Selection_119.png (78.94 KiB) Viewed 29171 times

Post Reply