_Title "Honeycombs thic lines - Rosetta Code" ' b+ 2021-10-30 trans from ' Honeycomb Rosetta.txt for JB v2 2018-11-24 B+ finish Rosetta Challenge
' 2021-10-30 complete overhaul except for grid drawing numbers and names.
' 2021-10-31 thicken lines a little, fix font for thicker lines.
' ===================== Try alternate Cols and Rows for HoneyComb ===============================
Const Cols
= 5, Rows
= 4, LMax
= Cols
* Rows
' hex grid <<<<<<<<<<<<<< as Rosetta Requires 'Const Cols = 4, Rows = 5, LMax = Cols * Rows ' hex grid <<<<<<<<<<<<<< reverse
'Const Cols = 6, Rows = 5, LMax = Cols * Rows ' hex grid <<<<<<<<<<<<<< More than just Letters
'Const Cols = 13, Rows = 2, LMax = Cols * Rows ' hex grid do exactly whole alphabet!
' global SELECTED$ ' all caps for globals
Const Pi3
= _Pi / 3, Sqr3
= Sqr(3), Side
= 30 ' constants for Hexagon making Const Xoff
= 100 - 1.5 * Side
, Yoff
= 100 - Side
* Sqr3
' center grid with offsets on screen Const XMax
= 2 * Xoff
+ Cols
* 1.5 * Side
+ 1.5 * Side
' screen display size needed Const YMax
= 2 * Yoff
+ (Rows
+ 2) * Side
* Sqr3
Dim Shared L$
(LMax
), LX
(LMax
), LY
(LMax
), LSELECTED
(LMax
), Selected$
' save letter and hex center positions by index
For i
= 1 To LMax
' get letters array loaded For i
= LMax
To 2 Step -1 ' shuffle letters Fisher - Yates
_Delay .25 ' get screen loaded before trying to move
f&
= _LoadFont("Consolab.ttf", 36) ' >>>>>>>>>>>> from Windows 10 FontsFor y
= 1 To Rows
' initialize screen with grid n = n + 1 ' index hex buttons
If x
Mod 2 = 0 Then yoff2
= .5 * Side
* Sqr3
Else yoff2
= 0 ' is this column lower than first column? cx = x * 1.5 * Side + Xoff: cy = y * Side * Sqr3 + Yoff + yoff2 ' calc hex key centers
LX(n) = cx: LY(n) = cy ' save hex key center positions
drawHex n, 0 ' draw key
While _KeyDown(27) = 0 ' allow user to select letters by key or mouse For i
= 1 To LMax
'if so was it selected already? or select it. For i
= 1 To LMax
' is distance from click within radius of non-selected button? If Sqr((mx
- LX
(i
)) ^ 2 + (my
- LY
(i
)) ^ 2) <= Side
* .5 * Sqr3
And LSELECTED
(i
) = 0 Then drawHex i
, 1
Sub drawHex
(i
, selectedTF
) x1
= LX
(i
) + Side
* Cos(a
* Pi3
): y1
= LY
(i
) + Side
* Sin(a
* Pi3
)
' =============================== Different versions of Thick Lines ======================
'If a > 0 Then Line (lastx, lasty)-(x1, y1), _RGB32(0, 0, 0) ' original no thick lines
'If a > 0 Then thic lastx, lasty, x1, y1, 2, _RGB32(0, 0, 0) ' these rectangle thick lines
' leave gaps where they meet at angles rounded with circles they leave knobs, r-1 they
' still leave gaps!
'Best
If a
> 0 Then thic2 lastx
, lasty
, x1
, y1
, 2, _RGB32(0, 0, 0) ' these thick lines are draw with filled circles like ball point pen
'=========================================================================================
lastx = x1: lasty = y1
If selectedTF
Then ' show the order of selection LSELECTED(i) = 1
Selected$ = Selected$ + L$(i)
Sub centerText
(x1
, x2
, midy
, s$
) ' ' if you want to center fit a string between two goal posts x1, and x2
'update 2020-01-24 to include PD2 inside the sub
PD2 = 1.570796326794897
t2 = thick / 2
x3
= x1
+ t2
* Cos(a
+ PD2
) y3
= y1
+ t2
* Sin(a
+ PD2
) x4
= x1
+ t2
* Cos(a
- PD2
) y4
= y1
+ t2
* Sin(a
- PD2
) x5
= x2
+ t2
* Cos(a
+ PD2
) y5
= y2
+ t2
* Sin(a
+ PD2
) x6
= x2
+ t2
* Cos(a
- PD2
) y6
= y2
+ t2
* Sin(a
- PD2
) ftri x6, y6, x4, y4, x3, y3, K
ftri x3, y3, x5, y5, x6, y6, K
fcirc x1
, y1
, t2
- 1, _RGB32(0, 0, 0) ' close gaps where two lines meet fcirc x2
, y2
, t2
- 1, _RGB32(0, 0, 0)
'2019-12-16 fix by Steve saves some time with STATIC and saves and restores last dest
_Blend a&
'<<<< new 2019-12-16 fix
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
'this version needs fcirc and is pretty inefficient but once and a while it comes in handy
'x1, y1 is one endpoint of line
'x2, y2 is the other endpoint of the line
'rThick is the radius of the tiny circles that will be drawn
' from one end point to the other to create the thick line
'Yes, the line will then extend beyond the endpoints with circular ends.
rThick
= Int(rThick
/ 2): stepx
= x2
- x1: stepy
= y2
- y1
length
= Int((stepx
^ 2 + stepy
^ 2) ^ .5) dx = stepx / length: dy = stepy / length
fcirc x1 + dx * i, y1 + dy * i, rThick, K
fcirc x1, y1, rThick, K