Skip to content

Instantly share code, notes, and snippets.

View bohnacker's full-sized avatar

Hartmut Bohnacker bohnacker

  • Stuttgart, Germany
View GitHub Profile
@bohnacker
bohnacker / circleOfDots_Spiral.js
Created January 24, 2024 12:01
Calculate positions of dots to draw a filled circle made of dots.
// Calling this function will return a function that gives you the position of the dot at an index.
// This version uses the golden angle to create a tightly packed spiral.
// This is made as a closure so that the array of positions is only calculated once.
//
// Usage:
// let getDotPosition = initCircleOfDots_Spiral();
// let p = getDotPosition(50);
//
// This will return a point in the format { x: 2.9227, y: 1.9894 }
// The distance between the dots is approximately 1, so you probably have to scale the positions.
@bohnacker
bohnacker / circleOfDots_SimpleRings.js
Created January 24, 2024 12:06
Calculate positions of dots to draw a filled circle made of dots. This version creates simple rings. The outer ring will be partially filled most of the time.
// Calling this function will return a function that gives you the position of the dot at an index.
// This version creates rings of dots. The outer ring will be partially filled most of the time.
// This is made as a closure so that the array of positions is only calculated once.
//
// Usage:
// let getDotPosition = initCircleOfDots_SimpleRings();
// let p = getDotPosition(50);
//
// This will return a point in the format { x: 1.4724, y: 3.7191 }
// The distance between the dots is approximately 1, so you probably have to scale the positions.
@bohnacker
bohnacker / circleOfDots_AdvancedRings.js
Last active April 29, 2024 08:33
Calculate positions of dots to draw a filled circle made of dots. This version creates rings in a more advanced way, so that the outer ring is always completely filled.
// Calling this function will return a function that gives you the position of the dot at an index.
// You must also pass the total number of dots of the circle to this function to calculate correctly.
//
// This version creates rings in a more advanced way, so that the outer ring is always completely filled.
// This is made as a closure so that the array of positions is only calculated once.
//
// Usage:
// let getDotPosition = initCircleOfDots_AdvancedRings();
// let p = getDotPosition(50, 100);
//