push

def setup
  background(220)
  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
end
def setup
  background(220)
  ellipse(0, 50, 33, 33)       # Left circle
  push do                      # Start a new drawing state
    strokeWeight(10)
    fill(204, 153, 0)
    ellipse(33, 50, 33, 33)    # Left-middle circle
    push do                    # Start another new drawing state
      stroke(0, 102, 153)
      ellipse(66, 50, 33, 33)  # Right-middle circle
    end                        # Restore previous state
  end                          # Restore original state
  ellipse(100, 50, 33, 33)     # Right circle
end

p5.jsリファレンス(参考情報)

[p5.js] push

概要

描画スタイルや座標系などの設定を保存します。

書式

push
push do ... end

引数

引数名内容備考オプションデフォルト値
...ブロック任意の処理

戻値

なし

備考

・「push do ~ end」は「push ~ pop」を Ruby風にアレンジした構文です。
・ブロック引数を指定する「push do ~ end」構文を用いない場合は、
 必ず popメソッドとペアで使用してください。

関連

pop