Last active
February 2, 2020 13:53
-
-
Save aadebdeb/2398c5f2464663c8721bdbd6c9a29bd8 to your computer and use it in GitHub Desktop.
random in circle with p5.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Please run on p5.js Web Editor or OpenProcessing. | |
// https://editor.p5js.org/ | |
// https://www.openprocessing.org/ | |
function randomInCircle() { | |
const theta = 2.0 * Math.PI * Math.random(); | |
const radius = Math.sqrt(Math.random()); | |
return [radius * Math.cos(theta), radius * Math.sin(theta)]; | |
} | |
function setup() { | |
createCanvas(300, 300); | |
noLoop(); | |
} | |
function draw() { | |
const halfSize = [0.5 * width, 0.5 * height]; | |
background(240); | |
fill(0); | |
noStroke(); | |
for(let i = 0; i < 1000; i++) { | |
const pos = randomInCircle(); | |
circle( | |
halfSize[0] * (1.0 + 0.75 * pos[0]), | |
halfSize[1] * (1.0 + 0.75 * pos[1]), | |
2.0 | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment