Exemplo n.º 1
0
from gram import Gram
gr = Gram()
gr.baseName = 'line'
gr.font = 'Helvetica'
gr.grid(0,0,4,4)
g = gr.line(1,1,2,3)
g.colour = 'black!20'
g.colour.transparent = True
g.lineThickness = 28. # pts
g = gr.line(3, 3.5, 2, 1)
g.lineThickness = 'semithick'
g.lineStyle = 'dashed'
# A default, un-modified line
gr.line(1, 3, 1.5, 0.5)
g = gr.line(3.5, 1, 3.5, 2)
g.lineThickness = 10
g.cap = 'rect'  # default butt
g = gr.text('some lines', 3,3)
g.anchor = 'north west'
g.textSize = 'normalsize'
gr.png()
gr.svg()
Exemplo n.º 2
0
from gram import Gram
gr = Gram()
gr.font = 'helvetica'
gr.baseName = 'rect'
gr.grid(2, 2, 6, 5)
g = gr.rect(2, 3, 5, 4)
g.lineThickness = 5
g.color = 'teal'
g.fill = 'cyan!10'
g = gr.text("xXy", 4, 5)
g.textSize = 'Large'
gr.pdf()
gr.svg()
Exemplo n.º 3
0
from gram import Gram

gr = Gram()
gr.font = 'helvetica'
gr.baseName = 'size'
gr.pngResolution = 90
gr.svgPxForCm = 35.43307
gr.grid(0, 0, 1, 1, color='black')
gr.png()
gr.svg()

gr.baseName = 'sizeB'
gr.pngResolution = 200
gr.svgPxForCm = 100
gr.png()
gr.svg()
Exemplo n.º 4
0
from gram import Gram
gr = Gram()
gr.baseName = 'fontWeight'
gr.font = 'helvetica'
gr.grid(-2,-1, 2, 1)
myText = "This is some text"
#gr.text("This is a PNG", 0,0)
g = gr.text(myText, 0,0)
g.dump()
gr.png()

gr.graphics.pop()
g = gr.text(myText, 0, 0)
g.anchor = 'center'
g.dump()
#gr.text("This is SVG, weight 300", 0, 0)
gr.svgTextNormalWeight = 300
gr.baseName = 'fontWeight300'
gr.svg()

# gr.graphics.pop()
# gr.text(myText, 0, 0)
# #gr.text("This is SVG, weight 400", 0, 0)
# gr.svgTextNormalWeight = 400
# gr.baseName = 'fontWeight400'
# gr.svg()

Exemplo n.º 5
0
from gram import Gram
gr = Gram()
gr.font = 'helvetica'
gr.baseName = 'big'

ox = 35
oy = 20
x = ox + 10
y = oy + 55

gr.grid(ox,oy,x,y)

g = gr.text("Bottom left", ox,oy)
g.anchor = 'south west'

g = gr.text("Top right", x, y)
g.anchor = 'north east'

gr.pdf()
gr.svg()

    
Exemplo n.º 6
0
from gram import Gram, GramCode
gr = Gram()
gr.svgPxForCm = 100
gr.baseName = 'code'
gr.grid(0, 0, 3, 3)
gr.code("% some tikz code")
gr.code(r"""\draw [->] (1,1) .. controls
(1.5,3) and (2,0) .. (2.5,2);""")
gr.code(r"""\draw [thick, gray, ->] (0,2)
parabola bend (0.5, 1)  (1, 2.5);""")
gr.png()

# Wipe out the tikz code
toRemove = [g for g in gr.graphics if isinstance(g, GramCode)]
for g in toRemove:
    gr.graphics.remove(g)

gr.code(
    r'<path d="M100 -100 C 150 -300 200 0 250 -200" stroke="black" fill="none" />'
)
gr.code(
    r'<path d="M 0 -200 Q 50 20 100 -250" stroke="grey" stroke-width="4px" fill="none" />'
)

gr.svg()
Exemplo n.º 7
0
from gram import Gram
gr = Gram()
gr.font = 'helvetica'
gr.baseName = 'rect'
gr.grid(2,2,6,5)
g = gr.rect(2,3,5,4)
g.lineThickness = 5
g.color = 'teal'
g.fill = 'cyan!10'
g = gr.text("xXy", 4,5)
g.textSize = 'Large'
gr.pdf()
gr.svg()
    
Exemplo n.º 8
0
from gram import Gram
gr = Gram()
gr.baseName = 'line'
gr.font = 'Helvetica'
gr.grid(0, 0, 4, 4)
g = gr.line(1, 1, 2, 3)
g.colour = 'black!20'
g.lineThickness = 28.  # pts
g = gr.line(3, 3.5, 2, 1)
g.lineThickness = 'semithick'
g.lineStyle = 'dashed'
# A default, un-modified line
gr.line(1, 3, 1.5, 0.5)
g = gr.line(3.5, 1, 3.5, 2)
g.lineThickness = 10
g.cap = 'rect'  # default butt
g = gr.text('some lines', 3, 3)
g.anchor = 'north west'
g.textSize = 'normalsize'
gr.png()
gr.svg()
Exemplo n.º 9
0
from gram import Gram
gr = Gram()
gr.baseName = 'colour'
gr.grid(0,0,6,4)

g = gr.rect(2.6, 2.6, 3.4, 3.4)
g.fill = "red!30"
g.draw = "blue!50"
g.lineThickness = 5

g = gr.rect(2.6, 1.6, 3.4, 2.4)
g.fill = "red!30"
g.draw = None

g = gr.rect(2.6, 0.6, 3.4, 1.4)
g.fill = None
g.draw = "blue!50"
g.lineThickness = 5

g = gr.text("default, transparent", 3.0, 3.75)
g.textSize = 'tiny'
g.fill = 'white'

g = gr.rect(4.6, 2.6, 5.4, 3.4)
g.fill = "red!30"
g.fill.transparent = False
g.draw = "blue!50"
g.draw.transparent = False
g.lineThickness = 5

g = gr.rect(4.6, 1.6, 5.4, 2.4)
Exemplo n.º 10
0
from gram import Gram

tt = "xxx xxX xXy xyy".split()
xx = [i for i in range(1,5)]
gr = Gram()
gr.baseName = 'textVerticalAlignment'
gr.grid(0,0,5,5)
for i in range(4):
    gr.code(r"\node [anchor=west] at (%.1f,4.0) {%s};" % (xx[i], tt[i]))
    g = gr.text(tt[i],xx[i],3)
    g.anchor = 'west'
    gr.code(r"\node [anchor=west,draw] at (%.1f,2.0) {%s};" % (xx[i], tt[i]))
    g = gr.text(tt[i],xx[i],1)
    g.anchor = 'west'
    g.draw = True

gr.png()
# gr.svg()  tikz code does not work here

Exemplo n.º 11
0
from gram import Gram
gr = Gram()
# gr.defaultInnerSep = 0.0
gr.grid(0, -1, 4, 2)
gr.font = 'palatino'
gr.baseName = 'bunnies'

# Define a couple of styles
from gram import GramText
st = GramText('Xy')
st.name = 'bunny1'
st.textShape = 'scshape'
st.color = 'violet'
gr.styleDict[st.name] = st

st = GramText('Xy')
st.name = 'bunny2'
st.rotate = 45
st.color = 'darkgray'
st.textSize = 'small'
st.draw = True
#st.shape='circle'
gr.styleDict[st.name] = st

g = gr.text("Flopsy", 1, 1.2)
g.style = 'bunny1'

g = gr.text("Mopsy", 3, 1.2)
g.style = 'bunny1'

g = gr.text("Cottontail", 1, 0)
Exemplo n.º 12
0
from gram import Gram,GramCode
gr = Gram()
gr.svgPxForCm = 100
gr.baseName = 'rawcode'
gr.grid(0,0,3,3)
gr.code("% some tikz code")
gr.code(r"""\draw [->] (1,1) .. controls
(1.5,3) and (2,0) .. (2.5,2);""")
gr.code(r"""\draw [thick, gray, ->] (0,2)
parabola bend (0.5, 1)  (1, 2.5);""")
gr.png()

# Wipe out the tikz code
toRemove = [g for g in gr.graphics if isinstance(g, GramCode)]
for g in toRemove:
    gr.graphics.remove(g)

gr.code(r'<path d="M100 -100 C 150 -300 200 0 250 -200" stroke="black" fill="none" />')
gr.code(r'<path d="M 0 -200 Q 50 20 100 -250" stroke="grey" stroke-width="4px" fill="none" />')

gr.svg()
Exemplo n.º 13
0
from gram import Gram
gr = Gram()
gr.baseName = 'rotatedText'
gr.showTextBB = True
gr.showTextAnchor = True
g = gr.text("short", 1,2)
g.rotate = 30
g.draw = 'blue'
g.lineThickness = 'thick'
g = gr.grid(0,0, 3, 3)
g = gr.text("Another bit of text.", 2,3)
g.anchor = 'south west'
g.rotate = -120
g.draw = 'cyan'
gr.pdf()
gr.svg()
Exemplo n.º 14
0
from gram import Gram

tt = "xxx xxX xXy xyy".split()
xx = [i for i in range(1, 5)]
gr = Gram()
gr.baseName = 'textVerticalAlignment'
gr.grid(0, 0, 5, 5)
for i in range(4):
    gr.code(r"\node [anchor=west] at (%.1f,4.0) {%s};" % (xx[i], tt[i]))
    g = gr.text(tt[i], xx[i], 3)
    g.anchor = 'west'
    gr.code(r"\node [anchor=west,draw] at (%.1f,2.0) {%s};" % (xx[i], tt[i]))
    g = gr.text(tt[i], xx[i], 1)
    g.anchor = 'west'
    g.draw = True

gr.png()
# gr.svg()  tikz code does not work here
Exemplo n.º 15
0
from gram import Gram
gr = Gram()
gr.baseName = 'fontWeight'
gr.font = 'helvetica'
gr.grid(-2, -1, 2, 1)
myText = "This is some text"
#gr.text("This is a PNG", 0,0)
gr.text(myText, 0, 0)
gr.png()

gr.graphics.pop()
gr.text(myText, 0, 0)
#gr.text("This is SVG, weight 300", 0, 0)
gr.svgTextNormalWeight = 300
gr.baseName = 'fontWeight300'
gr.svg()

gr.graphics.pop()
gr.text(myText, 0, 0)
#gr.text("This is SVG, weight 400", 0, 0)
gr.svgTextNormalWeight = 400
gr.baseName = 'fontWeight400'
gr.svg()
Exemplo n.º 16
0
from gram import Gram
gr = Gram()
gr.baseName = 'rotatedText'
gr.showTextBB = True
gr.showTextAnchor = True
g = gr.text("short", 1,2)
g.rotate = 30
g.draw = 'blue'
g.lineThickness = 'thick'
g = gr.grid(0,0, 3, 3)
g = gr.text("Another bit of text.", 2,3)
g.anchor = 'south west'
g.rotate = -120
g.draw = 'cyan'
gr.pdf()
#gr.svg()