Difference between revisions of "GSDP:GAM100/CProcessing/save()"
From Inside
< GSDP:GAM100 | CProcessing
>Zachary.logsdon (New page: {{GSDP:GAM100API.css}} = save() = == Description == Saves the current settings state. Such as transform, fill color, stroke color, and size changes. == Example == <syntaxhighlight lang='...) |
>Zachary.logsdon |
||
Line 3: | Line 3: | ||
== Description == | == Description == | ||
− | Saves the current settings state. Such as transform, fill color, stroke color, and size changes. | + | Saves the current settings state and adds it to a stack a save states. Such as transform, fill color, stroke color, and size changes. Can only have 32 save states on the stack at once. |
== Example == | == Example == |
Revision as of 11:42, 6 October 2019
save()
Description
Saves the current settings state and adds it to a stack a save states. Such as transform, fill color, stroke color, and size changes. Can only have 32 save states on the stack at once.
Example
void init()
{
rectMode(CENTER);
}
void save_restore_test_update()
{
// Draw a white background
background(color(255, 255, 255, 255));
// Draw a red square in the top left corner
fill(color(255, 0, 0, 255));
stroke(color(0, 0, 255, 255));
rect(canvasWidth * 0.25f, canvasHeight * 0.20f, 100.0f, 100.0f);
// Save the settings of the first square
save();
// Draw a blue square in the top middle
fill(color(0, 0, 255, 255));
stroke(color(255, 0, 0, 255));
strokeWeight(5);
rect(canvasWidth * 0.5f, canvasHeight * 0.35f, 100.0f, 100.0f);
// Save the settings of the second square
save();
// Now draw a pink and green square on the right side of the screen
fill(color(200, 0, 200, 255));
stroke(color(0, 255, 0, 255));
strokeWeight(10);
rect(canvasWidth * 0.75f, canvasHeight * 0.5f, 100.0f, 100.0f);
// Restore the blue settings and draw a blue square in the bottom middle
restore();
rect(canvasWidth * 0.5f, canvasHeight * 0.65f, 100.0f, 100.0f);
// Restore the red settings and draw a red square in the bottom left
restore();
rect(canvasWidth * 0.25f, canvasHeight * 0.80f, 100.0f, 100.0f);
}