_TITLE "Polygon Orbits 2" 'b+ 2020-02-25 ' Fellippe's post 2020-02-25 https://www.qb64.org/forum/index.php?topic=2234.msg114766#msg114766
' Inspired by this post: https://www.reddit.com/r/gifs/comments/f91c99/every_addtional_shape_adds_one_more_corner_and/
CONST xmax
= 550, ymax
= 550, side
= 100, center
= 275, P1
= _PI, P2
= P1
* 2, PD2
= P1
* .5 DIM SHARED poly$
(3 TO 15) 'point strings we will turn into arrays as needed c(3) = &HFF550000: c(4) = &HFFAA0000: c(5) = &HFFFF0000: c(6) = &HFFDD4400: c(7) = &HFF888800: c(8) = &HFFFF8800
c(9) = &HFF00FF00: c(10) = &HFF00FF88: c(11) = &HFF00FFFF: c(12) = &HFF0088FF: c(13) = &HFF0000FF: c(14) = &HF88F0088: c(15) = &HFF330033
DIM i
, n
, isoA
, isoA2
, turn
, r
, x1
, y1
, currA
, x2
, y2
rate(i) = (16 - i) / 12 'rate as angle mult that disc will move in circle
a = P2 / n ' central angle
isoA = (P1 - a) / 2 ' angle of one iso triangle at base
isoA2 = isoA * 2 ' 2 iso's is interior angle at each node
turn = P1 - isoA2 ' for turtle drawing, turn this much at each point
r
= .5 * side
/ SIN(a
/ 2) ' << so << 1/2 * side = r * sin(1/2 * a) radii(n) = r
x1
= center
+ r
* COS(a
/ 2 + PD2
): y1
= center
+ r
* SIN(a
/ 2 + PD2
) poly$
(n
) = STR$(x1
) + "," + STR$(y1
) 'our first point for polygon currA = P1 'turtle draw the rest of the poly and save the points
currA = currA + turn
x2
= x1
+ side
* COS(currA
): y2
= y1
+ side
* SIN(currA
) x1 = x2: y1 = y2
poly$
(n
) = poly$
(n
) + "," + STR$(x1
) + "," + STR$(y1
) drawPolys
DIM n
, i
, Px
, Py
, dist
, Rx
, Ry
, r
, g
, b
'here is where we want our dot but we have to place on a line segment between two closest points to Px, Py
Px
= center
+ radii
(n
) * COS(rate
(n
) * a
+ PD2
) Py
= center
+ radii
(n
) * SIN(rate
(n
) * a
+ PD2
) Split poly$(n), ",", pts()
min(0) = 1000: min(1) = 1100: save(0) = -1: save(1) = -2 'dummy
dist
= SQR((Px
- pts
(i
)) ^ 2 + (Py
- pts
(i
+ 1)) ^ 2) min(1) = min(0): min(0) = dist: save(1) = save(0): save(0) = i
min(1) = dist: save(1) = i
PSET (pts
(0), pts
(1)), c
(n
) LINE -(pts
(i
), pts
(i
+ 1)), c
(n
) 'now we have the two closest points of poly to px, py find Rx, RY on that line closest to Px, Py
IF ABS(pts
(save
(0)) - pts
(save
(1))) < .001 THEN ' have perpendicular line so get Rx, RY directly Rx = pts(save(0)): Ry = Py
PointOnLinePerp2Point pts(save(0)), pts(save(0) + 1), pts(save(1)), pts(save(1) + 1), Px, Py, Rx, Ry
fcirc Rx, Ry, i, midInk(r, g, b, 255, 255, 255, (9 - i) / 9)
SUB slopeYintersect
(X1
, Y1
, X2
, Y2
, slope
, Yintercept
) ' fix for when x1 = x2 slope = X1
Yintercept = Y2
slope = (Y2 - Y1) / (X2 - X1)
Yintercept = slope * (0 - X1) + Y1
SUB PointOnLinePerp2Point
(Lx1
, Ly1
, Lx2
, Ly2
, Px
, Py
, Rx
, Ry
) '
'this sub needs SUB slopeYintersect (X1, Y1, X2, Y2, slope, Yintercept) ' fix for when x1 = x2
'
'Lx1, Ly1, Lx2, Ly2 the two points that make a line
'Px, Py is point off the line
'Rx, Ry Return Point is the Point on the line perpendicular to Px, Py
slopeYintersect Lx1, Ly1, Lx2, Ly2, m, Y0
AA = m ^ 2 + 1
B = 2 * (m * Y0 - m * Py - Px)
Rx = -B / (2 * AA)
Ry = m * Rx + Y0
FUNCTION midInk~&
(r1%
, g1%
, b1%
, r2%
, g2%
, b2%
, fr##
) midInk~&
= _RGB32(r1%
+ (r2%
- r1%
) * fr##
, g1%
+ (g2%
- g1%
) * fr##
, b1%
+ (b2%
- b1%
) * fr##
)
'this sub modified for splitting into an single array!!!
curpos
= 1: arrpos
= LBOUND(loadMeArray
): LD
= LEN(delim
) dpos
= INSTR(curpos
, SplitMeString
, delim
) loadMeArray
(arrpos
) = VAL(MID$(SplitMeString
, curpos
, dpos
- curpos
)) arrpos = arrpos + 1
curpos = dpos + LD
dpos
= INSTR(curpos
, SplitMeString
, delim
) loadMeArray
(arrpos
) = VAL(MID$(SplitMeString
, curpos
))
Radius
= ABS(R
): RadiusError
= -Radius: X
= Radius: Y
= 0 LINE (CX
- X
, CY
)-(CX
+ X
, CY
), C
, BF
RadiusError = RadiusError + Y * 2 + 1
LINE (CX
- Y
, CY
- X
)-(CX
+ Y
, CY
- X
), C
, BF
LINE (CX
- Y
, CY
+ X
)-(CX
+ Y
, CY
+ X
), C
, BF
X = X - 1
RadiusError = RadiusError - X * 2
Y = Y + 1
LINE (CX
- X
, CY
- Y
)-(CX
+ X
, CY
- Y
), C
, BF
LINE (CX
- X
, CY
+ Y
)-(CX
+ X
, CY
+ Y
), C
, BF