Skip to content

Instantly share code, notes, and snippets.

@blzzua
Created November 28, 2019 16:02
Show Gist options
  • Save blzzua/9536166d21101fea18df648764cbf449 to your computer and use it in GitHub Desktop.
Save blzzua/9536166d21101fea18df648764cbf449 to your computer and use it in GitHub Desktop.
реализация "звезды" на библиотеке graph
from graph import *
from math import sin, cos, atan, sqrt, pi
def cart2pol(x, y):
r = sqrt(x**2 + y**2)
phi = atan(y, x)
return (r, phi)
def pol2cart(r, phi):
x = r * cos(phi)
y = r * sin(phi)
return (x, y)
def star(centerx, centery, internal_radius, external_radius, ray_count = 24):
vertex_count = ray_count * 2
VERTEX_POLAR = [[external_radius if (i % 2 == 0) else internal_radius, \
(i * 2 * pi/vertex_count)] for i in range(vertex_count)]
VERTEX_CART = [pol2cart(*v) for v in VERTEX_POLAR]
# move center of star to ( centerx, centery )
center = (centerx, centery)
VERTEX_CART = [[sum(i) for i in zip(v, center)] for v in VERTEX_CART]
mypol = polygon(VERTEX_CART)
return mypol
if __name__ == '__main__':
"демонстрация. рисует разноцветные эллипсы"
from random import randrange
windowSize(1800, 1000)
canvasSize(1800, 1000)
max_x = 1800
max_y = 900
min_x = 10
min_y = 10
for i in range(30):
brushColor(randColor())
penColor(randColor())
(x1, y1) = (randrange(start=min_x, stop=max_x),
randrange(start=min_y, stop=max_y))
print("print center coord:",x1,y1)
radius1 = randrange(200, 250)
radius2 = radius1 + randrange(40, int(radius1 * 0.5 ) )
star(x1, y1, radius1, radius2, ray_count= randrange( min(int(radius2/20 ),30) ,30 ))
run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment