Code archives/Algorithms/2 Points into a rectangle

This code has been declared by its author to be Public Domain code.

Download source code

2 Points into a rectangle by Yo! Wazzup?2008
Basically, turns 2 points into a rectangle.

This might not be the best way to do it, so don't get mad at me if I did it "Incorrectly".


And by the way, I suck at indenting/whitespacing.


...but this is public domain, so you can edit it all you want.


EDIT: JL235 helped me and made it simpler...
Graphics 1280,1024,32,2
SetBuffer BackBuffer()

Print "Click anywhere on the screen."
Locate 0,0
WaitMouse()
point1x=MouseX()
point1y=MouseY()
Cls
Plot point1x, point1y
Locate 0,0
Print "Click somewhere else."
WaitMouse()
point2x=MouseX()
point2y=MouseY()
Cls
Plot point1x, point1y
Plot point2x, point2y
Locate 0,0
Print "Now press left shift to make a solid rectangle or right shift to make a hollow rectangle."
While KeyHit(42)=False
If KeyHit(54) Then
FlushKeys()
Cls
RectFrom2Points(point1x, point1y, point2x, point2y, 0)
Locate 0,0
Print "Press any key to quit."
WaitKey()
End
EndIf
Wend
FlushKeys()
Cls
RectFrom2Points(point1x, point1y, point2x, point2y)
Locate 0,0
Print "Press any key to quit."
WaitKey()
End
Function min(a,b)
If a>b Then
Return a 
Else
Return b
EndIf
End Function
Function RectFrom2Points(point1x, point1y, point2x, point2y, solid=1)

rectWidth = Abs(point1x-point2x)
rectHeight = Abs(point1y-point2y)
xstart = min(point1x, point2x)
ystart = min(point1y, point2y)



Rect xstart, ystart, rectwidth, rectheight, solid

Flip


End Function

Comments

None.

Code Archives Forum