Subversion Repositories wimsdev

Rev

Rev 18665 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 18665 Rev 18669
Line 139... Line 139...
139
  font_size = 12;/* this may lead to problems when using something like <code>fontfamily Italic 24px Arial</code> the ''fontsize`` value is not substituted into fontfamily !! */
139
  font_size = 12;/* this may lead to problems when using something like <code>fontfamily Italic 24px Arial</code> the ''fontsize`` value is not substituted into fontfamily !! */
140
  int fly_font_size = 12; /*fly_font_size is relative to this... */
140
  int fly_font_size = 12; /*fly_font_size is relative to this... */
141
  for(i=0;i<MAX_JS_FUNCTIONS;i++){js_function[i]=0;}
141
  for(i=0;i<MAX_JS_FUNCTIONS;i++){js_function[i]=0;}
142
  int arrow_head = 8; /* size in px needed for arrow based  userdraw:  "userdraw arrow,color" */
142
  int arrow_head = 8; /* size in px needed for arrow based  userdraw:  "userdraw arrow,color" */
143
  int crosshair_size = 5; /* size in px*/
143
  int crosshair_size = 5; /* size in px*/
-
 
144
  int level_step = 1; /* resolution in pixels of level curves */
144
  int plot_steps = 250;/* the js-arrays with x_data_points and y_data_points will have size 250 each: use with care !!! use jscurve when precise plots are required  */
145
  int plot_steps = 250;/* the js-arrays with x_data_points and y_data_points will have size 250 each: use with care !!! use jscurve when precise plots are required  */
145
  int found_size_command = 0; /* 1 = found size ; 2 = found xrange; 3 = found yrange: just to flag an error message */
146
  int found_size_command = 0; /* 1 = found size ; 2 = found xrange; 3 = found yrange: just to flag an error message */
146
  int object_cnt = 0; /*counter to identify the "onclick" ojects ; 0 is first object set onclick: reply[object_cnt]=1 when clicked ; otherwise reply[object_cnt]=0 ; object_cnt is only increased when another object is set  again */
147
  int object_cnt = 0; /*counter to identify the "onclick" ojects ; 0 is first object set onclick: reply[object_cnt]=1 when clicked ; otherwise reply[object_cnt]=0 ; object_cnt is only increased when another object is set  again */
147
  int clock_cnt = 0; /* counts the amount of clocks used -> unique object clock%d */
148
  int clock_cnt = 0; /* counts the amount of clocks used -> unique object clock%d */
148
  int boxplot_cnt = 0;
149
  int boxplot_cnt = 0;
Line 1665... Line 1666...
1665
  @ any color (object) in the <a href="#canvastype">canvastype</a> will act as border to the bucket fill
1666
  @ any color (object) in the <a href="#canvastype">canvastype</a> will act as border to the bucket fill
1666
  @ use this command after all boundary objects are declared.
1667
  @ use this command after all boundary objects are declared.
1667
  @ Use command 'userdraw clickfill,color' for user click driven flood fill.
1668
  @ Use command 'userdraw clickfill,color' for user click driven flood fill.
1668
  @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5)
1669
  @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5)
1669
  @ note: the fill-family of commands are very (client) cpu intensive operations!<br>filling is done pixel by pixel e.g. image size of 400x400 uses 160000 pixels: each pixel contains 4 data (R,G,B,Opacity) = 640000 data.<br>on every data a few operations / comparisons are done...<br>So have pity on your students CPU..
1670
  @ note: the fill-family of commands are very (client) cpu intensive operations!<br>filling is done pixel by pixel e.g. image size of 400x400 uses 160000 pixels: each pixel contains 4 data (R,G,B,Opacity) = 640000 data.<br>on every data a few operations / comparisons are done...<br>So have pity on your students CPU..
1670
  @%fillall%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%vlines black,-5,0,-5,0,-4,0,-4,0,3,0,3,0%hlines black,-5,0,-5,0,-5,4,-5,4,-5,-2,-5,-2%circles green,0,0,2,3,3,5,-5,-5,3%opacity 240,50%fillall blue,1,1,8,8,-8,-8
1671
  @%fillall%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%vlines black,-5,0,-4,0,3,0,hlines black,-5,0,-5,4,-5,-2,%circles green,0,0,2,3,3,5,-5,-5,3%opacity 240,50%fillall blue,1,1,8,8,-8,-8
1671
  */
1672
  */
1672
          decimals = find_number_of_digits(precision);
1673
          decimals = find_number_of_digits(precision);
1673
          fill_color=get_color(infile,0); /* how nice: now the color comes first...*/
1674
          fill_color=get_color(infile,0); /* how nice: now the color comes first...*/
1674
          i=0;
1675
          i=0;
1675
          if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
1676
          if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
Line 2712... Line 2713...
2712
  @ linewidth int
2713
  @ linewidth int
2713
  @ default 1
2714
  @ default 1
2714
  @%linewidth%size 400,400%xrange -10,10%yrange -10,10%linewidth 1%line -5,-5,-5,5,red%linewidth 2%line -4,-5,-4,5,green%linewidth 3%line -3,-5,-3,5,blue%linewidth 4%line -2,-5,-2,5,orange%linewidth 1%line -1,-5,-1,5,brown%linewidth 5%line 1,-5,1,5,cyan%linewidth 6%line 3,-5,3,5,purple%linewidth 7%line 5,-5,5,5,black
2715
  @%linewidth%size 400,400%xrange -10,10%yrange -10,10%linewidth 1%line -5,-5,-5,5,red%linewidth 2%line -4,-5,-4,5,green%linewidth 3%line -3,-5,-3,5,blue%linewidth 4%line -2,-5,-2,5,orange%linewidth 1%line -1,-5,-1,5,brown%linewidth 5%line 1,-5,1,5,cyan%linewidth 6%line 3,-5,3,5,purple%linewidth 7%line 5,-5,5,5,black
2715
  */
2716
  */
2716
          line_width = (int) (get_real(infile,1));
2717
          line_width = (int) (get_real(infile,1));
-
 
2718
          break;
-
 
2719
        case LEVELSTEP:
-
 
2720
          level_step = (int) (get_real(infile,1));
-
 
2721
          if (level_step < 1) level_step=1;
-
 
2722
          if (level_step > 16) level_step=16;
2717
          break;
2723
          break;
2718
        case LEVELCURVE:
2724
        case LEVELCURVE:
2719
  /*
2725
  /*
2720
  @ levelcurve color,expression in x/y,l1,l2,...
2726
  @ levelcurve color,expression in x/y,l1,l2,...
2721
  @ draws very primitive level curves for expression, with levels l1,l2,l3,...,l_n
2727
  @ draws very primitive level curves for expression, with levels l1,l2,l3,...,l_n
Line 2735... Line 2741...
2735
            i++;
2741
            i++;
2736
          }
2742
          }
2737
          if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
2743
          if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
2738
          for(c = 0 ; c < i; c++){
2744
          for(c = 0 ; c < i; c++){
2739
            tmp_buffer=my_newmem(MAX_BUFFER);
2745
            tmp_buffer=my_newmem(MAX_BUFFER);
2740
            check_string_length(snprintf(tmp_buffer,MAX_BUFFER, "dragstuff.addShape(new Shape(%d,%d,%d,%d,16,%s,[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,eval_levelcurve(xsize,ysize,fun1,xmin,xmax,ymin,ymax,plot_steps,precision,double_data[c]),line_width,line_width,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset));
2746
            check_string_length(snprintf(tmp_buffer,MAX_BUFFER, "dragstuff.addShape(new Shape(%d,%d,%d,%d,16,%s,[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,eval_levelcurve(xsize,ysize,fun1,xmin,xmax,ymin,ymax,level_step,precision,double_data[c]),line_width,line_width,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset));
2741
            add_to_buffer(tmp_buffer);
2747
            add_to_buffer(tmp_buffer);
2742
            if(onclick != 0){object_cnt++;}
2748
            if(onclick != 0){object_cnt++;}
2743
           /* object_cnt++; */
2749
           /* object_cnt++; */
2744
          }
2750
          }
2745
          dragstuff[16] = 1;
2751
          dragstuff[16] = 1;
Line 3480... Line 3486...
3480
          reset();
3486
          reset();
3481
          break;
3487
          break;
3482
        case PLOTSTEPS:
3488
        case PLOTSTEPS:
3483
      /*
3489
      /*
3484
  @ plotsteps a_number
3490
  @ plotsteps a_number
3485
  @ default 150
3491
  @ default 250
3486
  @ only used for commands <a href="#curve">curve / plot</a> and <a href="#levelcurve">levelcurve</a>
3492
  @ only used for commands <a href="#curve">curve / plot</a>
3487
  @ use with care !
3493
  @ use with care !
3488
      */
3494
      */
3489
          plot_steps = (int) (get_real(infile,1));
3495
          plot_steps = (int) (get_real(infile,1));
3490
          break;
3496
          break;
3491
        case POINT:
3497
        case POINT:
Line 6367... Line 6373...
6367
  return double_xy2js_array(xydata,i,find_number_of_digits(precision));
6373
  return double_xy2js_array(xydata,i,find_number_of_digits(precision));
6368
}
6374
}
6369
static int filtre (int a, int b, int c, int d){
6375
static int filtre (int a, int b, int c, int d){
6370
  return ((a>0)||(b>0)||(c>0)||(d>0))&&((a<0)||(b<0)||(c<0)||(d<0));
6376
  return ((a>0)||(b>0)||(c>0)||(d>0))&&((a<0)||(b<0)||(c<0)||(d<0));
6371
}
6377
}
6372
/* plot a very primitive (!) levelcurve : not to be compared with "flydraw levelcurve"
6378
/* plot a levelcurve
6373
  modified 04/07/2025 bernardi
6379
  modified 08/2025 bernardi */
6374
  pts for plotsteps*/
-
 
6375
char *eval_levelcurve(int xsize,int ysize,char *fun,double xmin,double xmax,double ymin,double ymax,int pts,int precision,double level){
6380
char *eval_levelcurve(int xsize,int ysize,char *fun,double xmin,double xmax,double ymin,double ymax,int levelstep,int precision,double level){
6376
  void *f = eval_create(fun);
6381
  void *f = eval_create(fun);
6377
  if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;}
6382
  if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;}
-
 
6383
  int ptx=xsize/levelstep, pty=ysize/levelstep;
6378
  double dx = (xmax - xmin)/pts;
6384
  double dx = (xmax - xmin)/ptx;
6379
  double dy = (ymax - ymin)/pts;
6385
  double dy = (ymax - ymin)/pty;
6380
  int sgns[(pts+1)*(pts+1)];
6386
  int sgns[(ptx+1)*(pty+1)];
6381
  double x, y, diff, xydata[MAX_BUFFER+1];
6387
  double x, y, diff, xydata[MAX_BUFFER+1];
6382
  int i, j, k;
6388
  int i, j, k;
6383
  for (j = 0; j <= pts; ++j)
6389
  for (j = 0; j <= ptx; ++j)
6384
    for (k = 0; k <= pts; ++k){
6390
    for (k = 0; k <= pty; ++k){
6385
      x = xmin + j*dx;
6391
      x = xmin + j*dx;
6386
      y = ymin + k*dy;
6392
      y = ymin + k*dy;
6387
      diff = eval_x_y(f,x,y) - level;
6393
      diff = eval_x_y(f,x,y) - level;
6388
      sgns[k+j*(pts+1)] = (diff > 0) ? 1 : -(diff < 0);
6394
      sgns[k+j*(pty+1)] = (diff > 0) ? 1 : -(diff < 0);
6389
    };
6395
    };
6390
  i = 0;
6396
  i = 0;
6391
  for (j = 0; j < pts; ++j)
6397
  for (j = 0; j < ptx; ++j)
6392
    for (k = 0; k < pts; ++k){
6398
    for (k = 0; k < pty; ++k){
6393
      int b = k+j*(pts+1);
6399
      int b = k+j*(pty+1);
6394
      if(filtre(sgns[b],sgns[b+1],sgns[b+pts+1],sgns[b+pts+2])){
6400
      if(filtre(sgns[b],sgns[b+1],sgns[b+pty+1],sgns[b+pty+2])){
6395
        if (i >= MAX_BUFFER)
6401
        if (i >= MAX_BUFFER)
6396
          canvas_error("\nYour curve plotting produces too many data \n Use less plotsteps, decrease image size...\nor some other means to reduce the amount of data... ");
6402
          canvas_error("\nYour curve plotting produces too many data \n Use less plotsteps, decrease image size...\nor some other means to reduce the amount of data... ");
6397
        xydata[i++] = xmin+j*dx;
6403
        xydata[i++] = xmin+j*dx;
6398
        xydata[i++] = ymin+k*dy;
6404
        xydata[i++] = ymin+k*dy;
6399
      }
6405
      }
Line 6829... Line 6835...
6829
{"latex",LATEX,0},
6835
{"latex",LATEX,0},
6830
{"lattice",LATTICE,0},
6836
{"lattice",LATTICE,0},
6831
{"legend",LEGEND,0},
6837
{"legend",LEGEND,0},
6832
{"legendcolors",LEGENDCOLORS,0},
6838
{"legendcolors",LEGENDCOLORS,0},
6833
{"levelcurve",LEVELCURVE,0},
6839
{"levelcurve",LEVELCURVE,0},
-
 
6840
{"levelstep",LEVELSTEP,0},
6834
{"line",LINE,0},
6841
{"line",LINE,0},
6835
{"linear",LINEAR,0},
6842
{"linear",LINEAR,0},
6836
{"linegraph",LINEGRAPH,0},
6843
{"linegraph",LINEGRAPH,0},
6837
{"lines",LINES,0},
6844
{"lines",LINES,0},
6838
{"linewidth",LINEWIDTH,0},
6845
{"linewidth",LINEWIDTH,0},