diff options
author | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
commit | e0c6872cf40896c7be36b11dcc744620f10adf1d (patch) | |
tree | 60335e10d2f4354b0674ec22d7b53f0f8abee672 /graphics/tpx/Scripts/Old_TpXpy |
Initial commit
Diffstat (limited to 'graphics/tpx/Scripts/Old_TpXpy')
-rw-r--r-- | graphics/tpx/Scripts/Old_TpXpy/TpX_Dom.py | 41 | ||||
-rw-r--r-- | graphics/tpx/Scripts/Old_TpXpy/TpXpy.py | 212 | ||||
-rw-r--r-- | graphics/tpx/Scripts/Old_TpXpy/gen_samples.py | 17 | ||||
-rw-r--r-- | graphics/tpx/Scripts/Old_TpXpy/renew_all.py | 12 | ||||
-rw-r--r-- | graphics/tpx/Scripts/Old_TpXpy/sample_TpXpy.py | 142 | ||||
-rw-r--r-- | graphics/tpx/Scripts/Old_TpXpy/sample_TpXpy_Roulette.py | 132 |
6 files changed, 556 insertions, 0 deletions
diff --git a/graphics/tpx/Scripts/Old_TpXpy/TpX_Dom.py b/graphics/tpx/Scripts/Old_TpXpy/TpX_Dom.py new file mode 100644 index 0000000000..33c9930a32 --- /dev/null +++ b/graphics/tpx/Scripts/Old_TpXpy/TpX_Dom.py @@ -0,0 +1,41 @@ +import xml.dom.minidom +from TpXpy import TpXpic + +def TpX_Dom_as_text(XML): + t = XML.toprettyxml(' ', '\n') + t = t.replace('<caption>\n ','<caption>') + t = t.replace('\n </caption>','</caption>') + t = t.replace('<comment>\n ','<comment>') + t = t.replace('\n </comment>','</comment>') + t = t.replace('">\n ','">') + t = t.replace('\n','\n%') + j = t.find('\n') + t = t[j+1:] + j = t.rfind('\n') + t = t[:j] + return t + +def TpX_Dom_SaveToFile(XML, FileName): + f = file(FileName, 'w') + f.write(TpX_Dom_as_text(XML)) + f.close() + +def TpX_Dom_LoadFromFile(FileName): + lines = file(FileName, 'r').readlines() + for i in range(0,len(lines)): + if lines[i][:1]=='%': + lines[i] = lines[i][1:].strip() + else: break + return xml.dom.minidom.parseString(''.join(lines)) + +dom = TpX_Dom_LoadFromFile('sample_TpXpy.TpX') +nodes = dom.documentElement.childNodes +for node in nodes: + if node.nodeType == node.ELEMENT_NODE: + if node.getAttribute('lw')=='1.5': + node.setAttribute('lw', '3') + if node.getAttribute('li')=='': + node.setAttribute('fill', 'green') + #node.setAttribute('q', 'value') +TpX_Dom_SaveToFile(dom, 'sample_TpXpy_3.TpX') +dom.unlink()
\ No newline at end of file diff --git a/graphics/tpx/Scripts/Old_TpXpy/TpXpy.py b/graphics/tpx/Scripts/Old_TpXpy/TpXpy.py new file mode 100644 index 0000000000..46e070a87e --- /dev/null +++ b/graphics/tpx/Scripts/Old_TpXpy/TpXpy.py @@ -0,0 +1,212 @@ +import xml.dom.minidom +class TpXpic: + "Python module to generate TpX drawings" + def __init__(self): + self.aXML = xml.dom.minidom.getDOMImplementation().createDocument(None, "TpX", None) + self.XMLtop = self.aXML.documentElement + self.XMLtop.setAttribute('v', '4') + def __del__(self): + self.aXML.unlink() + def as_text(self): + t = self.aXML.toprettyxml(' ', '\n') + t = t.replace('<caption>\n ','<caption>') + t = t.replace('\n </caption>','</caption>') + t = t.replace('<comment>\n ','<comment>') + t = t.replace('\n </comment>','</comment>') + t = t.replace('">\n ','">') + t = t.replace('\n','\n%') + j = t.find('\n') + t = t[j+1:] + j = t.rfind('\n') + t = t[:j] + return t + def setRootAttribute(self, elID, s): + self.XMLtop.setAttribute(elID, str(s)) + def setEl(self, elID): + el = self.XMLtop.getElementsByTagName(elID) + if len(el)>0: + self.last = self.aXML.createElement(elID) + self.XMLtop.removeChild(el[0]).unlink() + else: + self.last = self.aXML.createElement(elID) + self.XMLtop.appendChild(self.last) + return self.last + def setCaption(self, s, label=None): + self.setEl('caption').appendChild(self.aXML.createTextNode(s)) + if label!=None: + self.a('label', label) + def setComment(self, s): + self.setEl('comment').appendChild(self.aXML.createTextNode(s)) + def addEl(self, elID): + self.last = self.aXML.createElement(elID) + self.XMLtop.appendChild(self.last) + return self.last + def a(self, elID, elValue, el=None): + if el==None: + self.last.setAttribute(elID, str(elValue)) + else: + el.setAttribute(elID, str(elValue)) + def lc(self, cl, el=None): + "set line color" + self.a('lc', cl, el) + def lw(self, w, el=None): + "set line width" + self.a('lw', w, el) + def li(self, li, el=None): + "set line style: none, dot, dash or solid (default)" + self.a('li', li, el) + def ha(self, ha, el=None): + "set hatching: 1,...,6" + self.a('ha', ha, el) + def hc(self, cl, el=None): + "set hatching color" + self.a('hc', cl, el) + def fill(self, cl, el=None): + "set fill color" + self.a('fill', cl, el) + def addLine(self, x1, y1, x2, y2): + "add line" + self.last = self.addEl('line') + self.a('x1', str(x1)) + self.a('y1', str(y1)) + self.a('x2', str(x2)) + self.a('y2', str(y2)) + return self.last + def arr(self, arr1=None, arr2=None, arrs=None, el=None): + "add arrow-heads; arr1,arr2: none, h40, h41, h42, h43, h44, h45, h46, h47, h48, t40, t43, t44, t45, h20, h21, h22, h23, h24, t20, t21, t22, t23, hr10, hr11, hr12, tr10, h10, h11, h12, h12c, t10, r0, r10, r11, r12, r20, r20c, r21, r33, ts10, ts11, ts12, hs10, hs12, ts20, ts21, ts23, hs20, hs23, o, oc, qq;" + "arrs is arrow-head size factor" + if arr1!=None: + self.a('arr1', arr1, el) + if arr2!=None: + self.a('arr2', arr2, el) + if arrs!=None: + self.a('arrs', str(arrs), el) + def addRect(self, x, y, w, h): + "add rectangle" + self.last = self.addEl('rect') + self.a('x', str(x)) + self.a('y', str(y)) + self.a('w', str(w)) + self.a('h', str(h)) + return self.last + def rotdeg(self, rotdeg, el=None): + self.a('rotdeg', rotdeg, el) + def addCircle(self, x, y, d): + "add circle" + self.last = self.addEl('circle') + self.a('x', str(x)) + self.a('y', str(y)) + self.a('d', str(d)) + return self.last + def addEllipse(self, x, y, dx, dy): + "add ellipse" + self.last = self.addEl('ellipse') + self.a('x', str(x)) + self.a('y', str(y)) + self.a('dx', str(dx)) + self.a('dy', str(dy)) + return self.last + def points_str(self, pp): + s = '' + for i in range(len(pp)): + s = s + str(pp[i][0]) + ',' + str(pp[i][1]) + ' ' + return s + def addPolyline(self, pp): + "add polyline" + self.last = self.addEl('polyline') + self.last.appendChild(self.aXML.createTextNode(self.points_str(pp))) + return self.last + def addPolygon(self, pp): + "add polygon" + self.last = self.addEl('polygon') + self.last.appendChild(self.aXML.createTextNode(self.points_str(pp))) + return self.last + def addCircular(self, aID, x, y, d, a1, a2): + "add circular object" + self.last = self.addEl(aID) + self.a('x', str(x)) + self.a('y', str(y)) + self.a('d', str(d)) + self.a('a1', str(a1)) + self.a('a2', str(a2)) + return self.last + def addArc(self, x, y, d, a1, a2): + "add arc" + return self.addCircular('arc', x, y, d, a1, a2) + def addSegment(self, x, y, d, a1, a2): + "add segment" + return self.addCircular('segment', x, y, d, a1, a2) + def addSector(self, x, y, d, a1, a2): + "add sector" + return self.addCircular('sector', x, y, d, a1, a2) + def addCurve(self, pp): + "add curve" + self.last = self.addEl('curve') + self.last.appendChild(self.aXML.createTextNode(self.points_str(pp))) + return self.last + def closed(self, el=None): + "make a curve closed" + self.a('closed', 1, el) + def addBezier(self, pp): + "add Bezier path" + self.last = self.addEl('bezier') + self.last.appendChild(self.aXML.createTextNode(self.points_str(pp))) + return self.last + def addText(self, x, y, h, t, tex=None): + "add text label" + self.last = self.addEl('text') + self.a('x', str(x)) + self.a('y', str(y)) + self.a('h', str(h)) + self.a('t', t) + if tex!=None: + self.a('tex', tex) + return self.last + def jh(self, j, el=None): + "set text horizontal justification: l (left, default), c (center) or r (right)" + self.a('jh', j, el) + def jv(self, j, el=None): + "set text vertical justification: 0 (baseline, default), b (bottom), c (center) or t (top)" + self.a('jv', j, el) + def addStar(self, x, y, s=None): + "add star" + self.last = self.addEl('star') + self.a('x', str(x)) + self.a('y', str(y)) + if s!=None: + self.a('s', s) + return self.last + def starShape(self, s, el=None): + "set star shape: circle (default), square, diamond, triup, tridown, penta, star4, star5, star6, cross, dcross, flower5, flower4, star4arc, maltese" + self.a('s', s, el) + def starD(self, d, el=None): + "set star size factor" + self.a('d', str(d), el) + def addSymbol(self, x, y, d, s=None): + "add symbol" + self.last = self.addEl('symbol') + self.a('x', str(x)) + self.a('y', str(y)) + self.a('d', str(d)) + if s!=None: + self.a('s', s) + return self.last + def symbShape(self, s, el=None): + "set symbol shape: process, decision, input-output, preparation, punch-card, manual-op, keyboard, punch-tape, document, documents, display, terminal, keying, alt-process, online-storage, magnetic-drum, magnetic-tape, hoarrow1, hoarrow1v, hoarrow2, hoarrow3, hoarrow4, star5, diamond8, baloon1, baloon2, cloud1, splash1, snowflake1" + self.a('s', s, el) + def SaveToFile(self, FileName): + f = file(FileName, 'w') + f.write(self.as_text()) + f.close() + +def HTML_color(r,g,b): + "Make HTML color from RGB levels" + r=round(r);g=round(g);b=round(b) + if r<0:r=0 + if r>255:r=255 + if g<0:g=0 + if g>255:g=255 + if b<0:b=0 + if b>255:b=255 + return '#%02X%02X%02X'%(r,g,b) + diff --git a/graphics/tpx/Scripts/Old_TpXpy/gen_samples.py b/graphics/tpx/Scripts/Old_TpXpy/gen_samples.py new file mode 100644 index 0000000000..21ff09e529 --- /dev/null +++ b/graphics/tpx/Scripts/Old_TpXpy/gen_samples.py @@ -0,0 +1,17 @@ +import os +'A script for generating bitmap or SVG files for all drawings in a specified directory' + +tpx_path = 'C:\\WRK\\Delphi\\TpX\\TpX.exe ' +pics_path = 'C:\\WRK\\Delphi\\TpX\\Distribution\\Samples\\' +os.chdir(pics_path) +files = os.listdir(pics_path) +for input_filename0 in files: + if input_filename0.find('.TpX')<0: continue + input_filename0 = '%s%s'%(pics_path,input_filename0) +# ext = 'svg' +# xfrmt = 'latexeps' + xfrmt = 'latexcustom' +# xfrmt = 'svg' + ext = 'qqq' + code = os.system('%s -f"%s" -x %s -o"%s"'%(tpx_path,input_filename0,xfrmt,input_filename0.replace('.TpX','.'+ext))) + print input_filename0, code diff --git a/graphics/tpx/Scripts/Old_TpXpy/renew_all.py b/graphics/tpx/Scripts/Old_TpXpy/renew_all.py new file mode 100644 index 0000000000..1d232d34da --- /dev/null +++ b/graphics/tpx/Scripts/Old_TpXpy/renew_all.py @@ -0,0 +1,12 @@ +import os +'A script for refreshing all drawings in a specified directory' + +tpx_path = '.........\\TpX.exe' +pics_path = '.........\\' +os.chdir(pics_path) +files = os.listdir(pics_path) +for input_filename0 in files: + if input_filename0[-4:] != '.TpX': continue + input_filename0 = '%s%s'%(pics_path,input_filename0) + code = os.system('%s -f"%s" -o'%(tpx_path,input_filename0)) + print input_filename0, code diff --git a/graphics/tpx/Scripts/Old_TpXpy/sample_TpXpy.py b/graphics/tpx/Scripts/Old_TpXpy/sample_TpXpy.py new file mode 100644 index 0000000000..a40ffcec12 --- /dev/null +++ b/graphics/tpx/Scripts/Old_TpXpy/sample_TpXpy.py @@ -0,0 +1,142 @@ +# Sample Python program using TpXpy +import math +import os +from TpXpy import TpXpic,HTML_color + +pic = TpXpic() +pic.addPolyline(((10,0), (30,-20), (15,-30))) +pic.fill('mintcream') +pic.lw(1.5) +pic.addPolygon(((0,-20), (10,0), (15,-30))) +pic.fill('floralwhite') +pic.lw(1.5) +pic.addLine(0,-20,30,-20) +pic.li('dash') +pic.addCurve(((0,-10), (5,-15), (25,-10), (15,-5), (10,-5))) +pic.closed() +pic.lw(0.5) +pic.ha(4) +pic.hc('silver') +pic.addPolygon(((5.56,-8.9),(12.45,-14.7),(18.3,-8.3))) +pic.li('dot') +pic.addLine(5.56,-8.9,10,0) +pic.lw(1.5) +pic.addLine(12.45,-14.7,10,0) +pic.lw(1.5) +pic.addLine(18.3,-8.3,10,0) +pic.lw(1.5) +pic.addSector(15, -30, 5.5, 0.6, 1.75) +pic.lw(0.5) +pic.addSector(15, -30, 6.5, 0.6, 1.75) +pic.lw(0.5) +pic.addSector(15, -30, 6, 1.75, 2.55) +pic.lw(0.5) +pic.addCircle(0,-20,0.4) +pic.li('none') +pic.fill('navy') +pic.addCircle(10,0,0.4) +pic.li('none') +pic.fill('navy') +pic.addCircle(15,-30,0.4) +pic.li('none') +pic.fill('navy') +pic.addCircle(30,-20,0.4) +pic.li('none') +pic.fill('navy') +pic.addLine(47,0,100,0) +for i in range(5): + pic.addLine(i*10 + 50,-0.7,i*10 + 50,0.7) + pic.addText(i*10 + 50, -1, 3, '%g'%(i*10), '\\texttt{%g}'%(i*10)) + pic.jh('r') + pic.jv('t') + pic.rotdeg(45) +pic.addLine(100,33,100,-33) +for i in range(7): + pic.addLine(100-0.7,i*10-30,100+0.7,i*10-30) + pic.addText(100+6,i*10-30-0.5, 3, '%g'%(i*10-30), '\\texttt{%g}'%(i*10-30)) + pic.jh('r') + pic.jv('c') +pp = () +for i in range(50): + x = i + 50 + y = 30 * math.sin(x/5.0) + p = (x, y), + pp = pp + p +pic.addCurve(pp) +pic.li('dot') +pic.lw(2) +for i in range(50): + x = i + 50 + y = 30 * math.sin(x/5.0) + pic.addStar(x, y + math.sin(i**2*4)*5) + pic.starShape('penta') + pic.starD(0.8) + pic.fill('lightgrey') + pic.lw(0.4) +d = [0] +for ll in range(8): + n = len(d) + for i in range(n): + d.append((d[n-i-1]+1)%4) +dd0 = [(1,0),(0,1),(-1,0),(0,-1)] +cc = ['blue','goldenrod','green','red'] +step = 2.5 +def PP(p): + x = p[0][0]+5 + y = p[0][1]+15 + r = math.sqrt(x**2+y**2) + c = 1 - math.cos(r/5)*0.05 + x = x*c + y = y*c + x,y = x+0.2*y,y-0.2*x + return (x/1.5+23, y/1.5+25), +for j in range(4): + pp = () + x,y = 0,0 + ddpre = [0, 0] + p = (0, 0), + pp = pp + PP(p) + for i in range(len(d)): + dd = dd0[(d[i]+j)%4] + p = (x-ddpre[0]*step*0.1, y-ddpre[1]*step*0.1), + pp = pp + PP(p) + p = (x+dd[0]*step*0.1, y+dd[1]*step*0.1), + pp = pp + PP(p) + p = (x+dd[0]*step*0.5, y+dd[1]*step*0.5), + pp = pp + PP(p) + x = x+dd[0]*step + y = y+dd[1]*step + ddpre = dd + p = (x, y), + pp = pp + PP(p) + PP(p) + PP(p) + pic.addBezier(pp) + pic.lc(cc[j]) +pic.addRect(28, -6, 57, 57) +pic.rotdeg(45) +d=2.8 +for i in range(12): + for j in range(12): + pic.addEllipse(i*d+70,j*d+43,d*0.7,d*0.9) + pic.rotdeg(45) + pic.fill(HTML_color(255*(0.5+0.5*math.sin(i/3.+math.sin(j/3.)*2)),\ + 255*(0.5+0.5*math.cos(j/3.-i**2/30.)),0)) + pic.li('none') +pic.addCurve(((25,75), (0,65), (-13,38))) +pic.arr('oc','h43',0.8) +pic.lw(0.5) +pic.addSymbol(52,70,25,'cloud1') +pic.lw(0.5) +pic.fill('whitesmoke') +pic.rotdeg(188) +pic.addText(52,70,5,'Fig 1') +pic.jh('c') +pic.jv('c') +pic.setCaption('A sample TpXpy picture', 'fig:TpXpy') +pic.setComment('Comment') +pic.setRootAttribute('BitmapRes', 11811) +pic.setRootAttribute('LineWidth', 0.25) +pic.setRootAttribute('MiterLimit', 1) +pic.setRootAttribute('HatchingStep', 1) +fname = 'sample_TpXpy.TpX' +pic.SaveToFile(fname) +os.startfile(fname) diff --git a/graphics/tpx/Scripts/Old_TpXpy/sample_TpXpy_Roulette.py b/graphics/tpx/Scripts/Old_TpXpy/sample_TpXpy_Roulette.py new file mode 100644 index 0000000000..520be1b4f5 --- /dev/null +++ b/graphics/tpx/Scripts/Old_TpXpy/sample_TpXpy_Roulette.py @@ -0,0 +1,132 @@ +import math +import os +from TpXpy import TpXpic,HTML_color + +def TransformPoint(P,T): + return (T[0][0]*P[0] + T[1][0]*P[1] + T[2][0], + T[0][1]*P[0] + T[1][1]*P[1] + T[2][1]) + +def TransformPoints(PP,T): + PP2 = [] + for i in range(len(PP)): + PP2.append(TransformPoint(PP[i],T)) + return PP2 + +pic = TpXpic() + +#pic.addPolygon(((20,0,0), (0,0), (0,70,0))) + +pp = () +p = (60,45),; pp = pp + p +p = (55,45),; pp = pp + p +p = (50,40),; pp = pp + p +p = (36,45),; pp = pp + p +#pic.addCurve(pp); pic.lw('0.5') + +digits = [] +digits.append([(62,104), (62,102), (62,87), (62,85), (62,83), (60,83), (60,85), (60,87), (60,117), (60,119), (60,121), (62,121), (62,119), (62,117), (62,105), (62,103), (64,103), (66,103), (68,103), (68,105), (68,118), (68,120), (68,122), (66,124), (64,124), (62,124), (60,124), (58,124), (56,124), (54,122), (54,120), (54,118), (54,86), (54,84), (54,82), (56,80), (58,80), (60,80), (62,80), (64,80), (66,80), (68,82), (68,84), (68,86), (68,102), (68,104), (66,104), (64,104)]) +digits.append([(74,80), (76,80), (78,80), (80,80), (80,82), (80,122), (80,124), (78,124), (77,124), (75,124), (75,122), (73,118), (70,117), (70,115), (70,114), (70,112), (70,112), (73,113), (74,114), (74,112), (74,82)]) +digits.append([(86,80), (88,80), (98,80), (100,80), (100,81), (100,83), (100,84), (98,84), (94,84), (92,84), (92,85), (92,84), (92,86), (92,90), (100,102), (100,106), (100,108), (100,118), (100,120), (100,122), (98,124), (96,124), (94,124), (92,124), (90,124), (88,124), (86,122), (86,120), (86,118), (86,110), (86,108), (88,108), (90,108), (92,108), (92,110), (92,117), (92,119), (92,121), (94,121), (94,119), (94,117), (94,108), (94,106), (94,102), (86,90), (86,86), (86,83), (86,82)]) +digits.append([(108,80), (110,80), (112,80), (114,80), (116,80), (118,82), (118,84), (118,86), (118,96), (118,98), (118,100), (116,102.4), (114,102.4), (114,102.8), (114,102.8), (114,102.8), (116,102.8), (118,105), (118,107), (118,109), (118,118), (118,120), (118,122), (116,124), (114,124), (112,124), (110,124), (108,124), (106,124), (104,122), (104,120), (104,118), (104,111), (104,109), (106,109), (108,109), (110,109), (110,111), (110,117), (110,119), (110,121), (112,121), (112,119), (112,117), (112,109), (112,107), (112,105), (110,104), (108,104), (108,103), (108,102), (108,101), (110,101), (112,100), (112,98), (112,96), (112,87), (112,85), (112,83), (110,83), (110,85), (110,87), (110,94), (110,96), (108,96), (106,96), (104,96), (104,94), (104,86), (104,84), (104,82), (106,80)]) +digits.append([(130,80), (131.5,80), (134.5,80), (136,80), (136,91), (136,113), (136,124), (133.75,124), (129.25,124), (127,124), (125.5,116.75), (122.5,102.25), (121,95), (121,94), (121,92), (121,91), (125.25,91), (133.75,91), (138,91), (138,92), (138,94), (138,95), (135,95), (129,95), (126,95), (127,100.5), (129,111.5), (130,117), (130,107.75), (130,89.25)]) +digits.append([(142,124), (144,124), (154,124), (156,124), (156,123), (156,121), (156,120), (154,120), (150,120), (148,120), (148,118), (148,112), (148,111), (149,112), (150,112), (152,112), (154,112), (156,110), (156,108), (156,106), (156,86), (156,84), (156,82), (154,80), (152,80), (150,80), (148,80), (146,80), (144,80), (142,82), (142,84), (142,86), (142,94), (142,96), (144,96), (146,96), (148,96), (148,94), (148,87), (148,85), (148,83), (150,83), (150,85), (150,87), (150,104), (150,106), (150,108), (148,108), (148,106), (148,105), (148,103), (148,102), (146,102), (144,102), (142,102), (142,104), (142,122)]) +digits.append([(165,124), (167,124), (169,124), (171,124), (173,124), (175,122), (175,120), (175,118), (175,113), (175,111), (173,111), (171,111), (169,111), (169,113), (169,117), (169,119), (169,121), (167,121), (167,119), (167,117), (167,107), (167,106), (168,107), (169,107), (171,107), (173,107), (175,105), (175,103), (175,101), (175,86), (175,84), (175,82), (173,80), (171,80), (169,80), (167,80), (165,80), (163,80), (161,82), (161,84), (161,86), (161,94), (161,96), (163,96), (165,96), (167,96), (167,94), (167,87), (167,85), (167,83), (169,83), (169,85), (169,87), (169,99), (169,101), (169,103), (167,103), (167,101), (167,100), (167,95), (167,93), (165,93), (163,93), (161,93), (161,95), (161,118), (161,120), (161,122), (163,124)]) +digits.append([(180,80), (181.5,80), (184.5,80), (186,80), (188,90), (192,110), (194,120), (194,121), (194,123), (194,124), (190,124), (182,124), (178,124), (178,123), (178,121), (178,120), (180.5,120), (185.5,120), (188,120), (186,110), (182,90)]) +digits.append([(202,80), (204,80), (206,80), (208,80), (210,80), (212,82), (212,84), (212,86), (212,96), (212,98), (212,100), (210,102.4), (208,102.4), (208,102.8), (208,102.8), (208,102.8), (210,102.8), (212,105), (212,107), (212,109), (212,118), (212,120), (212,122), (210,124), (208,124), (206,124), (204,124), (202,124), (200,124), (198,122), (198,120), (198,118), (198,113), (198,111), (200,111), (202,111), (204,111), (204,113), (204,117), (204,119), (204,121), (206,121), (206,119), (206,117), (206,109), (206,107), (206,105), (204,105), (204,107), (204,109), (204,114), (204,116), (202,116), (200,116), (198,116), (198,114), (198,109), (198,107), (198,105), (200,102.8), (202,102.8), (202,102.4), (202,102.4), (202,102.4), (200,102.4), (198,100), (198,98), (198,96), (198,92), (198,90), (200,90), (202,90), (204,90), (204,92), (204,96), (204,98), (204,100), (206,100), (206,98), (206,96), (206,87), (206,85), (206,83), (204,83), (204,85), (204,87), (204,93), (204,95), (202,95), (200,95), (198,95), (198,93), (198,86), (198,84), (198,82), (200,80)]) +digits.append([(227,80), (225,80), (223,80), (221,80), (219,80), (217,82), (217,84), (217,86), (217,91), (217,93), (219,93), (221,93), (223,93), (223,91), (223,87), (223,85), (223,83), (225,83), (225,85), (225,87), (225,97), (225,98), (224,97), (223,97), (221,97), (219,97), (217,99), (217,101), (217,103), (217,118), (217,120), (217,122), (219,124), (221,124), (223,124), (225,124), (227,124), (229,124), (231,122), (231,120), (231,118), (231,110), (231,108), (229,108), (227,108), (225,108), (225,110), (225,117), (225,119), (225,121), (223,121), (223,119), (223,117), (223,105), (223,103), (223,101), (225,101), (225,103), (225,105), (225,109), (225,111), (227,111), (229,111), (231,111), (231,109), (231,86), (231,84), (231,82), (229,80)]) +digits_width = [] +for d in range(len(digits)): + dd = digits[d] + minX = 1000000; minY = 1000000 + maxX = -1000000 + for i in range(len(dd)): + if dd[i][0]<minX: minX = dd[i][0] + if dd[i][1]<minY: minY = dd[i][1] + if dd[i][0]>maxX: maxX = dd[i][0] + T = ((1,0),(0,1),(-minX,-minY)) + digits[d] = TransformPoints(dd,T) + digits_width.append(maxX-minX) + +numbers = [-1,1,13,36,24,3,15,34,22,5,17,32,20,7,11,30,26,9,28,0,2,14,35,23,4,16,33,21,6,18,31,19,8,12,29,25,10,27] + +cos = []; sin = [] +for i in range(39): + cos.append(math.cos(math.pi/19*i)) + sin.append(math.sin(math.pi/19*i)) +pic.addCircle(0,0,146) +#pic.li('none') +pic.lc('gray') +pic.lw(2) +pic.fill('#A94E2C') +for i in range(38): + j=i+1 + pic.addPolygon(((31*cos[i],31*sin[i]), (48*cos[i],48*sin[i]), + (48*cos[j],48*sin[j]), (31*cos[j],31*sin[j]))) + pic.li('none') + if (i==0)|(i==19): pic.fill('mediumseagreen') + elif i%2==0: pic.fill('crimson') + else: pic.fill('black') +for i in range(38): + pic.addLine(31*cos[i],31*sin[i], 48*cos[i],48*sin[i]) + pic.lc('gray') + pic.lw(3) +pic.addCircle(0,0,124) +pic.lc('gray') +pic.lw(4) +pic.addCircle(0,0,96) +pic.lc('gray') +pic.lw(4) +pic.addCircle(0,0,80) +pic.lc('gray') +pic.lw(2) +pic.addCircle(0,0,62) +pic.lc('gray') +pic.fill('wheat') +pic.lw(4) +pic.addCircle(-25,-28,4) +pic.lc('wheat') +pic.fill('lightslategray') +pic.lw(1) + +def DigitRender(PP,T): + PP = TransformPoints(PP,T) + T = ((asin*s,-acos*s),(acos*s,asin*s),(41.7*acos, 41.7*asin)) + PP = TransformPoints(PP,T) + pic.addBezier(PP) + pic.closed() + pic.li('none') + pic.fill('beige') # white + +for i in range(38): + j=i+1 + acos = (cos[i]+cos[j])/2 + asin = (sin[i]+sin[j])/2 + s = 0.1 + d1 = numbers[i]//10 + d2 = numbers[i]%10 + if d1==0: d1 = -2 + if d1==-1: d1 = 0; d2 = 0 + if d1>-2: + w1 = digits_width[d1] + w2 = digits_width[d2] + w = w1 + w2 + 4 + else: + w = digits_width[d2] + d1 = d2 + w2 = 0 + PP = digits[d1] + T = ((1,0),(0,1),(-w/2, 0)) + DigitRender(PP,T) + if w2 > 0: + PP = digits[d2] + T = ((1,0),(0,1),(w/2-w2, 0)) + DigitRender(PP,T) + +pic.setComment('Roulette') +pic.setRootAttribute('LineWidth', 0.35) +pic.setRootAttribute('MiterLimit', 10) +pic.setRootAttribute('TeXFigure', 'none') +pic.setRootAttribute('TeXCenterFigure', '0') +fname = 'Roulette.TpX' +pic.SaveToFile(fname) +os.startfile(fname) |