Reputation: 1
I'd like to make bunch of coordinate on spiral line with python code or javascript. like this one Archimedean_spiral
Could anyone tell me how to do that?
Upvotes: 0
Views: 145
Reputation: 26
Here you go
import math
# Define variables and create the grid
a = 0
b = 2
rounds = 5
# Size of the grid
y_max, x_max = 100, 100
# Center of the grid
origo_y, origo_x = 50, 50
# Every element in the grid is truly unique element
# If the grid is created like this
# Don't use for example [[" "]*x_max]*y_max
grid = [[" " for i in range(x_max)] for j in range(y_max)]
for angle in range(rounds*360):
# Calculations for the spiral
rads = math.radians(angle)
r = a + b * rads
y = r * math.sin(rads)
x = r * math.cos(rads)
x_coord = origo_x + round(x)
y_coord = origo_y + round(y)
if (0 <= x_coord < x_max) and (0 <= y_coord < y_max):
grid[y_coord][x_coord] = "#"
# Print the whole grid
for line in grid:
print("".join(line))
I don't know if this site is for asking questions broad as your's, but as a coding problem this was quite interesting.
Upvotes: 1