Difference between revisions of "GSDP:GAM100/CProcessing/scale()"

From Inside
Jump to: navigation, search
>Zachary.logsdon
>Zachary.logsdon
 
Line 50: Line 50:
 
==== Related ====                             
 
==== Related ====                             
 
* [[GSDP:GAM100/CProcessing                          |Main Page                ]]
 
* [[GSDP:GAM100/CProcessing                          |Main Page                ]]
 +
* [[GSDP:GAM100/CProcessing/setWindowTitle()          |setWindowTitle()        ]]                                     
 
* [[GSDP:GAM100/CProcessing/background()              |background()            ]]
 
* [[GSDP:GAM100/CProcessing/background()              |background()            ]]
 
* [[GSDP:GAM100/CProcessing/fill()                    |fill()                  ]]
 
* [[GSDP:GAM100/CProcessing/fill()                    |fill()                  ]]
Line 58: Line 59:
 
* [[GSDP:GAM100/CProcessing/size()                    |size()                  ]]
 
* [[GSDP:GAM100/CProcessing/size()                    |size()                  ]]
 
* [[GSDP:GAM100/CProcessing/fullscreen()              |fullscreen()            ]]
 
* [[GSDP:GAM100/CProcessing/fullscreen()              |fullscreen()            ]]
 +
* [[GSDP:GAM100/CProcessing/fullscreenAdvanced()      |fullscreenAdvanced()    ]]
 +
* [[GSDP:GAM100/CProcessing/blendMode()              |blendMode()              ]]
 
* [[GSDP:GAM100/CProcessing/cursor()                  |cursor()                ]]
 
* [[GSDP:GAM100/CProcessing/cursor()                  |cursor()                ]]
 
* [[GSDP:GAM100/CProcessing/noCursor()                |noCursor()              ]]
 
* [[GSDP:GAM100/CProcessing/noCursor()                |noCursor()              ]]

Latest revision as of 12:58, 13 October 2019

scale()

Description

The function scale() uniformly changes the scale of the canvas using by a given scalar. Scalar must be non-zero and positive.

Parameters

scale(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 zoom in and out, depending on the mouse wheel

     // 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
     scale(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:>