Skip to content

Instantly share code, notes, and snippets.

@aadebdeb
Last active February 2, 2020 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aadebdeb/2398c5f2464663c8721bdbd6c9a29bd8 to your computer and use it in GitHub Desktop.
Save aadebdeb/2398c5f2464663c8721bdbd6c9a29bd8 to your computer and use it in GitHub Desktop.
random in circle with p5.js
// 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