Javascript 如何使坐标图呈螺旋形
我想用python代码或javascript在螺旋线上创建一组坐标。 像这个 谁能告诉我怎么做吗?给你Javascript 如何使坐标图呈螺旋形,javascript,python,Javascript,Python,我想用python代码或javascript在螺旋线上创建一组坐标。 像这个 谁能告诉我怎么做吗?给你 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 t
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))
导入数学
#定义变量并创建网格
a=0
b=2
轮数=5
#网格的大小
y_max,x_max=100100
#网格中心
origo_y,origo_x=50,50
#网格中的每个元素都是真正唯一的元素
#如果网格是这样创建的
#不要使用例如[[“”]*x\u max]*y\u max
栅格=[“”表示范围内的i(x_max)]表示范围内的j(y_max)]
对于范围内的角度(轮数*360):
#螺旋线的计算
rads=数学弧度(角度)
r=a+b*rads
y=r*math.sin(rads)
x=r*math.cos(rads)
x_坐标=origo_x+圆(x)
y_坐标=origo_y+圆(y)
如果(0)对不起,我不知道。无论如何谢谢你!!