Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to figure algorithm to draw and paint polygons
#6
On the way towards my algorithm, I usually wind up with big and ugly code to hash things out, see the pattern, and when I think I know how, I refactor the daylights out of the thing into some compact code.

Thanks all for the helpful resources.

For the giggles, here's the code I have tonight for tidying later:

Code: (Select All)
PSET (50,25) : AreaStartX = POINT(0) : AreaStartY = POINT(1)
LeftMostX = POINT(0) : LeftMostY = POINT(1) : LeftMostXBud2 = -1 : LeftMostYBud2 = -1
LastX = POINT(0): LastY = POINT(1)
LINE - (500,15),14
IF POINT(0) < LeftMostX THEN
  LeftMostX = POINT(0) : LeftMostY = POINT(1) : LeftMostXBud1 = LastX : LeftMostYBud1 = LastY : LeftMostXBud2 = -1 : LeftMostYBud2 = -1
ELSE
  IF LeftMostXBud2 = -1 THEN LeftMostXBud2 = POINT(0) : LeftMostYBud2 = POINT(1)
END IF
LastX = POINT(0): LastY = POINT(1)
LINE - (490,190),14
IF POINT(0) < LeftMostX THEN
  LeftMostX = POINT(0) : LeftMostY = POINT(1) : LeftMostXBud1 = LastX : LeftMostYBud1 = LastY : LeftMostXBud2 = -1 : LeftMostYBud2 = -1
ELSE
  IF LeftMostXBud2 = -1 THEN LeftMostXBud2 = POINT(0) : LeftMostYBud2 = POINT(1)
END IF
LastX = POINT(0): LastY = POINT(1)
LINE - (400,150),14
IF POINT(0) < LeftMostX THEN
  LeftMostX = POINT(0) : LeftMostY = POINT(1) : LeftMostXBud1 = LastX : LeftMostYBud1 = LastY : LeftMostXBud2 = -1 : LeftMostYBud2 = -1
ELSE
  IF LeftMostXBud2 = -1 THEN LeftMostXBud2 = POINT(0) : LeftMostYBud2 = POINT(1)
END IF
LastX = POINT(0): LastY = POINT(1)
LINE - (430,40),14
IF POINT(0) < LeftMostX THEN
  LeftMostX = POINT(0) : LeftMostY = POINT(1) : LeftMostXBud1 = LastX : LeftMostYBud1 = LastY : LeftMostXBud2 = -1 : LeftMostYBud2 = -1
ELSE
  IF LeftMostXBud2 = -1 THEN LeftMostXBud2 = POINT(0) : LeftMostYBud2 = POINT(1)
END IF
LastX = POINT(0): LastY = POINT(1)
LINE - (150,50),14
IF POINT(0) < LeftMostX THEN
  LeftMostX = POINT(0) : LeftMostY = POINT(1) : LeftMostXBud1 = LastX : LeftMostYBud1 = LastY : LeftMostXBud2 = -1 : LeftMostYBud2 = -1
ELSE
  IF LeftMostXBud2 = -1 THEN LeftMostXBud2 = POINT(0) : LeftMostYBud2 = POINT(1)
END IF
LastX = POINT(0): LastY = POINT(1)
LINE - (150,120),14
IF POINT(0) < LeftMostX THEN
  LeftMostX = POINT(0) : LeftMostY = POINT(1) : LeftMostXBud1 = LastX : LeftMostYBud1 = LastY : LeftMostXBud2 = -1 : LeftMostYBud2 = -1
ELSE
  IF LeftMostXBud2 = -1 THEN LeftMostXBud2 = POINT(0) : LeftMostYBud2 = POINT(1)
END IF
LastX = POINT(0): LastY = POINT(1)
LINE - (290,80),14
IF POINT(0) < LeftMostX THEN
  LeftMostX = POINT(0) : LeftMostY = POINT(1) : LeftMostXBud1 = LastX : LeftMostYBud1 = LastY : LeftMostXBud2 = -1 : LeftMostYBud2 = -1
ELSE
  IF LeftMostXBud2 = -1 THEN LeftMostXBud2 = POINT(0) : LeftMostYBud2 = POINT(1)
END IF
LastX = POINT(0): LastY = POINT(1)
LINE - (150,180),14
IF POINT(0) < LeftMostX THEN
  LeftMostX = POINT(0) : LeftMostY = POINT(1) : LeftMostXBud1 = LastX : LeftMostYBud1 = LastY : LeftMostXBud2 = -1 : LeftMostYBud2 = -1
ELSE
  IF LeftMostXBud2 = -1 THEN LeftMostXBud2 = POINT(0) : LeftMostYBud2 = POINT(1)
END IF
LastX = POINT(0): LastY = POINT(1)
LINE - (75,160),14
IF POINT(0) < LeftMostX THEN
  LeftMostX = POINT(0) : LeftMostY = POINT(1) : LeftMostXBud1 = LastX : LeftMostYBud1 = LastY : LeftMostXBud2 = -1 : LeftMostYBud2 = -1
ELSE
  IF LeftMostXBud2 = -1 THEN LeftMostXBud2 = POINT(0) : LeftMostYBud2 = POINT(1)
END IF
LastX = POINT(0): LastY = POINT(1)
LINE - (AreaStartX, AreaStartY), 14
IF POINT(0) = LeftMostX THEN LeftMostX = POINT(0) : LeftMostY = POINT(1) : LeftMostXBud1 = LastX : LeftMostYBud1 = LastY
LastX = POINT(0): LastY = POINT(1)
IF LeftMostXBud1 < LeftMostXBud2 THEN PAINT ( (LeftMostX + LeftMostXBud1) / 2 + 1, (LeftMostY + LeftMostYBud1) / 2 ), 1, 14 ELSE PAINT ( (LeftMostX + LeftMostXBud2) / 2 + 1, (LeftMostY + LeftMostYBud2) / 2 ), 1, 14

   
Reply


Messages In This Thread
RE: Trying to figure algorithm to draw and paint polygons - by CharlieJV - 08-14-2023, 02:41 AM



Users browsing this thread: 3 Guest(s)