
import sys
import math
sys.path.append("../../../scidocxml/draw/pydraw")
import pyDraw as draw
d = draw.Draw({'name':'figureA','width':800,'height':600,'medium-font-size':'16'})
s=draw.Scale({'sx':800,'sy':600})
t=draw.Translate({'tx':0.05,'ty':0.05})
nx=15
ny=15
dx=0.9/(nx-1)
dy=0.9/(ny-1)
for i in range(nx):
    t.add(draw.Line({'x1':i*dx,'y1':0,'x2':i*dx,'y2':0.9,'stroke':'grey','fill':'none'}))
for j in range(ny):
    t.add(draw.Line({'x1':0,'y1':j*dy,'x2':0.9,'y2':j*dy,'stroke':'grey','fill':'none'}))
def point(i,j,anchor,text):
    x = i*dx
    y = j*dy
    t.add(draw.Circle({'cx':x,'cy':y,'r':0.005,'stroke':'red','fill':'red'}))
    t.add(draw.Text({'x':x,'y':y,'a':anchor,'fill':'black','stroke':'black','font-size':'medium'},text))
def sommet(i,j,anchor,text,stroke):
    x = i*dx
    y = j*dy
    t.add(draw.Circle({'cx':x,'cy':y,'r':0.002,'stroke':stroke,'fill':stroke}))
    t.add(draw.Text({'x':x,'y':y,'a':anchor,'fill':stroke,'stroke':stroke,'font-size':'x-small'},text))
def text(i,j,anchor,text,stroke):
    x=i*dx
    y=j*dy
    t.add(draw.Text({'x':x,'y':y,'a':anchor,'fill':stroke,'stroke':stroke,'font-size':'x-small'},text))
def frontiere(points,stroke,dash):
    n = len(points)
    for k in range(n):
        x1 = points[k][0]*dx
        y1 = points[k][1]*dy
        if k < n-1:
            x2 = points[k+1][0]*dx
            y2 = points[k+1][1]*dy
        else:
            x2 = points[0][0]*dx
            y2 = points[0][1]*dy
        t.add(draw.Line({'x1':x1,'y1':y1,'x2':x2,'y2':y2,'stroke':stroke,'fill':'none','stroke-dasharray':dash}))
i=4
j=5
point(i,j,'l','i,j')
text(i,j,'r','A','red')
point(i-1,j,'r','i-1,j')
point(i+1,j,'l','i+1,j')
point(i,j+1,'b','i,j+1')
point(i,j-1,'t','i,j-1')
sommet(i+0.5,j+0.5,'bl','a','blue')
sommet(i-0.5,j+0.5,'br','b','blue')
sommet(i-0.5,j-0.5,'tr','c','blue')
sommet(i+0.5,j-0.5,'tl','d','blue')
dash = '2,2'
frontiere([[i+0.5,j+0.5],[i-0.5,j+0.5],[i-0.5,j-0.5],[i+0.5,j-0.5]],'blue',dash)
i=4
j=0
point(i,j,'t','i,j')
text(i,j,'b','B','red')
point(i-1,j,'r','i-1,j')
point(i+1,j,'l','i+1,j')
point(i,j+1,'b','i,j+1')
sommet(i+0.5,j+0.5,'bl','e','blue')
sommet(i-0.5,j+0.5,'br','f','blue')
sommet(i-0.5,j-0.1,'tr','g','blue')
sommet(i+0.5,j-0.1,'tl','h','blue')
dash = '2,2'
frontiere([[i+0.5,j+0.5],[i-0.5,j+0.5],[i-0.5,j-0.1],[i+0.5,j-0.1]],'blue',dash)
i=4
j=ny-1
point(i,j,'b','i,j')
text(i,j,'t','C','red')
point(i-1,j,'r','i-1,j')
point(i+1,j,'l','i+1,j')
point(i,j-1,'t','i,j-1')
sommet(i+0.5,j+0.1,'bl','k','blue')
sommet(i-0.5,j+0.1,'br','l','blue')
sommet(i-0.5,j-0.5,'tr','m','blue')
sommet(i+0.5,j-0.5,'tl','n','blue')
dash = '2,2'
frontiere([[i+0.5,j+0.1],[i-0.5,j+0.1],[i-0.5,j-0.5],[i+0.5,j-0.5]],'blue',dash)
i=0
j=7
point(i,j,'r','i,j')
text(i,j,'l','D','red')
point(i+1,j,'l','i+1,j')
point(i,j+1,'b','i,j+1')
point(i,j-1,'t','i,j-1')
sommet(i+0.5,j+0.5,'bl','o','blue')
sommet(i-0.1,j+0.5,'br','p','blue')
sommet(i-0.1,j-0.5,'tr','q','blue')
sommet(i+0.5,j-0.5,'tl','r','blue')
dash = '2,2'
frontiere([[i+0.5,j+0.5],[i-0.1,j+0.5],[i-0.1,j-0.5],[i+0.5,j-0.5]],'blue',dash)
i=0
j=ny-1
point(i,j,'b','i,j')
text(i,j,'tl','E','red')
point(i+1,j,'l','i+1,j')
point(i,j-1,'t','i,j-1')
sommet(i+0.5,j+0.1,'bl','s','blue')
sommet(i-0.1,j+0.1,'br','t','blue')
sommet(i-0.1,j-0.5,'tr','u','blue')
sommet(i+0.5,j-0.5,'tl','v','blue')
dash = '2,2'
frontiere([[i+0.5,j+0.1],[i-0.1,j+0.1],[i-0.1,j-0.5],[i+0.5,j-0.5]],'blue',dash)
i=0
j=0
point(i,j,'tl','i,j')
text(i,j,'bl','F','red')
point(i+1,j,'l','i+1,j')
point(i,j+1,'b','i,j+1')
sommet(i+0.5,j+0.5,'bl','w','blue')
sommet(i-0.1,j+0.5,'br','x','blue')
sommet(i-0.1,j-0.1,'tr','y','blue')
sommet(i+0.5,j-0.1,'tl','z','blue')
dash = '2,2'
frontiere([[i+0.5,j+0.5],[i-0.1,j+0.5],[i-0.1,j-0.1],[i+0.5,j-0.1]],'blue',dash)
i=8
j=5
frontiere([[i,j],[i+3,j],[i+3,j+2],[i+5,j+2],[i+5,j+5],[i,j+5]],'black','')
sommet(i,j,'tr','G','red')
sommet(i+3,j,'t','H','black')
sommet(i+3,j+2,'b','I','black')
sommet(i+5,j+2,'l','J','black')
sommet(i+5,j+5,'b','K','black')
sommet(i,j+5,'b','L','black')
point(i,j,'l','i,j')
point(i-1,j,'r','i-1,j')
point(i+1,j,'l','i+1,j')
point(i,j+1,'b','i,j+1')
point(i,j-1,'t','i,j-1')
sommet(i+0.5,j+0.1,'bl','a','blue')
sommet(i+0.1,j+0.1,'bl','b','blue')
sommet(i+0.1,j+0.5,'b','c','blue')
sommet(i-0.5,j+0.5,'br','d','blue')
sommet(i-0.5,j-0.5,'t','e','blue')
sommet(i+0.5,j-0.5,'t','f','blue')
dash = '2,2'
frontiere([[i+0.5,j+0.1],[i+0.1,j+0.1],[i+0.1,j+0.5],[i-0.5,j+0.5],[i-0.5,j-0.5],[i+0.5,j-0.5]],'blue',dash)
s.add(t)
d.add(s)
            
