forked from kodamail/gscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrawpoly.gs
175 lines (160 loc) · 4.23 KB
/
drawpoly.gs
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
*
* Help is in the end of this script
*
function drawpoly( args )
_version = '0.02r2'
rc = gsfallow( 'on' )
if( args = '' )
help()
return
endif
* pos = 1
***** Default value
* closed: for drawline.gs
closed = 1
by = 'xy'
fill = 0
r = -1
g = -1
b = -1
a = -1
setline = ''
***** Arguement *****
i = 1
p = 0
while( 1 )
arg = subwrd( args, i )
i = i + 1;
if( arg = '' ); break; endif
while( 1 )
*** option
if( arg = '-o' | arg = 'opened' ) ; closed = 0 ; break ; endif
if( arg = '-f' ) ; fill = 1 ; break ; endif
if( arg = '-by' ) ; by=subwrd(args,i) ; i=i+1 ; break ; endif
if( arg = '-rgb' )
r = subwrd(args,i)
g = subwrd(args,i+1)
b = subwrd(args,i+2)
i=i+3 ; break
endif
if( arg = '-rgba' )
r = subwrd(args,i)
g = subwrd(args,i+1)
b = subwrd(args,i+2)
a = subwrd(args,i+3)
i=i+4 ; break
endif
if( arg = '-setline' )
setline = subwrd(args,i) ; i=i+1
tmp = subwrd(args,i)
if( valnum(tmp) != 0 ) ; setline = setline % ' ' % tmp ; i=i+1 ; endif
tmp = subwrd(args,i)
if( valnum(tmp) != 0 ) ; setline = setline % ' ' % tmp ; i=i+1 ; endif
break
endif
if( arg = '-a' ) ; a=subwrd(args,i) ; i=i+1 ; break ; endif
if( valnum(arg) != 0 )
x.p = arg
y.p = subwrd(args,i)
i = i + 1
p = p + 1
break
endif
say 'syntax error: 'arg
return
endwhile
endwhile
pmax = p - 1
* color table from http://cola.gmu.edu/grads/gadoc/colorcontrol.html
r.0 = 0 ; g.0 = 0 ; b.0 = 0
r.1 = 255 ; g.1 = 255 ; b.1 = 255
r.2 = 250 ; g.2 = 60 ; b.2 = 60
r.3 = 0 ; g.3 = 220 ; b.3 = 0
r.4 = 30 ; g.4 = 60 ; b.4 = 255
r.5 = 0 ; g.5 = 200 ; b.5 = 200
r.6 = 240 ; g.6 = 0 ; b.6 = 130
r.7 = 230 ; g.7 = 220 ; b.7 = 50
r.8 = 240 ; g.8 = 130 ; b.8 = 40
r.9 = 160 ; g.9 = 0 ; b.9 = 200
r.10 = 160 ; g.10 = 230 ; b.10 = 50
r.11 = 0 ; g.11 = 160 ; b.11 = 255
r.12 = 230 ; g.12 = 175 ; b.12 = 45
r.13 = 0 ; g.13 = 210 ; b.13 = 140
r.14 = 130 ; g.14 = 0 ; b.14 = 220
r.15 = 170 ; g.15 = 170 ; b.15 = 170
if( setline != '' )
'set line 'setline
if( a != -1 )
c = subwrd( setline, 1 )
'set rgb 99 'r.c' 'g.c' 'b.c' 'a
'set line 99'
endif
endif
if( r != -1 & g != -1 & g != -1 )
if( a != -1 ) ; 'set rgb 99 'r' 'g' 'b' 'a
else ; 'set rgb 99 'r' 'g' 'b
endif
'set line 99'
endif
p = 0
pmm = -1
str_fill = ''
while( p <= pmax )
if( by = 'world' ) ; xy.p = qw2xy( x.p, y.p ) ; endif
if( by = 'grid' ) ; xy.p = qgr2xy( x.p, y.p ) ; endif
if( by = 'xy' ) ; xy.p = x.p % ' ' % y.p ; endif
if( pmm >= 0 & fill = 0 )
'draw line 'xy.pmm' 'xy.p
endif
if( fill = 1 )
str_fill = str_fill % xy.p % ' '
endif
p = p + 1
pmm = pmm + 1
endwhile
if( fill = 0 & closed = 1 )
'draw line 'xy.pmax' 'xy.0
endif
if( fill = 1 )
'draw polyf 'str_fill
endif
return
*
* help
*
function help()
say ' Name:'
say ' drawpoly '_version' - draw polygon'
say ' '
say ' Usage:'
say ' drawpoly [ -o | open ]'
say ' [ -f ]'
say ' [ -rgb r g b ]'
say ' [ -rgba r g b a ]'
say ' [ -setline setline-options ]'
say ' [ -by ( world | grid | xy ) ] x1 y1 x2 y2 ...'
say ' '
say ''
say ' -o | open : open polygon (for drawline.gs)'
say ''
say ' -f : filled'
say ''
say ' -rgb | -rgba : rgb or rgba values in [0-255]'
say ''
say ' -setline : options same as "set line"'
say ''
say ' -by : unit of p1, q1, p2, q2'
say ' world : world coordinate (e.g. lat)'
say ' grid : grid coordinate (grid number)'
say ' xy : same as "draw line"'
say ''
say ' x1, y1, ... : positions'
say ''
say ' Note:'
say ' [arg-name] : specify if needed'
say ' (arg1 | arg2) : arg1 or arg2 must be specified'
say ''
say ' Copyright (C) 2013-2019 Chihiro Kodama'
say ' Distributed under GNU GPL (http://www.gnu.org/licenses/gpl.html)'
say ''
return