_TITLE "Hexagonal Star Tiling 3" 'B+ 2019-04-19 ' Trying to duplicate results shown here by Daniel Shiffman
' [youtube]https://www.youtube.com/watch?v=sJ6pMLp_IaI&list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH[/youtube]&index=70
' but using a completely different method for drawing the tile
' 2019-04-17 Yes! the star tile can be generalized to any N sided regular polygon!
' 2019-04-17 This version try Hexagonal Tiling.
' 2019-04-17 Hexagonal Star Tiling 2, prep one tile and rubber stamp the grid with image.
' 2019-04-18 Go for a dynamic tile, image constantly changing
CONST xmax
= 1380 'bigger than your screen can hold '_SCREENMOVE _MIDDLE
polyRadius = 60
gridheight
= polyRadius
* SQR(3) / 2rd = 10
dm = 20
prepTile polyRadius, rd, dm
rDir = 1: dDir = 1
IF rd
+ 1 <= polyRadius
* .5 THEN rd = rd + 1: prepTile polyRadius, rd, dm
polyRadius = rand(20, 200)
rDir
= -1: dm
= RND * polyRadius
* .5: rd
= RND * polyRadius
* .5 \
1 rDir = -1
rd = rd - 1: prepTile polyRadius, rd, dm
polyRadius = rand(20, 200)
rDir
= 1: dm
= RND * polyRadius
* .5: rd
= RND * polyRadius
* .5 \
1 rDir = 1
gridheight
= polyRadius
* SQR(3) / 2 xoff = 0
FOR y
= -polyRadius
TO ymax
+ gridheight
STEP gridheight
FOR x
= -polyRadius
TO xmax
STEP 3 * polyRadius
_PUTIMAGE (x
+ xoff
* 1.5 * polyRadius
, y
), tile&
, 0
SUB prepTile
(pRadius
, innerStarRadius
, midPtDist
) tile&
= _NEWIMAGE(2 * pRadius
, 2 * pRadius
, 32) drawRegPolyStar pRadius, pRadius, pRadius, 6, innerStarRadius, midPtDist, triColor
SUB drawRegPolyStar
(cx
, cy
, pRadius
, nSides
, innerStarRadius
, midPtDist
, c1
AS _UNSIGNED LONG) DIM tilePtsX
(1 TO nSides
), tilePtsY
(1 TO nSides
) DIM innerStarX
(1 TO nSides
), innerStarY
(1 TO nSides
)
tilePtsX
(i
) = cx
+ pRadius
* COS(pA
* i
) tilePtsY
(i
) = cy
+ pRadius
* SIN(pA
* i
) 'on the same line the innerStar pts
innerStarX
(i
) = cx
+ innerStarRadius
* COS(pA
* i
) innerStarY
(i
) = cy
+ innerStarRadius
* SIN(pA
* i
) 'CIRCLE (innerStarX(i), innerStarY(i)), 3, _RGB32(255, 255, 0)
'draw tile
LINE (tilePtsX
(i
), tilePtsY
(i
))-(tilePtsX
(i
- 1), tilePtsY
(i
- 1)), _RGB32(255, 0, 0, 200) LINE (tilePtsX
(i
), tilePtsY
(i
))-(tilePtsX
(1), tilePtsY
(1)), _RGB32(255, 0, 0, 200) '_DELAY .5
'from each innerStarPt 2 lines connect to side midpoints
'lets calc all the midpoints +/- midPtDist
DIM mpdX
(1 TO 2 * nSides
), mpdY
(1 TO 2 * nSides
) mx = (tilePtsX(ei) + tilePtsX(i)) / 2
my = (tilePtsY(ei) + tilePtsY(i)) / 2
'check
'CIRCLE (mx, my), 2, _RGB32(0, 0, 255)
'_DELAY .5
'from each mx, my we need a point midPtDist along the angle from mx, my to the ei index point
a
= _ATAN2(tilePtsY
(ei
) - my
, tilePtsX
(ei
) - mx
) mdx
= mx
+ midPtDist
* COS(a
) mdy
= my
+ midPtDist
* SIN(a
) 'the other point is 180 degrees in opposite direction
mdx2
= mx
+ midPtDist
* COS(a
- _PI) mdy2
= my
+ midPtDist
* SIN(a
- _PI) 'check
'CIRCLE (mdx, mdy), 2, _RGB32(255, 255, 0)
'CIRCLE (mdx2, mdy2), 2, _RGB32(255, 0, 255)
'OK store all these points for drawing lines later
mpdX(2 * i - 1) = mdx: mpdY(2 * i - 1) = mdy
mpdX(2 * i) = mdx2: mpdY(2 * i) = mdy2
'from each point in inner star Radius draw 2 lines to the poly edges
'now figure the pattern: sequence maps are to 2*i +2 and to 2*i - 1
IF 2 * i
+ 2 > 2 * nSides
THEN map
= 2 * i
+ 2 - 2 * nSides
ELSE map
= 2 * i
+ 2 LINE (innerStarX
(i
), innerStarY
(i
))-(mpdX
(map
), mpdY
(map
))
IF 2 * i
- 1 < 1 THEN map2
= 2 * i
- 1 + 2 * nSides
ELSE map2
= 2 * i
- 1 LINE (innerStarX
(i
), innerStarY
(i
))-(mpdX
(map2
), mpdY
(map2
))
ftri innerStarX(i), innerStarY(i), mpdX(map), mpdY(map), mpdX(map2), mpdY(map2), c1
'_DELAY .5
rand%
= INT(RND * (hi%
- lo%
+ 1)) + lo%
' found at [abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]: http://www.[abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]/forum/index.php?topic=14425.0