Skip to content
Snippets Groups Projects
Commit ddb528a9 authored by Egli Adrian (IT-SCI-API-PFI)'s avatar Egli Adrian (IT-SCI-API-PFI)
Browse files

Bug fixed in editor.py click position works now perfectly (xy_to_rc)

parent 18a63599
No related branches found
No related tags found
No related merge requests found
......@@ -210,7 +210,11 @@ class View(object):
self.writableData[(y - 2):(y + 2), (x - 2):(x + 2), :3] = 0
def xy_to_rc(self, x, y):
rcCell = ((array([y, x]) - self.yxBase) / self.nPixCell).astype(int)
rcCell = ((array([y, x]) - self.yxBase))
nX = np.floor((self.yxSize[0] - self.yxBase[0])/ self.model.env.height)
nY = np.floor((self.yxSize[1] - self.yxBase[1])/ self.model.env.width)
rcCell[0] = max(0,min(np.floor(rcCell[0]/nY),self.model.env.height-1))
rcCell[1] = max(0,min(np.floor(rcCell[1]/nX),self.model.env.width-1))
return rcCell
def log(self, *args, **kwargs):
......
%% Cell type:markdown id: tags:
# Rail Editor v0.2
%% Cell type:code id: tags:
``` python
%load_ext autoreload
%autoreload 2
```
%% Output
The autoreload extension is already loaded. To reload it, use:
%reload_ext autoreload
%% Cell type:code id: tags:
``` python
import numpy as np
from numpy import array
import ipywidgets
import IPython
from IPython.core.display import display, HTML
```
%% Cell type:code id: tags:
``` python
display(HTML("<style>.container { width:95% !important; }</style>"))
```
%% Output
%% Cell type:code id: tags:
``` python
from flatland.utils.editor import EditorMVC, EditorModel, View, Controller
```
%% Output
cairo installed: OK
%% Cell type:code id: tags:
``` python
mvc = EditorMVC(sGL="PILSVG" ) # sGL="PIL")
```
%% Output
<flatland.utils.graphics_pil.PILSVG object at 0x000001E6748D1128> <class 'flatland.utils.graphics_pil.PILSVG'>
<flatland.utils.graphics_pil.PILSVG object at 0x0000020D4CDD2E10> <class 'flatland.utils.graphics_pil.PILSVG'>
<super: <class 'PILSVG'>, <PILSVG object>> <class 'super'>
0000000000000000 Background_#91D1DD.svg
WE 0000000000000100 Gleis_Deadend.svg
WW EE NN SS 1000010000100001 Gleis_Diamond_Crossing.svg
WW EE 0000010000000001 Gleis_horizontal.svg
EN SW 0000100000010000 Gleis_Kurve_oben_links.svg
WN SE 0000000001001000 Gleis_Kurve_oben_rechts.svg
ES NW 0001001000000000 Gleis_Kurve_unten_links.svg
NE WS 0100000000000010 Gleis_Kurve_unten_rechts.svg
NN SS 1000000000100000 Gleis_vertikal.svg
NN SS EE WW ES NW SE WN 1001011001101001 Weiche_Double_Slip.svg
EE WW EN SW 0000110000010001 Weiche_horizontal_oben_links.svg
EE WW SE WN 0000010001001001 Weiche_horizontal_oben_rechts.svg
EE WW ES NW 0001011000000001 Weiche_horizontal_unten_links.svg
EE WW NE WS 0100010000000011 Weiche_horizontal_unten_rechts.svg
NN SS EE WW NW ES 1001011000100001 Weiche_Single_Slip.svg
NE NW ES WS 0101001000000010 Weiche_Symetrical.svg
NN SS EN SW 1000100000110000 Weiche_vertikal_oben_links.svg
NN SS SE WN 1000000001101000 Weiche_vertikal_oben_rechts.svg
NN SS NW ES 1001001000100000 Weiche_vertikal_unten_links.svg
NN SS NE WS 1100000000100010 Weiche_vertikal_unten_rechts.svg
EW 0000000100000000 Bahnhof_#d50000_Deadend_links.svg
NS 0010000000000000 Bahnhof_#d50000_Deadend_oben.svg
WE 0000000000000100 Bahnhof_#d50000_Deadend_rechts.svg
SN 0000000010000000 Bahnhof_#d50000_Deadend_unten.svg
EE WW 0000010000000001 Bahnhof_#d50000_Gleis_horizontal.svg
NN SS 1000000000100000 Bahnhof_#d50000_Gleis_vertikal.svg
Clear rails
%% Cell type:markdown id: tags:
## Instructions
- Drag to draw (improved dead-ends)
- Shift-Drag to erase rails (erasing dead ends not yet automated - drag right across them)
- ctrl-click to add agent
- direction chosen randomly to fit rail
- ctrl-shift-click to add target for last agent
- target can be moved by repeating
- to Resize the env (cannot preserve work):
- select "Regen" tab, set regen size slider, click regenerate.
- alt-click remove all rails from cell
%% Cell type:code id: tags:
``` python
mvc.view.display()
```
%% Output
<flatland.utils.graphics_pil.PILSVG object at 0x000001E674DEF048> <class 'flatland.utils.graphics_pil.PILSVG'>
<flatland.utils.graphics_pil.PILSVG object at 0x0000020D4CF49D30> <class 'flatland.utils.graphics_pil.PILSVG'>
<super: <class 'PILSVG'>, <PILSVG object>> <class 'super'>
0000000000000000 Background_#91D1DD.svg
WE 0000000000000100 Gleis_Deadend.svg
WW EE NN SS 1000010000100001 Gleis_Diamond_Crossing.svg
WW EE 0000010000000001 Gleis_horizontal.svg
EN SW 0000100000010000 Gleis_Kurve_oben_links.svg
WN SE 0000000001001000 Gleis_Kurve_oben_rechts.svg
ES NW 0001001000000000 Gleis_Kurve_unten_links.svg
NE WS 0100000000000010 Gleis_Kurve_unten_rechts.svg
NN SS 1000000000100000 Gleis_vertikal.svg
NN SS EE WW ES NW SE WN 1001011001101001 Weiche_Double_Slip.svg
EE WW EN SW 0000110000010001 Weiche_horizontal_oben_links.svg
EE WW SE WN 0000010001001001 Weiche_horizontal_oben_rechts.svg
EE WW ES NW 0001011000000001 Weiche_horizontal_unten_links.svg
EE WW NE WS 0100010000000011 Weiche_horizontal_unten_rechts.svg
NN SS EE WW NW ES 1001011000100001 Weiche_Single_Slip.svg
NE NW ES WS 0101001000000010 Weiche_Symetrical.svg
NN SS EN SW 1000100000110000 Weiche_vertikal_oben_links.svg
NN SS SE WN 1000000001101000 Weiche_vertikal_oben_rechts.svg
NN SS NW ES 1001001000100000 Weiche_vertikal_unten_links.svg
NN SS NE WS 1100000000100010 Weiche_vertikal_unten_rechts.svg
EW 0000000100000000 Bahnhof_#d50000_Deadend_links.svg
NS 0010000000000000 Bahnhof_#d50000_Deadend_oben.svg
WE 0000000000000100 Bahnhof_#d50000_Deadend_rechts.svg
SN 0000000010000000 Bahnhof_#d50000_Deadend_unten.svg
EE WW 0000010000000001 Bahnhof_#d50000_Gleis_horizontal.svg
NN SS 1000000000100000 Bahnhof_#d50000_Gleis_vertikal.svg
%% Cell type:code id: tags:
``` python
mvc.view.wOutput.clear_output()
mvc.view.wOutput
```
%% Output
%% Cell type:code id: tags:
``` python
len(mvc.editor.env.agents), len(mvc.editor.env.agents_static)
```
%% Output
(0, 0)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment