
insdraw_size=$(psize)1,$(psize)1
# colors
!distribute items 200000000,000000255,000200000,255200000,000200255\
	into c0,c1,c2,c3,c4
f0=<font color=red>0</font>
f1=<font color=blue>1</font>
f2=<font color=green>2</font>
f3=<font color=#ffc000>3</font>
f4=<font color=#00c0ff>4</font>
flist2=$f0$f1
flist3=$f0$f1$f2
flist5=$f0$f1$f2$f3$f4
flist=$(flist$q)

template=!record 1 of writable/src.$Size
template=!trim $template
!if $template=$empty
 !for y=0 to $psize-1
  !for x=0 to $psize-1
   template=$template\
frect $[$x*10+1],$[$y*10+1],$[$x*10+9],$[$y*10+9],XXX,XXX,XXX
  !next x
 !next y
 !writefile src.$Size :$template
!endif

oseq=!text repeat $orgseq to $psize*$psize
!read polynomials/tables
pic1=!text interact $pic and $oseq table $(add$q)
!if $resseq!=$empty
  rseq=!text repeat $resseq to $psize*$psize
  pic2=!text interact $pic and $rseq table $(add$q)
  pp=!translate 012345 to abcdef in $pic2
  pp=!replace a by $c0 in $pp
  pp=!replace b by $c1 in $pp
  pp=!replace c by $c2 in $pp
  pp=!replace d by $c3 in $pp
  pp=!replace e by $c4 in $pp
  mask=!text mark X in $template
  draw_src2=!text insert $pp into $template mask $mask
!endif

pp=!translate 012345 to abcdef in $pic1
pp=!replace a by $c0 in $pp
pp=!replace b by $c1 in $pp
pp=!replace c by $c2 in $pp
pp=!replace d by $c3 in $pp
pp=!replace e by $c4 in $pp
mask=!text mark X in $template
draw_src1=!text insert $pp into $template mask $mask
draw_hd=fill 0,0,255,255,255

