October 28, 2020, 11:30:18 PM

Author Topic: [bb] 2 Points into a rectangle by Yo! Wazzup? [ 1+ years ago ]  (Read 1506 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : 2 Points into a rectangle
Author : Yo! Wazzup?
Posted : 1+ years ago

Description : 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...


Code :
Code: BlitzBasic
  1. Graphics 1280,1024,32,2
  2. SetBuffer BackBuffer()
  3.  
  4. Print "Click anywhere on the screen."
  5. Locate 0,0
  6. WaitMouse()
  7. point1x=MouseX()
  8. point1y=MouseY()
  9. Cls
  10. Plot point1x, point1y
  11. Locate 0,0
  12. Print "Click somewhere else."
  13. WaitMouse()
  14. point2x=MouseX()
  15. point2y=MouseY()
  16. Cls
  17. Plot point1x, point1y
  18. Plot point2x, point2y
  19. Locate 0,0
  20. Print "Now press left shift to make a solid rectangle or right shift to make a hollow rectangle."
  21. While KeyHit(42)=False
  22. If KeyHit(54) Then
  23. FlushKeys()
  24. Cls
  25. RectFrom2Points(point1x, point1y, point2x, point2y, 0)
  26. Locate 0,0
  27. Print "Press any key to quit."
  28. WaitKey()
  29. End
  30. EndIf
  31. Wend
  32. FlushKeys()
  33. Cls
  34. RectFrom2Points(point1x, point1y, point2x, point2y)
  35. Locate 0,0
  36. Print "Press any key to quit."
  37. WaitKey()
  38. End
  39. Function min(a,b)
  40. If a>b Then
  41. Return a
  42. Else
  43. Return b
  44. EndIf
  45. End Function
  46. Function RectFrom2Points(point1x, point1y, point2x, point2y, solid=1)
  47.  
  48. rectWidth = Abs(point1x-point2x)
  49. rectHeight = Abs(point1y-point2y)
  50. xstart = min(point1x, point2x)
  51. ystart = min(point1y, point2y)
  52.  
  53.  
  54.  
  55. Rect xstart, ystart, rectwidth, rectheight, solid
  56.  
  57. Flip
  58.  
  59.  
  60. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal