Help with homework? for the manufacture of a spirograph

SO during the rest week our teacher gave us a small project requiring Spirograph, here is the code that he helped us write before

from graphics import *
from math import *

def ar(a):
    return a*3.141592654/180

def main():
    x0 = 100
    y0 = 100
    startangle = 60
    stepangle = 120
    radius = 50

    win = GraphWin()

    p1 = Point(x0 + radius * cos(ar(startangle)), y0 + radius * sin(ar(startangle)))

    for i in range(stepangle+startangle,360+stepangle+startangle,stepangle):
        p2 = Point(x0 + radius * cos(ar(i)), y0 + radius * sin(ar(i)))
        Line(p1,p2).draw(win)
        p1 = p2

    input("<ENTER> to quit...")
    win.close()

main()

he then wants us to develop a program that sequentially draws 12 equilateral triangles (each time turning the triangle 30 degrees through a full circle 360). This can be achieved by "step" the STARTANGLE parameter. My question is: I was fixated on where to go from here, what does he mean by β€œstep”? I suppose to do some kind of cycle, is it possible that someone can give me a push on the right step?

+4
source share
1 answer

, matplotlib. . , .

from math import radians, sin, cos 
import matplotlib.pyplot as plt

startAngle = 0 
stepAngle = 30
origin = (0,0)

points = []
points.append(origin)
points.append((cos(radians(startAngle)), sin(radians(startAngle))))

for i in range(startAngle + stepAngle, 360 + stepAngle, stepAngle):
    x = cos(radians(i))
    y = sin(radians(i))
    points.append((x,y))
    points.append(origin)
    points.append((x,y))

x,y = zip(*points) #separate the tupples into x and y coordinates. 

plt.plot(x,y) #plots the points, drawing lines between each point
plt.show()

plt.plot ​​. , , . enter image description here

+1

Source: https://habr.com/ru/post/1528205/


All Articles