Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Random night stars with python turtle

# Random night stars with python turtle 
import turtle as tu
import random


sc = tu.Screen()
sc.bgcolor("black")

bn = tu.Turtle()
bn.pensize(3)
bn.color("blue", "blue")
bn.speed(0)
li = []

def star(lenth):
      bn.begin_fill()
      for i in range(5):
            bn.fd(lenth)
            bn.rt(144)
      bn.end_fill()

for i in range(120):
      x = random.randint(-300, 300)
      y = random.randint(-300, 300)
      bn.penup()
      bn.goto(x, y)
      li.append(bn.pos())
      bn.pendown()
      fn = random.randint(5, 22)
      for j in li:
            if (abs(bn.pos()) - abs(j)) <= fn + 10 :
                  #print(f"pos >{j}")
                  continue
      
      star(fn)


sc.exitonclick()
 
PREVIOUS NEXT
Tagged: #Random #night #stars #python #turtle
ADD COMMENT
Topic
Name
1+2 =