舞台

3. cheatsheet

3.4. 存储设置


push()

示例:

▶️运行示例代码




function setup() {
ellipse(0, 50, 33, 33); // Left circle
push(); // Start a new drawing state
strokeWeight(10);
fill(204, 153, 0);
translate(50, 0);
ellipse(0, 50, 33, 33); // Middle circle
pop(); // Restore original state
ellipse(100, 50, 33, 33); // Right circle
}

舞台区显示的画布内容如下:

示例:

▶️运行示例代码




function setup() {
ellipse(0, 50, 33, 33); // Left circle
push(); // Start a new drawing state
strokeWeight(10);
fill(204, 153, 0);
ellipse(33, 50, 33, 33); // Left-middle circle
push(); // Start another new drawing state
stroke(0, 102, 153);
ellipse(66, 50, 33, 33); // Right-middle circle
pop(); // Restore previous state
pop(); // Restore original state
ellipse(100, 50, 33, 33); // Right circle
}

舞台区显示的画布内容如下:



Description

The push() function saves the current drawing style settings and transformations, while pop() restores these settings. Note that these functions are always used together. They allow you to change the style and transformation settings and later return to what you had. When a new state is started with push(), it builds on the current style and transform information. The push() and pop() functions can be embedded to provide more control. (See the second example for a demonstration.)

push() stores information related to the current transformation state and style settings controlled by the following functions: fill()noFill()noStroke()stroke()tint()noTint()strokeWeight()strokeCap()strokeJoin()imageMode()rectMode()ellipseMode()colorMode()textAlign()textFont()textSize()textLeading()applyMatrix()resetMatrix()rotate()scale()shearX()shearY()translate()noiseSeed().

In WEBGL mode additional style settings are stored. These are controlled by the following functions: setCamera()ambientLight()directionalLight()pointLight()texture()specularMaterial()shininess()normalMaterial() and shader().

Syntax

push()

标签: