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/73964e26cf876d9dbc8453744c691000 to your computer and use it in GitHub Desktop.
Save aadebdeb/73964e26cf876d9dbc8453744c691000 to your computer and use it in GitHub Desktop.
random on circle with p5.js
// Please run on p5.js Web Editor or OpenProcessing.
// https://editor.p5js.org/
// https://www.openprocessing.org/
function randomOnCircle() {
const theta = 2.0 * Math.PI * Math.random();
return [Math.cos(theta), 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 = randomOnCircle();
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