void draw_slash() { np_canvas c = get_active_canvas(); np_image img = get_active_image(); int w = get_width(img); //キャンバスの幅を取得 int h = get_height(img); //キャンバスの高さを取得 // 横の幅決定 read_mouse_input(c,"input mouse pos1"); np_point p1 = get_mouse_point(c); read_mouse_input(c,"input mouse pos2"); np_point p2 = get_mouse_point(c); read_mouse_input(c,"input mouse pos3"); np_point p3 = get_mouse_point(c); // 斜線向き判断用 double px = p2.x - p1.x ; double py = p2.y - p1.y ; // 幅決定 double p4x = ((p2.x - p1.x) * (p3.y - p1.y) / (p2.y - p1.y) ) + p1.x ; double p5y = p2.y - ((p2.y - p1.y) * (p2.x - p3.x) / (p2.x - p1.x) ) ; double x = p3.x - p4x ; double y = p3.y - p5y ; if ( y < 0 ) { y = y * (-1) ; } if ( x < 0 ) { x = x * (-1) ; } if ( px < 0 && 0 < py || py < 0 && 0 < px) { double a = (p2.y - p1.y) * ( -30 - x / 3); double p6y = a / (p2.x - p1.x) ; double b = (p2.x - p1.x) * ( -30 - y / 3); double p7x = b / (p2.y - p1.y) ; for (int i = 0; i <= h / y + w / x ; ++i) { draw_line(c, p7x + (i * x), -30, -30, p6y + (i * y)); } }else { double a = (p2.y - p1.y) * ( x / 3 - ( -30 )); double p6y = h - (a / (p2.x - p1.x)) ; double b = (p2.x - p1.x) * ( ( h + 30 ) - ( h - y / 3)); double p7x = b / (p2.y - p1.y) ; for (int i = 0; i <= h / y + w / x ; ++i) { draw_line(c , (-30) , p6y - (i * y) , p7x + (i * x) , (h + 30) ); } } } ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// // 右上がり斜線 void draw_slash45a() { np_canvas c = get_active_canvas(); np_image img = get_active_image(); int w = get_width(img); //キャンバスの幅を取得 int h = get_height(img); //キャンバスの高さを取得 // 横の幅決定 read_mouse_input(c,"input mouse pos1"); np_point p1 = get_mouse_point(c); read_mouse_input(c,"input mouse pos2"); np_point p2 = get_mouse_point(c); // 幅決定 double x = p1.y - p2.y + p1.x - p2.x ; if ( x < 0 ) { x = x * (-1) ; } double a = (p1.x - p1.y) * ( -30 - x / 3); double p3y = a / (p1.y - p1.x) ; for (int i = 0; i <= h / x + w / x ; ++i) { draw_line(c, p3y + (i * x), -30, -30, p3y + (i * x)); } } ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// // 右下がり斜線 void draw_slash45b() { np_canvas c = get_active_canvas(); np_image img = get_active_image(); int w = get_width(img); //キャンバスの幅を取得 int h = get_height(img); //キャンバスの高さを取得 // 横の幅決定 read_mouse_input(c,"input mouse pos1"); np_point p1 = get_mouse_point(c); read_mouse_input(c,"input mouse pos2"); np_point p2 = get_mouse_point(c); // 幅決定 double x = p2.x - (p1.x - (p1.y - p2.y)); if ( x < 0 ) { x = x * (-1) ; } double p3y = h - ( x / 3 + 30) ; double p4x = x / 3 + 30 ; for (int i = 0; i <= h / x + w / x ; ++i) { draw_line(c , (-30) , p3y - (i * x) , p4x + (i * x) , (h + 30) ); } }