_TITLE "Celtic Challenge Advanced Sub" 'B+ 2019-07-06 develop as a sub ' parameters are x, y origin, radius of Knot, thicknes of rings, border color and fill color
' is there a max radius of knot?
CONST xmax
= 700, ymax
= 700, pi
= 3.14159265 CONST xc
= xmax
/ 2, yc
= ymax
/ 2
INPUT "Enter knot size, 20 to 150 best "; knot
INPUT "Enter ring thickness, 1 to 20% knot best ", thick
INPUT "Enter f to fill in with green, best not to fill when thickness < %5 knot "; w$
IF w$
= "f" THEN celticKnot xc
, yc
, knot
, thick
, &HFFFFFF00, &HFF00BB00 ELSE celticKnot xc
, yc
, knot
, thick
, &HFFFFFF00, 0 INPUT "press enter to cont... "; w$
'the max thickness for the knotRadius is .25 * knotRadius, ideal max is about 20%
' use 0 for fill color to skip PAINT jobs, recommended for small or thin knots
DIM r
, r1
, hex
, hd2
, nHex
'a good naming system is crucial i/o = inner/outer circle,
'p1/m1 plus1/minus1 (actually it's plus and minus 1/2 for outer rings)
DIM xi
, yi
, xim1
, yim1
, xip1
, yip1
, xom1
, yom1
, xop1
, yop1
'points of interest
DIM xm1
, xm2
, xm3
, xm4
, xm5
, xm6
, xm7
, xm9
, xm10
, xm12
DIM ym1
, ym2
, ym3
, ym4
, ym5
, ym6
, ym7
, ym9
, ym10
, ym12
DIM xn1
, xn2
, xn3
, xn4
, xn5
, xn6
, xn8
, xn9
, xn10
, xn11
DIM yn1
, yn2
, yn3
, yn4
, yn5
, yn6
, yn8
, yn9
, yn10
, yn11
DIM xp1
, xp2
, xp3
, xp4
, xp5
, xp6
, xp7
, xp8
DIM xq1
, xq2
, xq3
, xq4
, xq5
, xq6
DIM yp1
, yp2
, yp3
, yp4
, yp5
, yp6
, yp7
, yp8
DIM yq1
, yq2
, yq3
, yq4
, yq5
, yq6
r = .8 * knotR '4
r1 = r - ringThick '3 * ringThick ' 3
hex = pi * 2 / 6
hd2 = hex / 2
'5 circle origin sets
'inner ring before main ring
xim1
= xc
+ knotR
* COS((nHex
- 1) * hex
- hd2
) yim1
= yc
+ knotR
* SIN((nHex
- 1) * hex
- hd2
)
'main inner ring to draw up
xi
= xc
+ knotR
* COS(nHex
* hex
- hd2
) yi
= yc
+ knotR
* SIN(nHex
* hex
- hd2
)
'inner ring after main
xip1
= xc
+ knotR
* COS((nHex
+ 1) * hex
- hd2
) yip1
= yc
+ knotR
* SIN((nHex
+ 1) * hex
- hd2
)
'outer ring before main ring
xom1
= xc
+ (2 * knotR
- 1.5 * ringThick
) * COS((nHex
- 1) * hex
) yom1
= yc
+ (2 * knotR
- 1.5 * ringThick
) * SIN((nHex
- 1) * hex
)
'outer ring after main ring
xop1
= xc
+ (2 * knotR
- 1.5 * ringThick
) * COS(nHex
* hex
) yop1
= yc
+ (2 * knotR
- 1.5 * ringThick
) * SIN(nHex
* hex
)
'working main ring from 0 to 2*pi one segment at a time
'first point of interest on main is out circle /\ out circle of op1
intersect2Circles xi, yi, r, xop1, yop1, r, xm1, ym1, xm4, ym4
intersect2Circles xi, yi, r, xop1, yop1, r1, xm2, ym2, xm3, ym3
intersect2Circles xi, yi, r, xop1, yop1, r1, xm2, ym2, xm3, yn3
intersect2Circles xi, yi, r1, xop1, yop1, r1, xn2, yn2, xn3, yn3
minorArc xi, yi, r, rAngle(xi, yi, xm1, ym1), rAngle(xi, yi, xm3, ym3), outline
minorArc xi, yi, r1, rAngle(xi, yi, xn2, yn2), rAngle(xi, yi, xn3, yn3), outline
'inside main outside po1
intersect2Circles xi, yi, r1, xop1, yop1, r, xn1, yn1, xn4, yn4
'outside main with outside im1
intersect2Circles xi, yi, r, xim1, yim1, r, xm5, ym5, xm10, ym10
'inside main outside im1
intersect2Circles xi, yi, r1, xim1, yim1, r, xn5, yn5, xn10, yn10
minorArc xi, yi, r, rAngle(xi, yi, xm4, ym4), rAngle(xi, yi, xm5, ym5), outline
minorArc xi, yi, r1, rAngle(xi, yi, xn4, yn4), rAngle(xi, yi, xn5, yn5), outline
'outside main to inside im1
intersect2Circles xi, yi, r, xim1, yim1, r1, xm6, ym6, xm9, ym9
'inside main to inside im1
intersect2Circles xi, yi, r1, xim1, yim1, r1, xn6, yn6, xn9, yn9
minorArc xi, yi, r, rAngle(xi, yi, xm6, ym6), rAngle(xi, yi, xm9, ym9), outline
minorArc xi, yi, r1, rAngle(xi, yi, xn6, yn6), rAngle(xi, yi, xn9, yn9), outline
'outer main to outer om1
intersect2Circles xi, yi, r, xom1, yom1, r, xm7, ym7, xm12, ym12
'inner main to inner om1
intersect2Circles xi, yi, r1, xom1, yom1, r1, xn8, yn8, xn11, yn11
minorArc xi, yi, r, rAngle(xi, yi, xm10, ym10), rAngle(xi, yi, xm12, ym12), outline
minorArc xi, yi, r1, rAngle(xi, yi, xn10, yn10), rAngle(xi, yi, xn11, yn11), outline
'now for the two that fold inward
'outer op1 to outer ip1
intersect2Circles xop1, yop1, r, xip1, yip1, r, xp1, yp1, xp4, yp4
'outer op1 to inner p1
intersect2Circles xop1, yop1, r, xip1, yip1, r1, xp2, yp2, xp3, yp3
'inner op1 to inner p1
intersect2Circles xop1, yop1, r1, xip1, yip1, r1, xq2, yq2, xq3, yq3
minorArc xop1, yop1, r, rAngle(xop1, yop1, xp1, yp1), rAngle(xop1, yop1, xp3, yp3), outline
minorArc xop1, yop1, r1, rAngle(xop1, yop1, xq2, yq2), rAngle(xop1, yop1, xq3, yq3), outline
'inner op1 outer inner p1
intersect2Circles xop1, yop1, r1, xip1, yip1, r, xq1, yq1, xq4, yq4
minorArc xop1, yop1, r, rAngle(xop1, yop1, xp4, yp4), rAngle(xop1, yop1, xm1, ym1), outline
'last test?
minorArc xop1, yop1, r1, rAngle(xop1, yop1, xq4, yq4), rAngle(xop1, yop1, xn1, yn1), outline
'outer om1 to outer outer main
intersect2Circles xom1, yom1, r, xi, yi, r, xp5, yp5, xp8, yp8
'inner om1 to inner main
intersect2Circles xom1, yom1, r1, xi, yi, r1, xq5, yq5, xq6, yq6
'outer om1to inner main
intersect2Circles xom1, yom1, r, xi, yi, r1, xp6, yp6, xp7, yp7
minorArc xom1, yom1, r, rAngle(xom1, yom1, xp5, yp5), rAngle(xom1, yom1, xp7, yp7), outline
minorArc xom1, yom1, r1, rAngle(xom1, yom1, xq5, yq5), rAngle(xom1, yom1, xq6, yq6), outline
midR = (r + r1) / 2 + .5
'circles with origins in main circle
'main inner ring to draw up
xi
= xc
+ knotR
* COS(nHex
* hex
- hd2
) yi
= yc
+ knotR
* SIN(nHex
* hex
- hd2
)
'4 paint points
px
= xi
+ midR
* COS(nHex
* hex
+ .1 * pi
) py
= yi
+ midR
* SIN(nHex
* hex
+ .1 * pi
) 'CIRCLE (px, py), 1, fill
PAINT (px
, py
), fill
, outline
px
= xi
+ midR
* COS(nHex
* hex
+ .7 * pi
) py
= yi
+ midR
* SIN(nHex
* hex
+ .7 * pi
) 'CIRCLE (px, py), 1, fill
PAINT (px
, py
), fill
, outline
px
= xi
+ midR
* COS(nHex
* hex
+ 1.3 * pi
) py
= yi
+ midR
* SIN(nHex
* hex
+ 1.3 * pi
) 'CIRCLE (px, py), 1, fill
PAINT (px
, py
), fill
, outline
px
= xi
+ midR
* COS(nHex
* hex
+ 1.7 * pi
) py
= yi
+ midR
* SIN(nHex
* hex
+ 1.7 * pi
) 'CIRCLE (px, py), 1, fill
PAINT (px
, py
), fill
, outline
'given a circles origin and point on the circumference return the arc measure of that point
FUNCTION rAngle
(coX
, coY
, circumX
, circumY
) rAngle
= _ATAN2(circumY
- coY
, circumX
- coX
)
'given two arc angles I want the one that draws the smaller arc drawn
'which has smaller arc measure
IF ra2
- ra1
< _PI THEN raStart
= ra1: raStop
= ra2
ELSE raStart
= ra2: raStop
= ra1
IF ra1
- ra2
< _PI THEN raStart
= ra2: raStop
= ra1
ELSE raStart
= ra1: raStop
= ra2
arc x, y, r, raStart, raStop, c
SUB intersect2Circles
(x1
, y1
, r1
, x2
, y2
, r2
, ix1
, iy1
, ix2
, iy2
) 'x1, y1 origin of circle 1 with radius r1
'x2, y2 origin of circle 2 with radius r2
'ix1, iy1 is the first point of intersect
'ix2, iy2 is the 2nd point of intersect
'if ix1 = ix2 = iy1 = iy2 = 0 then no points returned
DIM d
, a
, h
, Px
, Py
, offset
, rang1
, rang2
d = distance(x1, y1, x2, y2) 'distance between two origins
'PRINT "The circles are too far apart to intersect.": END
'some signal ??? if ix1 = ix2 = iy1 = iy2 = 0 then no points returned
ix1 = 0: ix2 = 0: iy1 = 0: iy2 = 0
IF (d
< r1
AND r2
+ d
< r1
) OR (d
< r2
AND r1
+ d
< r2
) THEN ' no intersect ix1 = 0: ix2 = 0: iy1 = 0: iy2 = 0
'results
a = (r1 ^ 2 - r2 ^ 2 + d ^ 2) / (2 * d)
Px = x1 + a * (x2 - x1) / d
Py = y1 + a * (y2 - y1) / d
h = (r1 ^ 2 - a ^ 2) ^ .5
ix1
= INT(Px
- h
* (y2
- y1
) / d
) iy1
= INT(Py
+ h
* (x2
- x1
) / d
) ix2
= INT(Px
+ h
* (y2
- y1
) / d
) iy2
= INT(Py
- h
* (x2
- x1
) / d
)
''getting the order of points matched to varaible labels
offset = rAngle(xc, yc, x1, y1)
rang1 = rAngle(x1, y1, ix1, iy1) - offset
IF rang1
< 0 THEN rang1
= rang1
+ 2 * pi
rang2 = rAngle(x1, y1, ix2, iy2) - offset
IF rang2
< 0 THEN rang2
= rang2
+ 2 * pi
'x, y origin, r = radius, c = color
'raStart is first angle clockwise from due East = 0 degrees
' arc will start drawing there and clockwise until raStop angle reached
arc x
, y
, r
, raStart
, _PI(2), c
arc x, y, r, 0, raStop, c
' modified to easier way suggested by Steve
'Why was the line method not good? I forgot.
al
= _PI * r
* r
* (raStop
- raStart
) / _PI(2)
FUNCTION rrnd
(n1
, n2
) 'return real number between rrnd
= (n2
- n1
) * RND + n1
distance = ((x1 - x2) ^ 2 + (y1 - y2) ^ 2) ^ .5