random work in python  

by SimonMong

import turtle
import random
import math

def rec(x, y):
    with open('my.csv', 'a', encoding='utf-8') as points:
        points.write(str(round(x, 3))+','+str(round(y, 3))+'\n')


p = 10
turtle.setup(640, 480, 200, 200)
turtle.pendown()
turtle.pensize(2)
turtle.pencolor("purple")
turtle.seth(0)
for i in range(1000):
    deltaX = random.uniform(-1, 1) * random.choice([-1, 1])
    deltaY = math.sqrt(1 - deltaX ** 2) * random.choice([-1, 1])
    x = turtle.xcor() + p*deltaX
    y = turtle.ycor() + p*deltaY
    turtle.setpos(x, y)
    rec(x, y)
turtle.done()

Created: 2 years, 5 months ago Last modified: 2 years, 5 months ago

0 0 184

Comments (0)

No comments yet