xxxxxxxxxx
let img; //画像データ
//プレロード
function preload() {
//画像をロード
img = loadImage('./photo.jpg');
}
function setup() {
createCanvas(windowWidth, windowHeight);
//画像をリサイズ
img.resize(width, height);
//背景を黒に
background(0);
//四角形の基準点を中心に
rectMode(CENTER);
}
function draw() {
for (let i = 0; i < 100; i++) { //100倍速
//色を取得する位置をランダムに決定
let x = int(random(width));
let y = int(random(height));
//指定した場所の色を取得
let col = img.get(x, y);
noStroke();
//色の彩度を円の直径に反映させる
let rotation = map(saturation(col), 0, 255, 0, 360);
//大きさは明度に反映させる
let length = map(brightness(col), 0, 255, 0, 100);
//色に透明度を加える
fill(red(col), green(col), blue(col), 128);
push();
translate(x, y);
rotate(radians(rotation));
//四角形を描画
rect(0, 0, 2, length);
pop();
}
}