GSDP:GAM100/CProcessing/scaleY()

From Inside
< GSDP:GAM100‎ | CProcessing
Revision as of 12:59, 13 October 2019 by >Zachary.logsdon
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

scaleY()

Description

Similar to scale(), but only changes scale on the Y axis by a scalar. X axis does not change. Scalar must be non-zero and positive.

Parameters

scaleY(float scalar)

  • scalar - (float) the amount to scale the canvas by

Example

// Create variable to keep track of scale
// IMPORTANT: initialize to 1 because scale should not be 0
static float counter = 1;

void update()
{
     // Expected behavior: Camera will stretch and squish on the Y axis

     // Clear screen every frame
     background(color(255, 0, 0, 255));

     int zoom = mouseWheel();  // 1 zooms in, -1 zooms out
     float zoom_amount = 0.1f; // Small steps to smooth zooming

     if (zoom > 0)
     {
          ++counter;
     }
     else if (zoom < 0)
     {
          --counter;
     }

     // Change the scale of the canvas every frame
     scaleY(counter * zoom_amount);

     // Fixed points
     // Note: some parameters are multiplied by 1.0f to convert int to float
     rect(0, 0, 100, 50);				   // Draw rect clouds at the top left corner
     rect(canvasWidth * 1.0f - 100, 0, 100, 50);	           // Draw rect clouds at the top right corner
     rect(0, canvasWidth * 1.0f - 200, canvasWidth * 1.0f, 200); // Draw the ground
     ellipse(canvasWidth / 2.0f, canvasWidth / 2.0f, 20, 20);	   // Draw the sun in the middle of the screen
}

Related

Personal tools
Namespaces

Variants
Actions
Navigation
NameSpaces:>
Tools
Dynamic:>