Skip to content

Instantly share code, notes, and snippets.

@drbh
Last active April 3, 2020 19:28
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 drbh/6a5551bb36745c07c621d337df6cc155 to your computer and use it in GitHub Desktop.
Save drbh/6a5551bb36745c07c621d337df6cc155 to your computer and use it in GitHub Desktop.
Make circles and skew the points for jagged loops
const range = (start, end, length = end - start) =>
Array.from({ length }, (_, i) => start + i);
const randomNumber = (min, max) => {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
const points_in_circle = (r, n) => {
var result = [];
for (let x of range(0, n)) {
let a = Math.cos(((2 * Math.PI) / n) * x) * r;
let b = Math.sin(((2 * Math.PI) / n) * x) * r;
result.push([a, b]);
}
return result;
};
let pts = points_in_circle(5, 30);
pts.forEach( (value, index) => {
let n = randomNumber(8,12)
let rise = pts[index][0]
let run = pts[index][1]
pts[index] = rise*(n*0.1), run*(n*0.1)
})
import math
import matplotlib.pyplot as plt
import random
pi = math.pi
def points_in_circle(r, n=100):
return [(math.cos(2*pi/n*x)*r, math.sin(2*pi/n*x)*r) for x in range(0, n+1)]
def slope_to_zero(rs,ru):
return rs / ru
pts = points_in_circle(5,30)
for i, val in enumerate(pts):
n = random.randrange(8,12)
rise, run = pts[i]
pts[i] = rise*(n*0.1), run*(n*0.1)
x = [ x[0] for x in pts]
y = [ x[1] for x in pts]
plt.scatter(x,y)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment