Return to Snippet

Revision: 16973
at August 19, 2009 12:25 by helloworlder


Updated Code
if(dragging)  # yea this is a loop as long as dragging == true
{
    graphics.clear();

    current = getMousePosition() # get latest mouse position

    length = current.x - start_loc.x # current length so far
    height = current.y - start_loc.y # current height so far

    top = new Point(start_loc.x, start_loc.y)
    bottom = new Point(start_loc.x, start_loc.y + height)
    left = new Point(start_loc.x, start_loc.y)
    right = new Point(current.x, start_loc.y)

    #drawLine(positionX, positionY, length);
    drawLine(top.x, top.y, length) # line anchor point on left
    drawLine(bottom.x, bottom.y, length)
    drawLine(left.x, left.y, height)
    drawLine(right.x, right.y, height)
}

Revision: 16972
at August 19, 2009 12:22 by helloworlder


Initial Code
if(dragging)
{
    graphics.clear();

    current = getMousePosition() # get latest mouse position

    length = current.x - start_loc.x # current length so far
    height = current.y - start_loc.y # current height so far

    top = new Point(start_loc.x, start_loc.y)
    bottom = new Point(start_loc.x, start_loc.y + height)
    left = new Point(start_loc.x, start_loc.y)
    right = new Point(current.x, start_loc.y)

    #drawLine(positionX, positionY, length);
    drawLine(top.x, top.y, length) # line anchor point on left
    drawLine(bottom.x, bottom.y, length)
    drawLine(left.x, left.y, height)
    drawLine(right.x, right.y, height)
}

Initial URL


Initial Description
start_loc.x and start_loc.y is the position where the dragging first began.

Note that the top, bottom, left , and right represents positions of the 4 lines, with the anchor point at either the top of the line if vertical or left if horizontal.

Also note that the variable top will not always represent the position of the top line and the bottom not always the bottom etc, but only if you imagine dragging a lasso box from the top left to the bottom right. It does not matter however, the lasso will work in any case. The naming just made it easier for me to code it. Just think about it a little and you'll get it.

Initial Title
Draw a lasso rectangle

Initial Tags


Initial Language
Pseudocode