2017-08-10 62 views

回答

1

在這裏你去

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)) 

我不知道這個網站是爲要求寬泛,您的問題,但作爲一個編碼問題,這是挺有意思的。

+0

對不起,我不知道。不管怎樣,謝謝你!! – ehaannnn