LoginSignup
0
0

More than 3 years have passed since last update.

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

Last updated at Posted at 2020-06-16

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

loadPixels()

説明文

表示ウィンドウのピクセルデータをpixels配列に読み込みます。この関数は pixels配列の読み取りまたは書き込みの前に必ず呼び出す必要があります。 pixels配列が操作されたとき、または set() が呼び出されたときは常に loadPixels() を呼び出す必要があります。

構文

loadPixels()

例1

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

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

  image(img, 0, 0, width, height);

  let d = pixelDensity();

  // halfImageのサイズは dが1のとき 4 * (300*1) * (200*1/2) = 120000
  let halfImage = 4 * (width * d) * (height * d / 2);

  // pixels配列にキャンバス上の画像(サイズ:300x200x4)を読み込む
  loadPixels() ;

  // 画像の上半分(0~halfImage分)を画像の下半分に設定します
  for (let i = 0; i < halfImage; i++) {
    pixels[i + halfImage] = pixels[i];
  }

  // キャンバス上の画像を更新します
  updatePixels() ;
}

実行結果

著作権

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