Last active
February 2, 2020 13:53
-
-
Save aadebdeb/73964e26cf876d9dbc8453744c691000 to your computer and use it in GitHub Desktop.
random on 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 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