LoginSignup
0
0

More than 3 years have passed since last update.

P5.js 日本語リファレンス(createGraphics)

Last updated at Posted at 2020-05-11

このページでは「P5.js 日本語リファレンス」 の createGraphics関数を説明します。

createGraphics()

説明文

新しい p5.Graphics オブジェクト(グラフィックスバッファオブジェクト)を作成して返します。画面外のグラフィックバッファに描画する必要がある場合はこの関数を使用します。 2つのパラメータは、ピクセル単位で幅と高さを定義します。

構文

createGraphics(w, h, [renderer])

パラメタ

  • w

    Number:グラフィックバッファの幅

  • h

    Number:グラフィックバッファの高さ

  • renderer

    定数:P2D または WEBGL デフォルトはP2Dです(オプション)

戻り値

p5.Graphics:グラフィックバッファ

let pg;
function setup() {
  createCanvas(100, 100);
  // p5.Graphics (Graphics Buffer Object)の生成
  pg = createGraphics(100, 100);
}

function draw() {
  background(200, 250, 0); // 黄緑色
  pg.background(150); // グレー
  pg.noStroke() ;

  // pgの中央に幅50、縦50で円を描画する
  pg.ellipse(pg.width / 2, pg.height / 2, 50, 50);

  // pgの左上座標を(50,50)にしてpgを描画する
  image(pg, 50, 50);

  // pgの左上座標を(0,0)、幅50縦50に縮小してpgを描画する
  image(pg, 0, 0, 50, 50);
}

実行結果

p5Graphics.png

著作権

p5.js was created by Lauren McCarthy and is developed by a community of collaborators, with support from the Processing Foundation and NYU ITP. Identity and graphic design by Jerel Johnson.

ライセンス

Creative Commons(CC BY-NC-SA 4.0) に従います。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0