vectorgraphics / asymptote

2D & 3D TeX-Aware Vector Graphics Language
https://asymptote.sourceforge.io/
GNU General Public License v3.0
547 stars 90 forks source link

void draw(picture pic=currentpicture, pen fillrule=currentpen, path[] g, pen[] p); does not work as expected. #282

Closed justonlyasy closed 2 years ago

justonlyasy commented 2 years ago

Consider this code,

int plotpoints = 3;
int n = plotpoints + 1;

pen[] yourpens = { red, green, blue, yellow};
path g = (0,0)--(4,0);
real l = arclength(g)/n; // 
path[] g_ = sequence(new path(int i){ return subpath(g,arctime(g,i*l),arctime(g,(i+1)*l));},n);

write(g_);
write(yourpens);
draw(g_,yourpens);

I get this error on http://asymptote.ualberta.ca/

Error: /undefinedfilename in (workspace1.pdf) Operand stack:

Execution stack: %interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push Dictionary stack: --dict:731/1123(ro)(G)-- --dict:0/20(G)-- --dict:75/200(L)-- Current allocation mode is local Last OS error: Permission denied _shipout(prefix,f,currentpatterns,format,wait,view,t); ^ /usr/local/share/asymptote/plain_shipout.asy: 108.11: runtime: shipout failed GPL Ghostscript 9.53.3: Unrecoverable error, exit code 1

Maybe a bug or not ?

johncbowman commented 2 years ago

If you enable settings.verbose=2, you will see the message No pages of output. Hence the subsequent error. To generate output, change the last line to

for(int i=0; i < 4; ++i) draw(g_[i],yourpens[i]);

justonlyasy commented 2 years ago
for(int i=0; i < 4; ++i)
draw(g_[i],yourpens[i]);

works , but my purpose is One can also smoothly shade the regions... So Asymptote maybe have a command for doing it?

justonlyasy commented 2 years ago

This question inspired from

size(10cm,0);
import graph;

mapArray("real","pen");
void pspathHSV(path g, pen p=linewidth(1mm)+linecap(2), real HueBegin=0, real HueEnd=1, int plotpoints=100)
{
  real[] a=uniform(HueBegin*360,HueEnd*360,plotpoints); 
  pen[] q = map(new pen(real i){ return hsv(i,1,1)+p;},a);
  int n = plotpoints+1;
  real l = arclength(g)/n;
  path[] p = sequence(new path(int i){ return subpath(g,arctime(g,i*l),arctime(g,(i+1)*l));},n);
  // draw(p,q);
  for (int i=0; i<q.length; ++i)
    draw(p[i],q[i]);
}

guide g=graph(new real(real x){ return sin(x);},0,2pi,350);
pspathHSV((0,0)--(10,1),HueBegin=0,HueEnd=0.5);
pspathHSV((0,1)--(10,3),HueBegin=0.5,HueEnd=0.7);
pspathHSV((0,2)--(10,5),HueBegin=0.8,HueEnd=1);
pspathHSV(g,linewidth(1bp),plotpoints=350);

pspathHSV((0,4)--(3,4),linewidth(1.5cm)+linecap(2),HueBegin=0,HueEnd=1,plotpoints=360);

new1

pspathHSV(g,linewidth(1bp)+opacity(.5),plotpoints=350);. image