Rev 17425 | Rev 17586 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 17425 | Rev 17583 | ||
---|---|---|---|
Line 141... | Line 141... | ||
141 | 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 */ |
141 | 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 */ |
142 | int clock_cnt = 0; /* counts the amount of clocks used -> unique object clock%d */ |
142 | int clock_cnt = 0; /* counts the amount of clocks used -> unique object clock%d */ |
143 | int boxplot_cnt = 0; |
143 | int boxplot_cnt = 0; |
144 | int drawxml_cnt = 0; |
144 | int drawxml_cnt = 0; |
145 | int numberline_cnt = 0; |
145 | int numberline_cnt = 0; |
- | 146 | int snap_to_points_cnt = 0; |
|
146 | int reply_precision = 100; /* used for precision of student answers / drawings */ |
147 | int reply_precision = 100; /* used for precision of student answers / drawings */ |
147 | char *rotation_center = "null";/* needs to be removed... but is used for canvas CTX based rotation*/ |
148 | char *rotation_center = "null";/* needs to be removed... but is used for canvas CTX based rotation*/ |
148 | double rotationcenter[] = {0,0}; /* use for recalculating x/y values on rotation() */ |
149 | double rotationcenter[] = {0,0}; /* use for recalculating x/y values on rotation() */ |
149 | int use_animate = 0; /* used for jscurve / js parametric */ |
150 | int use_animate = 0; /* used for jscurve / js parametric */ |
150 | int use_input_xy = 0; /* 1= input fields 2= textarea 3=calc y value*/ |
151 | int use_input_xy = 0; /* 1= input fields 2= textarea 3=calc y value*/ |
Line 4648... | Line 4649... | ||
4648 | break; |
4649 | break; |
4649 | case SNAPTOPOINTS: |
4650 | case SNAPTOPOINTS: |
4650 | /* |
4651 | /* |
4651 | @ snaptopoints x1,y1,x2,y2,x3,y3.... |
4652 | @ snaptopoints x1,y1,x2,y2,x3,y3.... |
4652 | @ a userdraw object will snap to these points. |
4653 | @ a userdraw object will snap to these points. |
4653 | @ the array size (e.g. the number of points) of command ''snaptopoints`` is limited by constant MAX_INT (canvasdraw.h) |
4654 | @ the array size (e.g. the number of points) of command ''snaptopoints`` is limited by constant MAX_INT (canvasdraw.h)<br/>this command may be repeated multiple times (no limit) to add points |
4654 | @ a draggable object (use command ''drag x|y|xy``) will snap to the closed of these points when dragged (mouseup) |
4655 | @ a draggable object (use command ''drag x|y|xy``) will snap to the closed of these points when dragged (mouseup) |
4655 | @ other options: use keyword ''snaptogrid``, ''xsnaptogrid`` or ''ysnaptogrid`` |
4656 | @ other options: use keyword ''snaptogrid``, ''xsnaptogrid`` or ''ysnaptogrid`` |
4656 | @%snaptopoints%size 400,400%xrange -5,5%yrange -5,5%snaptopoints -1,-3,-1,-2,-1,0,-1,1,-1,2,-1,3,1,-3,1,-2,1,-1,1,0,1,1,1,2,1,3%linewidth 2%points red,-1,-3,-1,-2,-1,0,-1,1,-1,2,-1,3,1,-3,1,-2,1,-1,1,0,1,1,1,2,1,3%userdraw arrows,red |
4657 | @%snaptopoints%size 400,400%xrange -5,5%yrange -5,5%snaptopoints -1,-3,-1,-2,-1,0,-1,1,-1,2,-1,3,1,-3,1,-2,1,-1,1,0,1,1,1,2,1,3%linewidth 2%points red,-1,-3,-1,-2,-1,0,-1,1,-1,2,-1,3,1,-3,1,-2,1,-1,1,0,1,1,1,2,1,3%userdraw arrows,red |
4657 | @%snaptopoints%size 400,400%xrange -5,5%yrange -5,5%snaptopoints -1,-3,-1,-2,-1,0,-1,1,-1,2,-1,3,1,-3,1,-2,1,-1,1,0,1,1,1,2,1,3%linewidth 3%%points blue,-1,-3,-1,-2,-1,0,-1,1,-1,2,-1,3,1,-3,1,-2,1,-1,1,0,1,1,1,2,1,3%drag xy%ftriangle -4,0,-2,3,0,0,red |
4658 | @%snaptopoints%size 400,400%xrange -5,5%yrange -5,5%snaptopoints -1,-3,-1,-2,-1,0,-1,1,-1,2,-1,3,1,-3,1,-2,1,-1,1,0,1,1,1,2,1,3%linewidth 3%%points blue,-1,-3,-1,-2,-1,0,-1,1,-1,2,-1,3,1,-3,1,-2,1,-1,1,0,1,1,1,2,1,3%drag xy%ftriangle -4,0,-2,3,0,0,red |
4658 | */ |
4659 | */ |
4659 | i = 0; |
4660 | i = 0; |
4660 | use_snap = 4; |
- | |
4661 | while( ! done ){ /* get next item until EOL*/ |
4661 | while( ! done ){ /* get next item until EOL*/ |
4662 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
4662 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
4663 | if(i%2 == 0 ){ |
4663 | if(i%2 == 0 ){ |
4664 | double_data[i] = get_real(infile,0); /* x */ |
4664 | double_data[i] = get_real(infile,0); /* x */ |
4665 | } |
4665 | } |
4666 | else |
4666 | else |
4667 | { |
4667 | { |
4668 | double_data[i] = get_real(infile,1); /* y */ |
4668 | double_data[i] = get_real(infile,1); /* y */ |
4669 | } |
4669 | } |
4670 | i++; |
4670 | i++; |
4671 | } |
4671 | } |
4672 | decimals = find_number_of_digits(precision); |
4672 | decimals = find_number_of_digits(precision); |
- | 4673 | /* NEED AN EXTRA COUNTER VARIABLE FOR MORE THAN 2 CALLS */ |
|
- | 4674 | fprintf(js_include_file,"if( temp_push_array === 'undefined' ){var temp_push_array;};if( points_to_snap_on === 'undefined' ){var points_to_snap_on;};var temp_push_array = [%s];\n",double_xy2js_array(double_data,i,decimals)); |
|
- | 4675 | if( snap_to_points_cnt == 0 ){ |
|
4673 | fprintf |
4676 | fprintf(js_include_file,"points_to_snap_on = temp_push_array;function find_min_diff(x,y,X,Y){var diff = 100000000;var chk;var idx = 0;var p = 0;while(X[p] != null){chk = distance(x,y,X[p],Y[p]);if( chk < diff ){ diff = chk; idx = p;};p++;};return idx;};function snap_to_points(x,y){x = px2x(x); y = px2y(y);var xpoints = points_to_snap_on[0];var ypoints = points_to_snap_on[1];var idx = find_min_diff(x,y,xpoints,ypoints);x = xpoints[idx];y = ypoints[idx];return [x2px(x),y2px(y)];};"); |
- | 4677 | }else{ |
|
- | 4678 | fprintf(js_include_file,"points_to_snap_on[0].push.apply(points_to_snap_on[0],temp_push_array[0]);points_to_snap_on[1].push.apply(points_to_snap_on[1],temp_push_array[1]);"); |
|
- | 4679 | } |
|
- | 4680 | snap_to_points_cnt = 1; /* do not repeat including the js-functions...just once*/ |
|
- | 4681 | use_snap = 4; |
|
4674 | break; |
4682 | break; |
4675 | 4683 | ||
4676 | case SNAPTOGRID: |
4684 | case SNAPTOGRID: |
4677 | /* |
4685 | /* |
4678 | @ snaptogrid |
4686 | @ snaptogrid |