tiledland 0.1.0__tar.gz
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.
- tiledland-0.1.0/LICENCE.md +9 -0
- tiledland-0.1.0/PKG-INFO +20 -0
- tiledland-0.1.0/docs/pypip-index.md +3 -0
- tiledland-0.1.0/pyproject.toml +22 -0
- tiledland-0.1.0/src/tiledland/.pytest_cache/.gitignore +2 -0
- tiledland-0.1.0/src/tiledland/.pytest_cache/CACHEDIR.TAG +4 -0
- tiledland-0.1.0/src/tiledland/.pytest_cache/README.md +8 -0
- tiledland-0.1.0/src/tiledland/.pytest_cache/v/cache/nodeids +1 -0
- tiledland-0.1.0/src/tiledland/.pytest_cache/v/cache/stepwise +1 -0
- tiledland-0.1.0/src/tiledland/__init__.py +14 -0
- tiledland-0.1.0/src/tiledland/agent.py +116 -0
- tiledland-0.1.0/src/tiledland/artist/__init__.py +309 -0
- tiledland-0.1.0/src/tiledland/artist/color.py +41 -0
- tiledland-0.1.0/src/tiledland/artist/support.py +152 -0
- tiledland-0.1.0/src/tiledland/artist/supportCairo.py +138 -0
- tiledland-0.1.0/src/tiledland/artist/webapp.py +0 -0
- tiledland-0.1.0/src/tiledland/game/moveit/__init__.py +0 -0
- tiledland-0.1.0/src/tiledland/game/pickndel/.pytest_cache/.gitignore +2 -0
- tiledland-0.1.0/src/tiledland/game/pickndel/.pytest_cache/CACHEDIR.TAG +4 -0
- tiledland-0.1.0/src/tiledland/game/pickndel/.pytest_cache/README.md +8 -0
- tiledland-0.1.0/src/tiledland/game/pickndel/.pytest_cache/v/cache/nodeids +1 -0
- tiledland-0.1.0/src/tiledland/game/pickndel/.pytest_cache/v/cache/stepwise +1 -0
- tiledland-0.1.0/src/tiledland/game/pickndel/__init__.py +18 -0
- tiledland-0.1.0/src/tiledland/game/pickndel/carrier.py +32 -0
- tiledland-0.1.0/src/tiledland/game/pickndel/master.py +223 -0
- tiledland-0.1.0/src/tiledland/game/pickndel/player.py +88 -0
- tiledland-0.1.0/src/tiledland/game/pickndel/world.py +253 -0
- tiledland-0.1.0/src/tiledland/geometry/__init__.py +20 -0
- tiledland-0.1.0/src/tiledland/geometry/basic.py +265 -0
- tiledland-0.1.0/src/tiledland/geometry/box.py +122 -0
- tiledland-0.1.0/src/tiledland/geometry/convex.py +281 -0
- tiledland-0.1.0/src/tiledland/geometry/grid.py +436 -0
- tiledland-0.1.0/src/tiledland/geometry/mesh.py +47 -0
- tiledland-0.1.0/src/tiledland/interface/ros.py +112 -0
- tiledland-0.1.0/src/tiledland/interface/web.py +0 -0
- tiledland-0.1.0/src/tiledland/pod.py +165 -0
- tiledland-0.1.0/src/tiledland/scene.py +490 -0
- tiledland-0.1.0/src/tiledland/tile.py +124 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Copyright © 2025, Guillaume LOZENGUEZ - Instut Mines-Telecom
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
The Software is provided “as is”, without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders X be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the Software.
|
|
8
|
+
Except as contained in this notice, the name of the Instut Mines-Telecom or Guillaume LOZENGUEZ shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from Guillaume LOZENGUEZ.
|
|
9
|
+
|
tiledland-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tiledland
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Polygon-based interconnected tiles to model an environment and mobile objects inside.
|
|
5
|
+
Author-email: Guillaume Lozenguez <guillaume.lozenguez@imt-nord-europe.fr>
|
|
6
|
+
Requires-Python: >=3.8
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
License-File: LICENCE.md
|
|
12
|
+
Requires-Dist: hacka
|
|
13
|
+
Requires-Dist: pycairo
|
|
14
|
+
Requires-Dist: pyyaml
|
|
15
|
+
Project-URL: Homepage, https://imt-mobisyst.github.io
|
|
16
|
+
|
|
17
|
+
# Tiled-Land: Polygon-based simulation engine.
|
|
18
|
+
|
|
19
|
+
Polygon-based interconnected tiles to model an environment and mobile objects inside.
|
|
20
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["flit_core >= 3.4"]
|
|
3
|
+
build-backend = "flit_core.buildapi"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "tiledland"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
authors = [
|
|
9
|
+
{ name="Guillaume Lozenguez", email="guillaume.lozenguez@imt-nord-europe.fr" },
|
|
10
|
+
]
|
|
11
|
+
description = "Polygon-based interconnected tiles to model an environment and mobile objects inside."
|
|
12
|
+
dependencies = [ "hacka", "pycairo", "pyyaml" ]
|
|
13
|
+
readme = "docs/pypip-index.md"
|
|
14
|
+
requires-python = ">=3.8"
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[project.urls]
|
|
22
|
+
Homepage = "https://imt-mobisyst.github.io"
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# pytest cache directory #
|
|
2
|
+
|
|
3
|
+
This directory contains data from the pytest's cache plugin,
|
|
4
|
+
which provides the `--lf` and `--ff` options, as well as the `cache` fixture.
|
|
5
|
+
|
|
6
|
+
**Do not** commit this to version control.
|
|
7
|
+
|
|
8
|
+
See [the docs](https://docs.pytest.org/en/stable/how-to/cache.html) for more information.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[]
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Basement:
|
|
2
|
+
from .geometry import Point, Line, Box, Convex, Grid
|
|
3
|
+
|
|
4
|
+
# core coponents:
|
|
5
|
+
from .agent import Agent
|
|
6
|
+
from .tile import Tile
|
|
7
|
+
from .scene import Scene
|
|
8
|
+
|
|
9
|
+
# rendering:
|
|
10
|
+
from .artist import Support, SupportSVG, SupportPNG, Artist
|
|
11
|
+
|
|
12
|
+
# interoperability:
|
|
13
|
+
from .interface import ros
|
|
14
|
+
from .interface import web
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
from .geometry import Point, Convex
|
|
2
|
+
from .pod import Podable, Pod
|
|
3
|
+
|
|
4
|
+
class Agent(Podable):
|
|
5
|
+
|
|
6
|
+
# Initialization Destruction:
|
|
7
|
+
def __init__( self, identifier= 0, group=0, position= Point(0.0, 0.0), shape= None):
|
|
8
|
+
self._id= identifier
|
|
9
|
+
self._group= group
|
|
10
|
+
self._tile= 0
|
|
11
|
+
self._center= Point( position.x(), position.y() )
|
|
12
|
+
self._shape= shape
|
|
13
|
+
if self._shape is None :
|
|
14
|
+
self._shape= Convex().initializeSquare(0.4)
|
|
15
|
+
self._matter= 10+group
|
|
16
|
+
|
|
17
|
+
# Accessor:
|
|
18
|
+
def group(self):
|
|
19
|
+
return self._group
|
|
20
|
+
|
|
21
|
+
def id(self):
|
|
22
|
+
return self._id
|
|
23
|
+
|
|
24
|
+
def tile(self):
|
|
25
|
+
return self._tile
|
|
26
|
+
|
|
27
|
+
def matter(self):
|
|
28
|
+
return self._matter
|
|
29
|
+
|
|
30
|
+
def position(self):
|
|
31
|
+
return self._center
|
|
32
|
+
|
|
33
|
+
def shape(self):
|
|
34
|
+
return self._shape
|
|
35
|
+
|
|
36
|
+
def body(self):
|
|
37
|
+
return self._shape.copy(self._center)
|
|
38
|
+
|
|
39
|
+
# Convex accessor :
|
|
40
|
+
def box(self):
|
|
41
|
+
return self.body().box()
|
|
42
|
+
|
|
43
|
+
def radius(self):
|
|
44
|
+
r= 0.0
|
|
45
|
+
zero= Point()
|
|
46
|
+
for p in self._shape._points :
|
|
47
|
+
d= zero.distance( p )
|
|
48
|
+
r= max( d, r )
|
|
49
|
+
return r
|
|
50
|
+
|
|
51
|
+
# Construction:
|
|
52
|
+
def setId(self, aInteger):
|
|
53
|
+
self._id= aInteger
|
|
54
|
+
return self
|
|
55
|
+
|
|
56
|
+
def setGroup(self, aInteger):
|
|
57
|
+
self._group= aInteger
|
|
58
|
+
return self
|
|
59
|
+
|
|
60
|
+
def setTile(self, aInteger):
|
|
61
|
+
self._tile= aInteger
|
|
62
|
+
return self
|
|
63
|
+
|
|
64
|
+
def setPosition(self, aPoint):
|
|
65
|
+
self._center= aPoint
|
|
66
|
+
return self
|
|
67
|
+
|
|
68
|
+
def setMatter(self, aInteger):
|
|
69
|
+
self._matter= aInteger
|
|
70
|
+
return self
|
|
71
|
+
|
|
72
|
+
def setShape(self, aConvex):
|
|
73
|
+
self._shape= aConvex
|
|
74
|
+
return self
|
|
75
|
+
|
|
76
|
+
def setShapeRegular(self, size= 1.0):
|
|
77
|
+
self._shape.initializeSquare(size)
|
|
78
|
+
return self
|
|
79
|
+
|
|
80
|
+
def setShapeRegular(self, numberOfVertex= 6, size= 1.0):
|
|
81
|
+
self._shape.initializeRegular( numberOfVertex, size)
|
|
82
|
+
return self
|
|
83
|
+
|
|
84
|
+
def setBody(self, aConvex):
|
|
85
|
+
self._center= aConvex.center()
|
|
86
|
+
subCenter= Point( -self._center.x(), -self._center.y() )
|
|
87
|
+
self._shape= aConvex.copy(subCenter)
|
|
88
|
+
return self
|
|
89
|
+
|
|
90
|
+
# Pod interface:
|
|
91
|
+
def asPod(self):
|
|
92
|
+
return Pod().fromLists(
|
|
93
|
+
["Agent"],
|
|
94
|
+
[self.id(), self.group(), self.matter(), self.tile()],
|
|
95
|
+
self.position().asList(),
|
|
96
|
+
[ self.shape().asPod() ]
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
def fromPod( self, aPod ):
|
|
100
|
+
integers= aPod.integers()
|
|
101
|
+
self.setId( integers[0] )
|
|
102
|
+
self.setGroup( integers[1] )
|
|
103
|
+
self.setMatter( integers[2] )
|
|
104
|
+
self.setTile( integers[3] )
|
|
105
|
+
self.setPosition( Point().fromList( aPod.values() ) )
|
|
106
|
+
self.setShape( Convex().fromPod( aPod.children()[0] ) )
|
|
107
|
+
return self
|
|
108
|
+
|
|
109
|
+
# str:
|
|
110
|
+
def str(self, typeName= "Agent"):
|
|
111
|
+
if self.group() :
|
|
112
|
+
return typeName + f"-{self.group()}.{self.id()} {self.box()}"
|
|
113
|
+
return typeName + f"-{self.id()} {self.box()}"
|
|
114
|
+
|
|
115
|
+
def __str__(self):
|
|
116
|
+
return self.str()
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
from .color import color, colorRatio, colorRatio, rgbColor, percentColor, webColor, colorFromWeb
|
|
2
|
+
from .support import AbsSupport, Support, SupportSVG
|
|
3
|
+
from .supportCairo import SupportPNG
|
|
4
|
+
from ..scene import Scene
|
|
5
|
+
|
|
6
|
+
def drawScene(scene, filePath= "shot-tiled.png", width= 1600, height= 1200):
|
|
7
|
+
pablo= Artist().initializePNG( filePath, width, height )
|
|
8
|
+
pablo.fit(scene)
|
|
9
|
+
pablo.drawScene(scene)
|
|
10
|
+
pablo.flip()
|
|
11
|
+
|
|
12
|
+
def drawConvexes(convexes, filePath= "shot-tiled.png", width= 1600, height= 1200):
|
|
13
|
+
scene= Scene(convexes)
|
|
14
|
+
drawScene(scene,filePath, width, height)
|
|
15
|
+
|
|
16
|
+
# Artist:
|
|
17
|
+
class Brush():
|
|
18
|
+
def __init__(self, fill= 0xff6644, stroke= 0x991100, width= 4 ):
|
|
19
|
+
self.fill= fill
|
|
20
|
+
self.stroke= stroke
|
|
21
|
+
self.width= width
|
|
22
|
+
|
|
23
|
+
class Artist():
|
|
24
|
+
def __init__(self):
|
|
25
|
+
# Initialize support:
|
|
26
|
+
self._support= Support()
|
|
27
|
+
|
|
28
|
+
# Initialize brush :
|
|
29
|
+
self._background= 0xb86e00
|
|
30
|
+
self._panel= [
|
|
31
|
+
Brush(0xffcd80, 0x603800, 4), # 0-Free
|
|
32
|
+
Brush(0xff6644, 0x991100, 4), # 1-Red
|
|
33
|
+
Brush(0x70f050, 0x20770a, 4), # 2-Green
|
|
34
|
+
Brush(0x6666ff, 0x1111aa, 4), # 3-Blue
|
|
35
|
+
Brush(0xfd9622, 0xdd550a, 4), # 4-Orange
|
|
36
|
+
Brush(0xdd77ff, 0x8800aa, 4), # 5-Purple
|
|
37
|
+
Brush(0x66ddee, 0x117799, 4), # 6-Cian
|
|
38
|
+
Brush(0xffffff, 0xbbbbbb, 4), # 7-White
|
|
39
|
+
Brush(0x888888, 0x555555, 4), # 8-Grey
|
|
40
|
+
Brush(0x444444, 0x000000, 4), # 9-Black
|
|
41
|
+
|
|
42
|
+
Brush(0x603800, 0xffcd80, 4), # 10-Background
|
|
43
|
+
Brush(0x991100, 0xff6644, 4), # 11-Red
|
|
44
|
+
Brush(0x20770a, 0x70f050, 4), # 12-Green
|
|
45
|
+
Brush(0x1111aa, 0x6666ff, 4), # 13-Blue
|
|
46
|
+
Brush(0xdd550a, 0xfd9622, 4), # 14-Orange
|
|
47
|
+
Brush(0x8800aa, 0xdd77ff, 4), # 15-Purple
|
|
48
|
+
Brush(0x117799, 0x66ddee, 4), # 16-Cian
|
|
49
|
+
Brush(0xbbbbbb, 0xffffff, 4), # 17-White
|
|
50
|
+
Brush(0x555555, 0x888888, 4), # 18-Grey
|
|
51
|
+
Brush(0x000000, 0x444444, 4) # 19-Black
|
|
52
|
+
]
|
|
53
|
+
self._fontSize= 16
|
|
54
|
+
|
|
55
|
+
# Initialize Frame :
|
|
56
|
+
self._x= 0.0
|
|
57
|
+
self._y= 0.0
|
|
58
|
+
self._scale= 100.0
|
|
59
|
+
self.flip()
|
|
60
|
+
|
|
61
|
+
# Construction:
|
|
62
|
+
def initializeSVG(self, filePath, width= 1600, height= 1200):
|
|
63
|
+
self._support= SupportSVG( width, height, filePath )
|
|
64
|
+
self.flip()
|
|
65
|
+
return self
|
|
66
|
+
|
|
67
|
+
def initializePNG(self, filePath, width= 1600, height= 1200):
|
|
68
|
+
self._support= SupportPNG( width, height, filePath )
|
|
69
|
+
self.flip()
|
|
70
|
+
return self
|
|
71
|
+
|
|
72
|
+
# Accessor:
|
|
73
|
+
def support(self):
|
|
74
|
+
return self._support
|
|
75
|
+
|
|
76
|
+
def content(self):
|
|
77
|
+
return self._support.content()
|
|
78
|
+
|
|
79
|
+
def clear(self):
|
|
80
|
+
h= self._support.height()
|
|
81
|
+
w= self._support.width()
|
|
82
|
+
self._support.clear()
|
|
83
|
+
self._support.fillPolygon(
|
|
84
|
+
[0, 0, w, w],
|
|
85
|
+
[0, h, h, 0],
|
|
86
|
+
self._background
|
|
87
|
+
)
|
|
88
|
+
return self
|
|
89
|
+
|
|
90
|
+
def render( self ):
|
|
91
|
+
return self._support.render()
|
|
92
|
+
|
|
93
|
+
def camera( self ):
|
|
94
|
+
return (self._x, self._y)
|
|
95
|
+
|
|
96
|
+
def scale( self ):
|
|
97
|
+
return (self._scale)
|
|
98
|
+
|
|
99
|
+
# Setters:
|
|
100
|
+
def setCamera( self, x, y ):
|
|
101
|
+
self._x, self._y= x, y
|
|
102
|
+
return self
|
|
103
|
+
|
|
104
|
+
def setScale( self, scale ):
|
|
105
|
+
self._scale= scale
|
|
106
|
+
return self
|
|
107
|
+
|
|
108
|
+
def fit(self, anObj):
|
|
109
|
+
return self.fitBox( anObj.box() )
|
|
110
|
+
|
|
111
|
+
def fitBox( self, aBox, marge=10 ):
|
|
112
|
+
marge= marge*2
|
|
113
|
+
minx, miny= aBox.leftFloor().asTuple()
|
|
114
|
+
maxx, maxy= aBox.rightCeiling().asTuple()
|
|
115
|
+
self.setCamera( (minx+maxx)*0.5, (miny+maxy)*0.5 )
|
|
116
|
+
distx= maxx-minx
|
|
117
|
+
disty= maxy-miny
|
|
118
|
+
ratioX, ratioY= 1.0, 1.0
|
|
119
|
+
if distx != 0.0 :
|
|
120
|
+
ratioX= (self._support.width()-marge)/distx
|
|
121
|
+
if disty != 0.0 :
|
|
122
|
+
ratioY= (self._support.height()-marge)/disty
|
|
123
|
+
self.setScale( min(ratioX, ratioY) )
|
|
124
|
+
return self
|
|
125
|
+
|
|
126
|
+
# Panel managments:
|
|
127
|
+
|
|
128
|
+
# Transformation World <-> Frame
|
|
129
|
+
def toFrame(self, x, y ):
|
|
130
|
+
dwidth= self._support.width()*0.5
|
|
131
|
+
dheight= self._support.height()*0.5
|
|
132
|
+
dx= (x-self._x)*self._scale
|
|
133
|
+
dy= (y-self._y)*-self._scale
|
|
134
|
+
return dx+dwidth, dy+dheight
|
|
135
|
+
|
|
136
|
+
def xToFrame(self, x ):
|
|
137
|
+
dwidth= self._support.width()*0.5
|
|
138
|
+
return (x-self._x)*self._scale + dwidth
|
|
139
|
+
|
|
140
|
+
def yToFrame(self, y ):
|
|
141
|
+
dheight= self._support.height()*0.5
|
|
142
|
+
return (y-self._y)*-self._scale + dheight
|
|
143
|
+
|
|
144
|
+
def toWorld(self, pixx, pixy):
|
|
145
|
+
return 0, 0
|
|
146
|
+
|
|
147
|
+
# Drawing primitives:
|
|
148
|
+
def tracePoint( self, x, y, brush= Brush() ):
|
|
149
|
+
pixx, pixy= self.toFrame( x, y )
|
|
150
|
+
self._support.fillCircle( pixx, pixy, brush.width, brush.stroke )
|
|
151
|
+
return self
|
|
152
|
+
|
|
153
|
+
def traceLine( self, ax, ay, bx, by, brush= Brush() ):
|
|
154
|
+
pixxA, pixyA= self.toFrame( ax, ay )
|
|
155
|
+
pixxB, pixyB= self.toFrame( bx, by )
|
|
156
|
+
self._support.traceLine( pixxA, pixyA, pixxB, pixyB, brush.stroke, brush.width)
|
|
157
|
+
return self
|
|
158
|
+
|
|
159
|
+
def traceCircle( self, x, y, radius, brush= Brush()):
|
|
160
|
+
pixx, pixy= self.toFrame(x, y)
|
|
161
|
+
self._support.traceCircle( pixx, pixy, radius*self._scale, brush.stroke, brush.width)
|
|
162
|
+
return self
|
|
163
|
+
|
|
164
|
+
def fillCircle( self, x, y, radius, brush= Brush()):
|
|
165
|
+
pixx, pixy= self.toFrame(x, y)
|
|
166
|
+
self._support.fillCircle( pixx, pixy, radius*self._scale, brush.fill )
|
|
167
|
+
return self
|
|
168
|
+
|
|
169
|
+
def drawCircle( self, x, y, radius, brush= Brush() ):
|
|
170
|
+
pixx, pixy= self.toFrame( x, y )
|
|
171
|
+
self._support.drawCircle( pixx, pixy, radius*self._scale, brush.fill, brush.stroke, brush.width )
|
|
172
|
+
return self
|
|
173
|
+
|
|
174
|
+
def tracePolygon( self, coordXs, coordYs, brush= Brush() ):
|
|
175
|
+
self._support.tracePolygon(
|
|
176
|
+
[ self.xToFrame( x ) for x in coordXs ],
|
|
177
|
+
[ self.yToFrame( y ) for y in coordYs ],
|
|
178
|
+
brush.stroke, brush.width
|
|
179
|
+
)
|
|
180
|
+
return self
|
|
181
|
+
|
|
182
|
+
def fillPolygon( self, coordXs, coordYs, brush= Brush() ):
|
|
183
|
+
self._support.fillPolygon(
|
|
184
|
+
[ self.xToFrame( x ) for x in coordXs ],
|
|
185
|
+
[ self.yToFrame( y ) for y in coordYs ],
|
|
186
|
+
brush.fill
|
|
187
|
+
)
|
|
188
|
+
return self
|
|
189
|
+
|
|
190
|
+
def drawPolygon( self, coordXs, coordYs, brush= Brush() ):
|
|
191
|
+
self._support.drawPolygon(
|
|
192
|
+
[ self.xToFrame( x ) for x in coordXs ],
|
|
193
|
+
[ self.yToFrame( y ) for y in coordYs ],
|
|
194
|
+
brush.fill, brush.stroke, brush.width
|
|
195
|
+
)
|
|
196
|
+
return self
|
|
197
|
+
|
|
198
|
+
# Writting primitives:
|
|
199
|
+
def write( self, x, y, text, brush= Brush() ):
|
|
200
|
+
self._support.write(
|
|
201
|
+
self.xToFrame(x), self.yToFrame(y),
|
|
202
|
+
text, brush.stroke, self._fontSize
|
|
203
|
+
)
|
|
204
|
+
return self
|
|
205
|
+
|
|
206
|
+
# Drawing frame:
|
|
207
|
+
def drawFrameGrid( self, step= 1.0, color=None ):
|
|
208
|
+
|
|
209
|
+
pixX, pixY= self.toFrame( 0, 0 )
|
|
210
|
+
pixStep= step*self._scale
|
|
211
|
+
|
|
212
|
+
while pixX > pixStep :
|
|
213
|
+
pixX-= pixStep
|
|
214
|
+
|
|
215
|
+
while pixY > pixStep :
|
|
216
|
+
pixY-= pixStep
|
|
217
|
+
|
|
218
|
+
width= self._support.width()
|
|
219
|
+
height= self._support.height()
|
|
220
|
+
|
|
221
|
+
if not color :
|
|
222
|
+
color= self._panel[0].stroke
|
|
223
|
+
|
|
224
|
+
# Vertical
|
|
225
|
+
for i in range( (int)(width/pixStep)+1 ) :
|
|
226
|
+
self._support.traceLine( pixX+(pixStep*i), 10, pixX+(pixStep*i), height-10, color, 2 )
|
|
227
|
+
# Horizontal
|
|
228
|
+
for i in range( (int)(height/pixStep)+1 ) :
|
|
229
|
+
self._support.traceLine( 10, pixY+(pixStep*i), width-10, pixY+(pixStep*i), color, 2 )
|
|
230
|
+
return self
|
|
231
|
+
|
|
232
|
+
def drawFrameAxes( self ):
|
|
233
|
+
brush= Brush( 0xE26060, 0xE26060, 6 )
|
|
234
|
+
self.traceLine( 0, 0, 1, 0, brush )
|
|
235
|
+
brush.stroke= 0x60E260
|
|
236
|
+
self.traceLine( 0, 0, 0, 1, brush )
|
|
237
|
+
brush.stroke= 0x0606E2
|
|
238
|
+
self.tracePoint( 0, 0, brush )
|
|
239
|
+
return self
|
|
240
|
+
|
|
241
|
+
# Drawing map:
|
|
242
|
+
def drawConvex( self, shape, brushId=0, px=0, py=0 ):
|
|
243
|
+
listxs, listys= shape.asLists(px, py)
|
|
244
|
+
self.drawPolygon( listxs, listys, self._panel[ brushId%len(self._panel) ] )
|
|
245
|
+
|
|
246
|
+
def fillConvex( self, shape, brushId=0, px=0, py=0 ):
|
|
247
|
+
listxs, listys= shape.asLists(px, py)
|
|
248
|
+
self.fillPolygon( listxs, listys, self._panel[ brushId%len(self._panel) ] )
|
|
249
|
+
|
|
250
|
+
def drawTile( self, aTile ):
|
|
251
|
+
env= aTile.body().asZipped()
|
|
252
|
+
self.drawPolygon(
|
|
253
|
+
[p[0] for p in env],
|
|
254
|
+
[p[1] for p in env],
|
|
255
|
+
self._panel[ aTile.matter() ]
|
|
256
|
+
)
|
|
257
|
+
|
|
258
|
+
def writeTile( self, aTile ):
|
|
259
|
+
minx, miny= aTile.box().leftFloor().asTuple()
|
|
260
|
+
x, y= aTile.position().asTuple()
|
|
261
|
+
x= x+(minx-x)*2/3
|
|
262
|
+
y= y+(miny-y)*2/3
|
|
263
|
+
self.write( x, y, str(aTile.id()), self._panel[ aTile.matter() ] )
|
|
264
|
+
|
|
265
|
+
def drawAgent( self, agent, brushId ):
|
|
266
|
+
self.fillConvex(
|
|
267
|
+
agent.body(),
|
|
268
|
+
brushId )
|
|
269
|
+
minx, miny= agent.box().leftFloor().asTuple()
|
|
270
|
+
x, y= agent.position().asTuple()
|
|
271
|
+
self.write( x, y, str(agent.id()), self._panel[brushId] )
|
|
272
|
+
|
|
273
|
+
def drawSceneNetwork( self, aScene ):
|
|
274
|
+
for tile in aScene.tiles() :
|
|
275
|
+
cx, cy= tile.position().asTuple()
|
|
276
|
+
self.tracePoint( cx, cy, self._panel[ tile.matter() ] )
|
|
277
|
+
|
|
278
|
+
for fromId, toId in aScene.edges() :
|
|
279
|
+
fromX, fromY= aScene.tile( fromId ).position().asTuple()
|
|
280
|
+
brush= self._panel[ aScene.tile( fromId ).matter() ]
|
|
281
|
+
toX, toY= aScene.tile( toId ).position().asTuple()
|
|
282
|
+
self.traceLine( fromX, fromY, toX, toY, brush )
|
|
283
|
+
|
|
284
|
+
def drawSceneTiles( self, aScene ):
|
|
285
|
+
for tile in aScene.tiles() :
|
|
286
|
+
self.drawTile( tile )
|
|
287
|
+
|
|
288
|
+
def drawSceneAgents( self, aScene ):
|
|
289
|
+
for tile in aScene.tiles() :
|
|
290
|
+
x, y= tile.position().asTuple()
|
|
291
|
+
position= (x+0.1, y+0.1)
|
|
292
|
+
for agent in tile.agents() :
|
|
293
|
+
self.drawAgent( agent, agent.matter() )
|
|
294
|
+
|
|
295
|
+
def writeSceneTiles( self, aScene ):
|
|
296
|
+
for tile in aScene.tiles() :
|
|
297
|
+
self.writeTile( tile )
|
|
298
|
+
|
|
299
|
+
def drawScene( self, aScene ):
|
|
300
|
+
self.drawSceneNetwork(aScene)
|
|
301
|
+
self.drawSceneTiles(aScene)
|
|
302
|
+
self.writeSceneTiles(aScene)
|
|
303
|
+
self.drawSceneAgents(aScene)
|
|
304
|
+
|
|
305
|
+
# Control:
|
|
306
|
+
def flip(self):
|
|
307
|
+
ref= self._support.flip()
|
|
308
|
+
self.clear()
|
|
309
|
+
return ref
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Color transform:
|
|
2
|
+
|
|
3
|
+
def color( red, green, blue ):
|
|
4
|
+
if red > 0xFF :
|
|
5
|
+
red= 0xFF
|
|
6
|
+
if green > 0xFF :
|
|
7
|
+
green= 0xFF
|
|
8
|
+
if blue > 0xFF :
|
|
9
|
+
blue= 0xFF
|
|
10
|
+
return (red<<16) + (green<<8) + (blue)
|
|
11
|
+
|
|
12
|
+
def colorFromWeb( webColor ):
|
|
13
|
+
return int( webColor[1:], base=16)
|
|
14
|
+
|
|
15
|
+
def rgbColor( color ):
|
|
16
|
+
b= (color & 0xFF)
|
|
17
|
+
var= color >> 8
|
|
18
|
+
g= (var & 0xFF)
|
|
19
|
+
var= var >> 8
|
|
20
|
+
r= (var & 0xFF)
|
|
21
|
+
return (r, g, b)
|
|
22
|
+
|
|
23
|
+
def percentColor( color ):
|
|
24
|
+
r, g, b= rgbColor(color)
|
|
25
|
+
ratio= 1.0/0xff
|
|
26
|
+
return round(r*ratio, 4), round(g*ratio, 4), round(b*ratio, 4)
|
|
27
|
+
|
|
28
|
+
def webColor( color ):
|
|
29
|
+
string= '#'
|
|
30
|
+
for c in rgbColor( color ) :
|
|
31
|
+
string+= hex( (c>>4)&0xF )[2]
|
|
32
|
+
string+= hex( c&0xF )[2]
|
|
33
|
+
return string
|
|
34
|
+
|
|
35
|
+
def colorRatio( color, ratio ):
|
|
36
|
+
r,g,b= rgbColor( color )
|
|
37
|
+
r= int( r*ratio )
|
|
38
|
+
g= int( r*ratio )
|
|
39
|
+
b= int( r*ratio )
|
|
40
|
+
return color
|
|
41
|
+
|