このスケッチは、乱数のガウス分布に関連付けられたxおよびy位置で楕円を描画します。
randomGaussian distribution
Math Data
View Source Code
/*
* @name Random Gaussian
* @arialabel Translucent white circles are drawn in a line left and right multiple times until they overlap to form a white streak
* @frame 720,400
* @description This sketch draws ellipses with x and y locations tied to a gaussian distribution of random numbers.
* <br><br><small><em>This example is ported from the <a href="https://processing.org/examples/randomgaussian.html">Random Gaussian example</a>
* on the Processing website</em></small>
*/
function setup() {
// createCanvas(720, 400);
createCanvas(windowWidth, windowHeight);
background(0);
}
function draw() {
// Get a gaussian random number w/ mean of 0 and standard deviation of 1.0
let val = randomGaussian();
let sd = 60; // Define a standard deviation
let mean = width/2; // Define a mean value (middle of the screen along the x-axis)
let x = ( val * sd ) + mean; // Scale the gaussian random number by standard deviation and mean
noStroke();
fill(255, 10);
ellipse(x, height/2, 32, 32); // Draw an ellipse at our "normal" random location
}
License
Source code is available on GitHub p5.js website legacy.
All examples are licensed under CC BY-NC-SA 4.0.