1

After trying a few things inside small basic to make a line follow the mouse but not move the entire line, I recently came across a problem. Originally I was trying to constantly have a line update so as it stays connected from one point to the mouse position by clearing the graphics window and redrawing a line from the bottom right to the mouse. This could not work and was to resource intensive. However, now I have come across Shape.addline and shape.move. But I'm not too sure as to how they work, from my understanding, a shape can have it's own name by doing:

[Shapename] = Shapes.addline(positions)

and then that shape can be moved using:

Shapes.move(Shapename,Coordinates)

In my case it's:

L1 = Shapes.AddLine(0,GraphicsWindow.Height,GraphicsWindow.MouseX,GraphicsWindow.MouseY)

(Drawing a line from the bottom left corner to the mouses position)

and

Shapes.Move(L1,GraphicsWindow.MouseX,GraphicsWindow.MouseY)

The only problem is that Shapes.Move only supports 3 arguments being:

  • shapeName

  • X

  • Y

But, when drawing the line (Shapes.AddLine), I use 4 arguments:

  • X1

  • Y1

  • X2

  • Y2

This means I can only control those two positions. So, how would you control the other two? If we can only modify X1 and Y1, is there any way of still using at least something similar to the shape.move method but be able to control the other X2 and Y2 positions? Primarily, I would like to actually Only change the X2 and Y2 positions, as I'm trying to make a line originate from one point and stay there, then alter the opposing point so that it follows the mouse, and not move the entire shape. If none of this is possible, is there any known way of moving / changing only the X2 and Y2 coordinates of a line without having to clear the entire screen?

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
EpicMinecartz
  • 39
  • 2
  • 5

2 Answers2

1

Ah yes. These are the shortcomings of small basic. Shapes.move will not let you define a starting and ending point of a line. What you will need to do is move the center of the line in between the first point and the cursor, and the rotate it correctly. Like so:

Mouseline = Shapes.AddLine(0,0,100,0)
Shapes.Move(Mouseline,200,200)
GraphicsWindow.MouseMove = OnMouseMove


Sub OnMouseMove
 XDif = (GraphicsWindow.MouseX-250)
 YDif = (GraphicsWindow.MouseY-200)
 If XDif <> 0 Then
 MouseAngle = Math.ArcTan(YDif/XDif)
 EndIf
 If XDif < 0 Then
 MouseAngle = MouseAngle + 3.14 '180 degrees in radians
 EndIf
 Shapes.Rotate(Mouseline,Math.GetDegrees(MouseAngle))
 Shapes.Move(Mouseline,(Math.Cos(MouseAngle)*50)+200,(Math.Sin(MouseAngle)*50)+200)
EndSub

Another way of doing this is with the LitDev extension (http://litdev.co.uk/). It has a MoveLine(x1,y1,x2,y2) function in it.

Zock77
  • 951
  • 8
  • 26
  • Fantastic, this completely solved what I wanted to achive, however, one more thing, how would I make this appear in the bottom left of the screen, I have alterd the addline and move to what I belived would get it to the bottom left, but it's about 150 pixels off from the left side? – EpicMinecartz Jan 02 '16 at 02:46
1

im guessing u would alter the end of the program where it says math.cos(mouseangle) change the 200 to 0 and change the other 200 to the bottom. so if what im trying to figure out, ur trying to get the line to only project in the 1st quadrant in a cortesian plane yes?

Matthew
  • 157
  • 1
  • 9