0
0

More than 3 years have passed since last update.

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

Last updated at Posted at 2020-06-16

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

copy()

説明文

キャンバスの領域の一部をキャンバスの別の領域にコピーします。または、srcImage パラメータで指定したコピー元画像からキャンバスにコピーします。コピー元領域とコピー先領域が同じサイズでない場合、指定されたコピー先領域に合わせてコピー元ピクセルのサイズが自動的に変更されます。

構文

copy(srcImage, sx, sy, sw, sh, dx, dy, dw, dh)

copy(sx, sy, sw, sh, dx, dy, dw, dh)

パラメタ

  • srcImage
    p5.Image|p5.Element:コピー元画像

  • sx
    Number:コピー元画像の左上隅のX座標

  • sy
    Number:コピー元画像の左上隅のY座標

  • sw
    Number:コピー元画像の幅

  • sh
    Number:コピー元画像の高さ

  • dx
    Number:コピー先画像の左上隅のX座標

  • dy
    Number:コピー先画像の左上隅のY座標

  • dw
    Number:コピー先画像の幅

  • dh
    Number:コピー先画像の高さ

例1

let img;

function preload() {
  img = loadImage('assets/mountain.jpg');
}

function setup() {
  createCanvas(300, 200);
  background(img);

  // Imgパラメータで指定したコピー元画像からキャンバスにコピーします。
  copy(img, 10, 30, 60, 40, 40, 100, 120, 80);
  stroke(255);
  noFill() ;
  //長方形はコピーされる領域を示します
  rect(10, 30, 60, 40);
}

実行結果

例2

let img;

function preload() {
  img = loadImage('assets/mountain.jpg');
}

function setup() {
  createCanvas(300, 200);
  background(img);

  // キャンバスの領域の一部をキャンバスの別の領域にコピーします。
  copy(10, 30, 60, 40, 40, 100, 120, 80);
  stroke(255);
  noFill() ;
  //長方形はコピーされる領域を示します
  rect(10, 30, 60, 40);
}

実行結果

著作権

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