Subversion Repositories wimsdev

Rev

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

Rev 18609 Rev 18615
Line 158... Line 158...
158
  double stroke_opacity = 0.95; /* use some opacity as default */
158
  double stroke_opacity = 0.95; /* use some opacity as default */
159
  double fill_opacity = 0.5;/* use some opacity as default */
159
  double fill_opacity = 0.5;/* use some opacity as default */
160
  char *URL = "http://localhost/images";
160
  char *URL = "http://localhost/images";
161
  memset(buffer,'\0',MAX_BUFFER);
161
  memset(buffer,'\0',MAX_BUFFER);
162
  void *tmp_buffer = "";
162
  void *tmp_buffer = "";
163
  double res[7];
163
  double res[10];
164
  /* default writing a unzipped js-include file into wims getfile directory */
164
  /* default writing a unzipped js-include file into wims getfile directory */
165
  char *w_wims_session = getenv("w_wims_session");
165
  char *w_wims_session = getenv("w_wims_session");
166
  if( w_wims_session == NULL || *w_wims_session == 0 ){canvas_error("Hmmm, your wims environment does not exist...\nCanvasdraw should be used within wims.");}
166
  if( w_wims_session == NULL || *w_wims_session == 0 ){canvas_error("Hmmm, your wims environment does not exist...\nCanvasdraw should be used within wims.");}
167
  int L0=strlen(w_wims_session) + 21;
167
  int L0=strlen(w_wims_session) + 21;
168
  char *getfile_dir = my_newmem(L0); /* create memory to fit string precisely */
168
  char *getfile_dir = my_newmem(L0); /* create memory to fit string precisely */
Line 1657... Line 1657...
1657
          if(use_dragstuff == 0 ){ use_dragstuff = 1; }
1657
          if(use_dragstuff == 0 ){ use_dragstuff = 1; }
1658
          break;
1658
          break;
1659
        case FILLALL:
1659
        case FILLALL:
1660
  /*
1660
  /*
1661
  @ fillall color,x1,y1,x2,y2...x_n,y_n
1661
  @ fillall color,x1,y1,x2,y2...x_n,y_n
1662
  @ fill all region containing points (x1:y1),(x2:y2)...(x_n:y_n) with color 'color'
1662
  @ fill all the region containing points (x1:y1),(x2:y2)...(x_n:y_n) with color 'color'
1663
  @ any other colors (objects) in the <a href="#canvastype">canvastype</a> will act as border to the bucket fill
1663
  @ any color (object) in the <a href="#canvastype">canvastype</a> will act as border to the bucket fill
1664
  @ use this command after all boundary objects are declared.
1664
  @ use this command after all boundary objects are declared.
1665
  @ Use command 'userdraw clickfill,color' for user click driven flood fill.
1665
  @ Use command 'userdraw clickfill,color' for user click driven flood fill.
1666
  @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5)
1666
  @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5)
1667
  @ 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..
1667
  @ 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..
1668
  @%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
1668
  @%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
Line 1751... Line 1751...
1751
          break;
1751
          break;
1752
        case FILLTOBORDER:
1752
        case FILLTOBORDER:
1753
  /*
1753
  /*
1754
  @ filltoborder x,y,bordercolor,color
1754
  @ filltoborder x,y,bordercolor,color
1755
  @ fill the region of point (x:y) with color 'color'
1755
  @ fill the region of point (x:y) with color 'color'
1756
  @ any other color will not act as border to the bucket fill
1756
  @ any other color than bordercolor will not act as border to the bucket fill
-
 
1757
  @ the filling is done in the connex component whih contains (x,y) of the set of points which are in a color different of bordercolor
1757
  @ use this command after all boundary objects are declared.
1758
  @ use this command after all boundary objects are declared.
-
 
1759
  @ it can be useful to increase strokeopacity or linewidth
1758
  @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5)
1760
  @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5)
1759
  @ note: filltoborder is a very (client) cpu intensive operation!<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..
1761
  @ note: filltoborder is a very (client) cpu intensive operation!<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..
1760
  @ maybe used together with command <a href="#userdraw">userdraw clickfill,color</a>
1762
  @ maybe used together with command <a href="#userdraw">userdraw clickfill,color</a>
1761
  @%filltoborder%size 400,400%xrange -10,10%yrange -10,10%canvastype 100%linewidth 2%precision 1000%jsplot blue,5*sin(x)%opacity 200,50%filltoborder 6,6,blue,blue%filltoborder 6,-6,blue,red
1763
  @%filltoborder%size 400,400%xrange -10,10%yrange -10,10%canvastype 100%linewidth 2%precision 1000%jsplot blue,5*sin(x)%opacity 200,50%filltoborder 6,6,blue,green%filltoborder 6,-6,blue,red
1762
  */
1764
  */
1763
          for(i=0 ;i < 4 ; i++){
1765
          for(i=0 ;i < 4 ; i++){
1764
            switch(i){
1766
            switch(i){
1765
              case 0:double_data[0] = get_real(infile,0);break;
1767
              case 0:double_data[0] = get_real(infile,0);break;
1766
              case 1:double_data[1] = get_real(infile,0);break;
1768
              case 1:double_data[1] = get_real(infile,0);break;
Line 5740... Line 5742...
5740
          reset();
5742
          reset();
5741
          dragstuff[4] = 1;dragstuff[12] = 1;
5743
          dragstuff[4] = 1;dragstuff[12] = 1;
5742
          if(use_dragstuff == 0 ){ use_dragstuff = 1; }
5744
          if(use_dragstuff == 0 ){ use_dragstuff = 1; }
5743
          break;
5745
          break;
5744
        case HYPPOLY:
5746
        case HYPPOLY:
-
 
5747
/*  @ hyppolygon color,x1,y1,x2,y2...x_n-1,y_n-1,x_n,y_n
-
 
5748
    @ draw hyperbolicpolygon in the Poincaré disk through points (x1:y1)--(x2:y2) ...(x_n-1:y_n-1)--(x_n:y_n) -- (x1:y1)  in color 'color'
-
 
5749
    may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
-
 
5750
    @ option fhyppolygon only for convex polygon for the moment
-
 
5751
    @%hyppolygon%size 400,400%xrange -1,1%yrange -1,1%circles black,0,0,1%hyppolygon green,0,0,0.5,0.3,0.8,-0.1,0.4,-0.5
-
 
5752
*/
5745
          stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
5753
          stroke_color=get_color(infile,0);
5746
          fill_color = stroke_color;
5754
          fill_color = stroke_color;
5747
          i=0;
5755
          i=0;
5748
          while( ! done ){     /* get next item until EOL*/
5756
          while( ! done ){     /* get next item until EOL*/
5749
            if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
5757
            if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
5750
            if(i%2 == 0 ){
5758
            if(i%2 == 0 ){
5751
              double_data[i] = get_real(infile,0); /* x */
5759
              double_data[i] = get_real(infile,0); /* x */
5752
            }
5760
            }
5753
            else {
5761
            else {
5754
              double_data[i] = get_real(infile,1); /* y */
5762
              double_data[i] = get_real(infile,1); /* y */
5755
            }
5763
            }
5756
            i++;
5764
            i++;
5757
          }
5765
          }
5758
          /* il faut rajouter le premier point à la fin*/
5766
          /* il faut rajouter le premier point à la fin*/
5759
          double_data[i]=double_data[0]; double_data[i+1]=double_data[1];
5767
          double_data[i]=double_data[0]; double_data[i+1]=double_data[1];
5760
          if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);}
5768
          if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);}
5761
          if(use_affine == TRUE ){ transform(i-1,2);}
5769
          if(use_affine == TRUE ){ transform(i-1,2);}
5762
          if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
5770
          if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
5763
          decimals = find_number_of_digits(precision);
5771
          decimals = find_number_of_digits(precision);
5764
          for(c = 0 ; c < i-1 ; c = c+2){
5772
          for(c = 0 ; c < i-1 ; c = c+2){
5765
          tmp_buffer=my_newmem(MAX_BUFFER);
5773
            tmp_buffer=my_newmem(MAX_BUFFER);
5766
            if (hypgeodaux(double_data+c,res,0)){
5774
            if (hypgeodaux(double_data+c,res,0)){
5767
              check_string_length(snprintf(tmp_buffer,MAX_BUFFER,"dragstuff.addShape(new Shape(%d,%d,%d,%d,12,[%.*f,%.*f],[%.*f,%.*f],[%.*f,%.*f],[%.*f,%.*f],%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,decimals,res[0],decimals,res[0],decimals,res[1],decimals,res[1],decimals,res[2],decimals,res[3],decimals,res[4],decimals,res[5],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));
5775
              check_string_length(snprintf(tmp_buffer,MAX_BUFFER,"dragstuff.addShape(new Shape(%d,%d,%d,%d,12,[%.*f,%.*f],[%.*f,%.*f],[%.*f,%.*f],[%.*f,%.*f],%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,decimals,res[0],decimals,res[0],decimals,res[1],decimals,res[1],decimals,res[2],decimals,res[3],decimals,res[4],decimals,res[5],line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset));
5768
            }
5776
            }
5769
            else {
5777
            else {
5770
              check_string_length(snprintf(tmp_buffer,MAX_BUFFER,"dragstuff.addShape(new Shape(%d,%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%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,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+1],decimals,double_data[c+3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset));
5778
              check_string_length(snprintf(tmp_buffer,MAX_BUFFER,"dragstuff.addShape(new Shape(%d,%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%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,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+1],decimals,double_data[c+3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset));
5771
            }
5779
            }
5772
            add_to_buffer(tmp_buffer);
5780
            add_to_buffer(tmp_buffer);
5773
            if(onclick != 0){object_cnt++;}
5781
            if(onclick != 0){object_cnt++;}
-
 
5782
          }
-
 
5783
          if(use_filled){
-
 
5784
            hypgeodaux(double_data+2,res,0);
-
 
5785
            res[4]=double_data[0]; res[5]=double_data[1];
-
 
5786
            hypgeodaux(res+4,res,0);
-
 
5787
            add_js_filltoborder(canvas_type);
-
 
5788
            check_string_length(snprintf(tmp_buffer,MAX_BUFFER,"setTimeout(function(){filltoborder (%.*f,%.*f,[%s,%d],[%s,%d],%d,false,null);},1000);\n",decimals,res[6],decimals,res[7],fill_color,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215),FILL_CANVAS+fill_cnt));
-
 
5789
            add_to_buffer(tmp_buffer);
-
 
5790
                fill_cnt++;
5774
                }
5791
                }
5775
          dragstuff[4] = 1; dragstuff[12] = 1;
5792
          dragstuff[4] = 1; dragstuff[12] = 1;
5776
          if(use_dragstuff == 0 ){ use_dragstuff = 1; }
5793
          if(use_dragstuff == 0 ){ use_dragstuff = 1; }
5777
          reset();
5794
          reset();
5778
          break;
5795
          break;
Line 6609... Line 6626...
6609
    canvas_error("problem with your arguments to command...");
6626
    canvas_error("problem with your arguments to command...");
6610
  }
6627
  }
6611
  return;
6628
  return;
6612
}
6629
}
6613
/* useful in hyp commands: determine if the hypsegment is an arc or a line */
6630
/* useful in hyp commands: determine if the hypsegment is an arc or a line */
-
 
6631
/* give a point on the arc */
6614
int hypgeodaux(double *q, double* ress, int full){
6632
int hypgeodaux(double *q, double* ress, int full){
6615
  double alpha,beta,gamma,r,cx,cy,a1,a2,a3,tmp,
6633
  double alpha,beta,gamma,r,cx,cy,a1,a2,a3,tmp,
6616
    nx = -q[0]*q[2]*q[2]+(q[0]*q[0]+q[1]*q[1]+1)*q[2]-q[0]*q[3]*q[3]-q[0],
6634
    nx = -q[0]*q[2]*q[2]+(q[0]*q[0]+q[1]*q[1]+1)*q[2]-q[0]*q[3]*q[3]-q[0],
6617
    ny = -q[1]*q[2]*q[2]-q[1]*q[3]*q[3]+(q[0]*q[0]+q[1]*q[1]+1)*q[3]-q[1],
6635
    ny = -q[1]*q[2]*q[2]-q[1]*q[3]*q[3]+(q[0]*q[0]+q[1]*q[1]+1)*q[3]-q[1],
6618
    dy = -2*q[1]*q[2]+2*q[0]*q[3];
6636
    dy = -2*q[1]*q[2]+2*q[0]*q[3];
Line 6624... Line 6642...
6624
        gamma = atan2(q[3],q[2]);
6642
        gamma = atan2(q[3],q[2]);
6625
      ress[0]=cos(gamma); ress[1]=sin(gamma); ress[2]=-cos(gamma); ress[3]=-sin(gamma);
6643
      ress[0]=cos(gamma); ress[1]=sin(gamma); ress[2]=-cos(gamma); ress[3]=-sin(gamma);
6626
    }
6644
    }
6627
    else
6645
    else
6628
      {int i;for(i=0;i<4;++i) ress[i]=q[i];}
6646
      {int i;for(i=0;i<4;++i) ress[i]=q[i];}
6629
    ress[5]=(q[0]+q[2])/2;
6647
    ress[6]=(q[0]+q[2])/2;
6630
    ress[6]=(q[1]+q[3])/2;
6648
    ress[7]=(q[1]+q[3])/2;
6631
    return 0;}
6649
    return 0;}
6632
  cx = ny/dy; cy=-nx/dy;
6650
  cx = ny/dy; cy=-nx/dy;
6633
  r = sqrt(cx*cx+cy*cy-1);
6651
  r = sqrt(cx*cx+cy*cy-1);
6634
  if(full)
6652
  if(full)
6635
    {alpha=atan(1/r); beta = atan2(cy,cx);a1=M_PI+beta-alpha;a2=M_PI+beta+alpha;}
6653
    {alpha=atan(1/r); beta = atan2(cy,cx);a1=M_PI+beta-alpha;a2=M_PI+beta+alpha;}
Line 6736... Line 6754...
6736
{"farc",ARC,usefilled},
6754
{"farc",ARC,usefilled},
6737
{"fcircle",CIRCLE,usefilled},
6755
{"fcircle",CIRCLE,usefilled},
6738
{"fcircles",CIRCLES,usefilled},
6756
{"fcircles",CIRCLES,usefilled},
6739
{"fellipse",ELLIPSE,usefilled},
6757
{"fellipse",ELLIPSE,usefilled},
6740
{"fhypcircles",HYPCIRCLES,usefilled},
6758
{"fhypcircles",HYPCIRCLES,usefilled},
-
 
6759
{"fhyppolygon",HYPPOLY,usefilled},
6741
{"fill",FLOODFILL,0},
6760
{"fill",FLOODFILL,0},
6742
{"fillall",FILLALL,0},
6761
{"fillall",FILLALL,0},
6743
{"fillcolor",FILLCOLOR,0},
6762
{"fillcolor",FILLCOLOR,0},
6744
{"fillcolors",MULTIFILLCOLORS,0},
6763
{"fillcolors",MULTIFILLCOLORS,0},
6745
{"filled",FILLED,0},
6764
{"filled",FILLED,0},