胡斌

improve using line,draw arc at each end point

正在显示 1 个修改的文件 包含 43 行增加48 行删除
... ... @@ -371,76 +371,71 @@
drawMouse();
}
var draw_method = 0;
function Point(x , y, p) {
this.x = x;
this.y = y;
this.p = p;
}
var previousPoint = new Point(0, 0, 0), currentPoint = new Point(0, 0, 0);
var previousWidth = 0;
var kWIDTH_MIN = 0.2;
var kWIDTH_MAX = 3.0;
//current width
var strokeWidth = 3.0;
var rotate_degree = 0;
var pressure_level = 2048.0 - 1;
var draw_method = 0;
function draw_method_change(){
draw_method = document.getElementById("draw_method").selectedIndex;
}
function draw_ext_input(px,py,p) {
if(p > pressure_level) {
//something maybe wrong
return ;
}
if(draw_method == 0) {
draw_ext_input_arc(px,py,p);
draw_ext_input_dda(px,py,p);
}
else if(draw_method == 1) {
draw_ext_input_line(px,py,p);
}
}
var last_ext_press = 0;
var last_x = 0;
var last_y = 0;
function draw_ext_input_line(px,py,p) {
x = px * ratio_x;
y = py * ratio_y;
if(last_ext_press == 0){
function draw_ext_input_line(px,py,p) {
if(currentPoint.p == 0){
if (p != 0) {
ctx.beginPath();
ctx.lineWidth = (kWIDTH_MAX - kWIDTH_MIN) / pressure_level * p + kWIDTH_MIN;
ctx.moveTo(x, y);
ctx.lineTo(x, y);
ctx.stroke();
last_x = x;
last_y = y;
currentPoint.x = px * ratio_x;
currentPoint.y = py * ratio_y;
currentPoint.p = p;
draw_point(currentPoint);
}
}
else if(p != 0) {
ctx.beginPath();
ctx.lineWidth = (kWIDTH_MAX - kWIDTH_MIN)/pressure_level * p + kWIDTH_MIN;
ctx.moveTo(last_x, last_y);
ctx.lineTo(x, y);
ctx.moveTo(currentPoint.x, currentPoint.y);
ctx.lineWidth = previousWidth;
currentPoint.x = px * ratio_x;
currentPoint.y = py * ratio_y;
ctx.lineTo(currentPoint.x, currentPoint.y);
ctx.stroke();
last_x = x;
last_y = y;
currentPoint.p = p;
draw_point(currentPoint);
}
else {
ctx.beginPath();
ctx.lineWidth = (kWIDTH_MAX - kWIDTH_MIN)/pressure_level * last_ext_press + kWIDTH_MIN;
ctx.moveTo(last_x, last_y);
ctx.lineTo(x, y);
ctx.stroke();
currentPoint.p = p;
}
last_ext_press = p;
}
function Point(x , y, p) {
this.x = x;
this.y = y;
this.p = p;
}
var previousPoint = new Point(0,0,0), currentPoint= new Point(0,0,0);
var previousWidth = 0;
var kWIDTH_MIN = 0.2;
var kWIDTH_MAX = 3.0;
//current width
var strokeWidth = 3.0;
var rotate_degree = 0;
var pressure_level = 2048.0 - 1;
function draw_ext_input_arc(px, py, press) {
if(press == 0) {
function draw_ext_input_dda(px, py, p) {
if(p == 0) {
previousPoint.p = 0;
}
else {
... ... @@ -450,7 +445,7 @@
currentPoint.x = px * ratio_x;
currentPoint.y = py * ratio_y;
currentPoint.p = press;
currentPoint.p = p;
if(previousPoint.p == 0) {
draw_point(currentPoint);
... ... @@ -469,7 +464,7 @@
$( "#line_width_slider" ).slider({
range: true,
min: 1,
max: 50,
max: 100,
values: [ 2, 32 ],
slide: function( event, ui ) {
$( "#line_width" ).val( ui.values[ 0 ] /10.0+ " - " + ui.values[ 1 ] /10.0);
... ... @@ -2073,7 +2068,7 @@
<td><input type="text" id="line_width" size="10" readonly style="border:0; color:#f6931f; font-weight:bold;"/></td>>
<td colspan="2"><select id="pen_type" name="pen_type"><option value ="PendoTech">PendoTech PH-1820-A</option><option value ="robot">Nebula T7</option></select></td>
<td colspan="2"><select id="draw_method" name="draw_method" onchange='javascript:draw_method_change();'><option value ="use_arc">use arc</option><option value ="use_line">use line</option></select></td>
<td colspan="2"><select id="draw_method" name="draw_method" onchange='javascript:draw_method_change();'><option value ="use_arc">use dda</option><option value ="use_line">use line</option></select></td>
</tr>
</table>
</div>
... ...