-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
76 lines (62 loc) · 1.66 KB
/
main.py
File metadata and controls
76 lines (62 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import random as rnd
import matplotlib.pyplot as plt
import math
plt.ylim(-10,10)
plt.xlim(-10,10)
plt.gca().set_aspect('equal', adjustable='box')
print("Input number of repetitions")
n = int(input())
#number of point in the circle
p_in = 0
#number of all points
p_all = 0
Xvalues = [None]
Yvalues = [None]
XvaluesIN = [None]
YvaluesIN = [None]
for i in range(n):
#generate random number
x = rnd.uniform(-10,10)
y = rnd.uniform(-10,10)
if(i % 10 == 0):
#write percentage
percentage = (i*100)/n
print(str(percentage) + " %")
#check distance
d = math.sqrt((x*x)+(y*y))
if(d < 10):
#set point
#IN CIRCLE
p_in += 1
p_all += 1
XvaluesIN.append(x)
YvaluesIN.append(y)
else:
#set point
#IN SQUARE
p_all += 1
Xvalues.append(x)
Yvalues.append(y)
if(len(XvaluesIN) > 5000000 or len(Xvalues) > 5000000):
#after some time there might be to much RAM USSAGE
print("scattering points IN TO PREVENT RAM OVERUSSAGE")
plt.scatter(XvaluesIN,YvaluesIN,1,c='#ff0000')
print("scattering points OUT TO PREVENT RAM OVERUSSAGE")
plt.scatter(Xvalues,Yvalues,1,c='#00ff00')
Xvalues = [None]
Yvalues = [None]
XvaluesIN = [None]
YvaluesIN = [None]
print("scattering points IN")
plt.scatter(XvaluesIN,YvaluesIN,1,c='#ff0000')
print("scattering points OUT")
plt.scatter(Xvalues,Yvalues,1,c='#00ff00')
print("counting PI")
pi = (4 * p_in)/p_all
s = "PI" + str(pi)
plt.xlabel(s)
save_i = "S_REP_" + str(n) + ".png"
print("showing image")
plt.show()
print("saving image")
plt.savefig(save_i)