Scale

Scale by Denis Grutze.

Paramenters for the scale() function are values specified as decimal percentages. For example, the method call scale(2.0) will increase the dimension of the shape by 200 percent. Objects always scale from the origin.

 
float a = 0.0;
float s = 0.0;

void setup() {
  size(640, 360);
  noStroke();
  rectMode(CENTER);
  frameRate(30);
}

void draw() {
  
  background(102);
  
  a = a + 0.04;
  s = cos(a)*2;
  
  translate(width/2, height/2);
  scale(s); 
  fill(51);
  rect(0, 0, 50, 50); 
  
  translate(75, 0);
  fill(255);
  scale(s);
  rect(0, 0, 50, 50);       
}

Functions Used

fill()

Sets the color used to fill shapes

Learn More
size()

Defines the dimension of the display window width and height in units of pixels

Learn More
rectMode()

Modifies the location from which rectangles are drawn by changing the way in which parameters given to rect() are intepreted

Learn More
scale()

Increases or decreases the size of a shape by expanding and contracting vertices

Learn More
setup()

The setup() function is run once, when the program starts

Learn More
cos()

Calculates the cosine of an angle

Learn More
rect()

Draws a rectangle to the screen

Learn More
frameRate

The system variable frameRate contains the approximate frame rate of a running sketch

Learn More
translate()

Specifies an amount to displace objects within the display window

Learn More
draw()

Called directly after setup(), the draw() function continuously executes the lines of code contained inside its block until the program is stopped or noLoop() is called

Learn More
noStroke()

Disables drawing the stroke (outline)

Learn More
background()

The background() function sets the color used for the background of the Processing window

Learn More