createImage() 関数は、操作するための新しいピクセルバッファを提供します。この例では、画像のグラデーションを作成します。
createImage pixels
Image Drawing
View Source Code
/*
* @name Create Image
* @arialabel Black background with a blue gradient square on the left. Another blue gradient square follows the user’s mouse as it moves
* @description The createImage() function provides a fresh buffer of pixels to
* play with. This example creates an image gradient.
*/
let img; // Declare variable 'img'.
function setup() {
// createCanvas(720, 400);
createCanvas(windowWidth, windowHeight);
img = createImage(230, 230);
img.loadPixels();
for (let x = 0; x < img.width; x++) {
for (let y = 0; y < img.height; y++) {
let a = map(y, 0, img.height, 255, 0);
img.set(x, y, [0, 153, 204, a]);
}
}
img.updatePixels();
}
function draw() {
background(0);
image(img, 90, 80);
image(img, mouseX - img.width / 2, mouseY - img.height / 2);
}
License
Source code is available on GitHub p5.js website legacy.
All examples are licensed under CC BY-NC-SA 4.0.