GSDP:GAM100/CProcessing/save()

From Inside
Jump to: navigation, search

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 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);
}

Related

Personal tools
Namespaces

Variants
Actions
Navigation
NameSpaces:>
Tools
Dynamic:>