Demo entry 6285307

ring-python

   

Submitted by anonymous on Oct 18, 2016 at 17:27
Language: Python 3. Code size: 876 Bytes.

from exturtle import *

from math import sin, cos, pi

def star(turtle, x, y, points, R, r):
	angle = (2 * pi) / points
	penup(turtle)
	goto(turtle, x + r * sin((- 0.5) * (angle)), y + r * cos((- 0.5) * (angle)))	
	for i in range(points):
		pendown(turtle)
		goto(turtle, x + R * sin(angle * i), y + R * cos(angle * i))
		goto(turtle, x + r * sin((i + 0.5) * (angle)), y + r * cos((i + 0.5) * (angle)))
		penup(turtle)

fred = Turtle()

star(fred, -300, -250, 5, 50, 20)
star(fred, -100, -250, 6, 50, 20)
star(fred, 100, -250, 7, 50, 20)
star(fred, 300, -250, 8, 50, 20)

def ring(turtle, cx, cy, Nstars, radius, points, R, r):
	angle = (2 * pi) / Nstars
	for i in range(Nstars):
		change_in_x = radius * sin(angle * i)
		change_in_y = radius * cos(angle * i)
		star(turtle, cx + change_in_x, cy + change_in_y, points, R, r)

ring(fred, 0, 100, 12, 150, 5, 25, 10)

mainloop()

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).