Merge pull request #1724 from ybakos/p5_web_45_examples_tileImages

Examples patch (8 of 9)
This commit is contained in:
Casey Reas
2013-04-05 14:32:51 -07:00
2 changed files with 17 additions and 18 deletions
@@ -1,7 +1,7 @@
/**
* Tile Images
*
* Draws an image larger than the screen by tiling it into small sections.
*
* Draws an image larger than the screen, and saves the image as six tiles.
* The scaleValue variable sets amount of scaling: 1 is 100%, 2 is 200%, etc.
*/
@@ -9,31 +9,29 @@ int scaleValue = 3; // Multiplication factor
int xoffset = 0; // x-axis offset
int yoffset = 0; // y-axis offset
void setup()
{
void setup() {
size(600, 600);
stroke(0, 100);
}
void draw()
{
void draw() {
background(204);
scale(scaleValue);
translate(xoffset *(-width / scaleValue), yoffset *(-height / scaleValue));
translate(xoffset * (-width / scaleValue), yoffset * (-height / scaleValue));
line(10, 150, 500, 50);
line(0, 600, 600, 0);
save("lines-" + yoffset + "-" + xoffset + ".png");
setOffset();
}
void setOffset()
{
save("lines-" + xoffset + "-" + yoffset + ".jpg");
void setOffset() {
xoffset++;
if (xoffset == scaleValue) {
xoffset = 0;
yoffset++;
if (yoffset == scaleValue) {
println("Tiles saved.");
exit();
}
}
background(204);
}
}
@@ -1,7 +1,7 @@
/**
* Tile Images
*
* Draws an image larger than the screen by tiling it into small sections.
*
* Draws an image larger than the screen, and saves the image as six tiles.
* The scaleValue variable sets amount of scaling: 1 is 100%, 2 is 200%, etc.
*/
@@ -15,22 +15,23 @@ void setup() {
}
void draw() {
background(204);
scale(scaleValue);
translate(xoffset *(-width / scaleValue), yoffset *(-height / scaleValue));
translate(xoffset * (-width / scaleValue), yoffset * (-height / scaleValue));
line(10, 150, 500, 50);
line(0, 600, 600, 0);
save("lines-" + yoffset + "-" + xoffset + ".png");
setOffset();
}
void setOffset() {
save("lines-" + xoffset + "-" + yoffset + ".png");
xoffset++;
if (xoffset == scaleValue) {
xoffset = 0;
yoffset++;
if (yoffset == scaleValue) {
println("Tiles saved.");
exit();
}
}
background(204);
}
}