Uh oh!
There was an error while loading. Please reload this page.
This repository was archived by the owner on Nov 20, 2020. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.lua
More file actions
Latest commit
132 lines (118 loc) · 2.61 KB
/
Copy pathtest.lua
File metadata and controls
132 lines (118 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
-- test gpc library
localP=require"gpc"
print(P.version)
functionoutput(f,...)
fori=1,arg.ndo
f:write(arg[i],"")
end
f:write("\n")
end
functionplottri(f,p,r,g,b,w)
ifw=="stroke" thenoutput(f,0,"setlinewidth") end
output(f,r,g,b,"setrgbcolor")
forc=1,p:get() do
localn=p:get(c)
localx1,y1=p:get(c,1)
localx2,y2=p:get(c,2)
fori=3,ndo
localx,y=p:get(c,i)
output(f,x1,y1,"moveto")
output(f,x2,y2,"lineto")
output(f,x,y,"lineto")
output(f,"closepath")
x1,y1,x2,y2=x2,y2,x,y
end
end
output(f,w)
end
functionplot(f,p,r,g,b,w)
output(f,r,g,b,"setrgbcolor")
forc=1,p:get() do
localn,h=p:get(c)
locals="moveto"
fori=1,ndo
localx,y=p:get(c,i)
output(f,x,y,s)
s="lineto"
end
output(f,"closepath")
end
output(f,w)
end
functionshow(n,f,p,r,g,b,w)
output(f)
output(f,"%%Page:",w,n)
output(f,"setup")
plot(f,p,r,g,b,"eofill")
plot(f,p,0,0,0,"stroke")
output(f,"showpage")
end
N=0
functionpage(f,p,w,r,g,b)
N=N+1
print(N,p:get(),w)
show(N,f,p,r,g,b,w)
end
functionbbox(p,xmin,xmax,ymin,ymax)
localhuge=1e30
xmin=xminorhuge
xmax=xmaxor-huge
ymin=yminorhuge
ymax=ymaxor-huge
forc=1,p:get() do
fori=1,p:get(c) do
localx,y=p:get(c,i)
ifx<xminthenxmin=xelseifx>xmaxthenxmax=xend
ify<yminthenymin=yelseify>ymaxthenymax=yend
end
end
returnxmin,xmax,ymin,ymax
end
functiontest(file)
localX0,Y0,DX,DY=50,50,500,500
localxmin,xmax,ymin,ymax=bbox(b,bbox(a))
print("bbox",xmin,xmax,ymin,ymax)
localdx=xmax-xmin
localdy=ymax-ymin
locald=(dx-dy)/2
if (d>0) thenymin=ymin-dymax=ymax+dd=dxelsexmin=xmin-dxmax=xmax+dd=dyend
localf=assert(io.open(file,"w"))
output(f,"%!PS-Adobe-2.0")
output(f,"%%Title: gpc lua test")
output(f,"%%%BoundingBox:",X0-5,Y0-5,X0+DX+5,Y0+DY+5) -- inactive
output(f,"%%Creator:",P.version)
output(f,"%%Pages:",9)
output(f,"%%EndComments")
output(f,"/setup {",X0,Y0,"translate",DX,DY,"scale")
output(f,"1",d,"div dup scale",-xmin,-ymin,"translate")
output(f,d/200,"setlinewidth} def")
page(f,a,"a",1,0.8,0.8)
page(f,b,"b",0.8,0.8,1)
page(f,a+b,"union",0.8,1,0.8)
page(f,a*b,"intersection",0.8,1,0.8)
page(f,a-b,"diff",1,0.8,0.8)
page(f,b-a,"diff",0.8,0.8,1)
page(f,a^b,"xor",0.8,1,0.8)
page(f,a,"a",1,0.8,0.8)
plot=plottri
page(f,a:strip(),"strip",1,0.8,0.8)
output(f,"%%EOF")
f:close()
end
------------------------------------------------------------------------------
a=P.new():add{
1315 , 1282 ,
1315 , 1329 ,
1300 , 1314 ,
1284 , 1345 ,
1253 , 1312 ,
1284 , 1298 ,
1268 , 1282 ,
}
b=P.new():add{
1290 , 1270 ,
1335 , 1315 ,
1250 , 1340 ,
}
test"test.ps"
print(P.version)