P5 Python Docs
  • Getting Started
  • Simple mode
  • Reference
    • Shapes
      • 2D
        • point()
        • line()
        • rect()
        • square()
        • triangle()
        • circle()
        • ellipse()
        • arc()
        • quad()
        • beginShape()
      • 3D
        • plane()
        • box()
        • sphere()
        • cone()
        • cylinder()
        • ellipsoid()
        • torus()
    • Controlling the environment
      • coordinateMode()
      • rectMode()
      • ellipseMode()
      • frameRate()
      • setup()
      • draw()
    • Built-in Variables
      • Environment
      • Keyboard
      • Mouse
    • Built-in Functions
      • keyIsDown()
      • millis()
      • second()
      • minute()
      • hour()
      • translate()
      • rotate()
      • createSlider()
      • createGraphics()
      • createVector()
    • Events
      • Keyboard
        • keyPressed()
        • keyReleased()
      • Mouse
        • mouseMoved()
        • mouseDragged()
        • mousePressed()
        • doubleClicked()
        • mouseWheel()
    • Text
      • text()
      • textSize()
      • textAlign()
    • Math
      • drawTickAxes()
      • random()
      • randomGaussian()
      • dist()
      • linmap()
      • bounce()
      • wave()
    • Colour and Outline
      • colorMode()
      • fill()
      • stroke()
      • strokeWeight()
      • background()
    • Images & Audio
      • loadImage() and image()
      • loadSound()
    • 3D Controls
      • orbitControl()
      • translate()
      • rotateZ()
      • rotateX()
      • rotateY()
      • scale()
Powered by GitBook
On this page
  • Example
  • Syntax
  • Full Example
  • Description
  1. Reference
  2. 3D Controls

scale()

Scales Object in 3D from the Origin

PreviousrotateY()

Last updated 2 years ago

Example

Syntax

scale(x, y, z)
Input
Description

x

scaling factor of edges and faces in the x-direction

y

scaling factor of edges and faces in the y-direction

z

scaling factor of edges and faces in the z-direction

Full Example

Example Full Code
def setup():
  createCanvas(300,300, WEBGL)

def draw():
  background(255, 79, 132)
  fill(112, 88, 255)
  stroke(176, 235, 51)
  strokeWeight(2)
  orbitControl()
  # draw3DAxes(100, (100, 50, 20))
  rotateX(frameCount/2)
  rotateZ(frameCount)
  sX = 1+0.75*cos(frameCount)
  sY = 1+0.25*sin(frameCount)
  sZ = 1+0.5*sin(frameCount)
  scale(sX, sY, sZ)
  torus(75, 15)
  # rotateY(-2*frameCount)
  cone(30, 30)

Description

Increases or decreases the size of a shape by expanding or contracting its edges and faces in a specific direction. Objects always scale from their relative origin to the coordinate system. Scale values are specified as decimal percentages. For example, the function call scale(2.0, 1, 1) increases the x dimension of a shape by 200%.

If a negative number was specified, the shape will flip, then scale. For example, scale(-2.0, 1, 1) first flips the shape, then increases the dimensions by 200%.

Find these documents helpful? Let the people who made them help your child learn to code at !

We'd love to hear your Feedback/Comments .

Strivemath
here
Original Shape (Front View)
Original Shape (Side View)
scaling by 1.5 in x-direction
scaling by 0.5 in y-direction
scaling by 3 in z-direction