netlogopy 0.0.14__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
netlogopy/netlogopy.py ADDED
@@ -0,0 +1,143 @@
1
+ import copy
2
+ import nl4py,time,copy
3
+ import os
4
+
5
+ global list_pyturtle
6
+ global list_street
7
+
8
+ list_pyturtle=[]
9
+ list_street=[]
10
+
11
+ def netlogoshow(n,word):
12
+ c = "netlogoshow "+list2nllist([word])
13
+ c = n.report(c)
14
+ return c
15
+ def resize_world(n,x0,xf,y0,yf):
16
+ c = "resize_world "+list2nllist([x0,xf,y0,yf])
17
+ c = n.report(c)
18
+ return c
19
+ def list2nllist(lis):
20
+ s="["
21
+ for i in lis:
22
+ if type(i) == str:
23
+ s+=' "'+i+'" '
24
+ else :
25
+ s+=' '+str(i)+' '
26
+ s+="]"
27
+ return s
28
+ def set_background(n,image):
29
+ c = "set_background "+list2nllist([image])
30
+ c = n.report(c)
31
+ return c
32
+ def de_copy(a):
33
+ return copy.deepcopy(a)
34
+ def run_netlogo(netlogo_home="C:/Program Files/NetLogo 6.2.2"):
35
+
36
+ nl4py.initialize(netlogo_home)
37
+ nl4py.startServer(netlogo_home)
38
+ model = os.path.dirname(__file__)+"/netlogopy.nlogo"
39
+ n=nl4py.NetLogoApp()
40
+ n.openModel(model)
41
+ n.command("setup")
42
+ return n
43
+ def distancebetween(n,fromm=0,target=1):
44
+ id_fromm=fromm.id
45
+ id_target=target.id
46
+ c = "distanceto "+list2nllist([id_fromm,id_target])
47
+ c = n.report(c)
48
+ return c
49
+
50
+ def getxyturtle(n,turtle):
51
+ id_turtle=turtle.id
52
+ c = "getxyturtle "+list2nllist([id_turtle])
53
+ c = n.report(c)
54
+ c=eval(c)
55
+ return c
56
+
57
+ class n_model:
58
+ def __init__(self,netlogo_home="C:/Program Files/NetLogo 6.2.2"):
59
+ pass
60
+ def gui(self,netlogo_home="C:/Program Files/NetLogo 6.2.2"):
61
+ nl4py.initialize(netlogo_home)
62
+ nl4py.startServer(netlogo_home)
63
+ model = "./netlogopy.nlogo"
64
+ self=nl4py.NetLogoApp()
65
+ self.openModel(model)
66
+ self.command("setup")
67
+
68
+ return self
69
+
70
+ class turtle():
71
+ def __init__(self,n):
72
+ self.id= id
73
+ self.n= n
74
+ def distanceto(self,target=1):
75
+ id_fromm=self.id
76
+ id_target=target.id
77
+ c = "distanceto "+list2nllist([id_fromm,id_target])
78
+ c = self.n.report(c)
79
+ # idd = int(c[:-2])
80
+ return c
81
+
82
+ def face_to(self,target=1):
83
+ id_fromm=self.id
84
+ id_target=target.id
85
+ c="faceto "+list2nllist([id_fromm,id_target])
86
+ c=self.n.report(c)
87
+ idd= int(c[:-2])
88
+ return idd
89
+ def move_to(self,id_target):
90
+ fr=self.id
91
+ c="moveto "+list2nllist([fr,id_target.id])
92
+ c=self.n.report(c)
93
+
94
+ def hideturtle(self):
95
+ turtleid=self.id
96
+ c="hideturtle "+list2nllist([turtleid])
97
+ self.n.report(c)
98
+ def dieturtle(self):
99
+ turtleid=self.id
100
+ c="dieturtle "+list2nllist([turtleid])
101
+ self.n.report(c)
102
+ def set_shape(self,shape):
103
+ turtleid=self.id
104
+ c="set_shape "+list2nllist([turtleid,shape])
105
+ self.n.report(c)
106
+ def setxy(self,x,y):
107
+ turtleid=self.id
108
+ c="turtle_setxy "+list2nllist([turtleid,x,y])
109
+ self.n.report(c)
110
+
111
+
112
+ def fd(self,repeat=1):
113
+ fr=self.id
114
+ c="fdfd "+list2nllist([fr,repeat])
115
+ self.n.report(c)
116
+
117
+ class street :
118
+ def __init__(self, n,fromm=0,too=1,label="street",labelcolor=0,color=0,shape="aa",thickness=0.5):
119
+ fromm=fromm.id
120
+ too=too.id
121
+ self.id = id
122
+ self.create_street_ft(n,fromm,too,label,labelcolor,color,shape,thickness)
123
+ def create_street_ft(self,n,fromm=20,too=10,label="street",labelcolor=0,color=0,shape="aa",thickness=0.5):
124
+ c="create-street-ft "+list2nllist([fromm,too,label,labelcolor,color,shape,thickness])
125
+
126
+ c=n.report(c)
127
+ self.id= c
128
+ list_street.append(self)
129
+ return self
130
+
131
+ class pyturtle(turtle) :
132
+ def __init__(self, n,x=0,y=0,shape="car",size_shape=4,color=0,name="zn",labelcolor=0,fields={}):
133
+
134
+ super().__init__(n)
135
+ self.__dict__.update(fields)
136
+ self.create_pyturtle_xyid(n,x,y,shape,size_shape,color,name,labelcolor)
137
+
138
+ def create_pyturtle_xyid(self,n,x,y,shape,size_shape,color,name,labelcolor,):
139
+ c="create-pyturtle-xyid "+list2nllist([x,y,shape,size_shape,color,name,labelcolor])
140
+ c=n.report(c)
141
+ self.id= int(c[:-2])
142
+ list_pyturtle.append(self)
143
+ return self