Basicprogramming(.org) > General questions and discussions

Celtic Knot Challenge

(1/3) > >>

Anyone else want to try this:

EDIT: title of thread.

 I think I ruined my eyes, getting all start and end angles for arcs. Ruined eyes in turn makes it hard to detect typos, assuming you know how to spell the word in first place :D

I'm lazy, so if you could outline the algorithm I'll definitely give that a go :)


--- Quote from: ZXDunny on July 04, 2019, 10:31:22 am ---I'm lazy, so if you could outline the algorithm I'll definitely give that a go :)

--- End quote ---
+1  ;D

Sorry, it is time and patience exercise that I know of:

_TITLE "Vince Celtic Challenge Skeleton"
CONST xmax = 1200, ymax = 700, pi = 3.14159265
CONST xc = xmax / 2, yc = ymax / 2
SCREEN _NEWIMAGE(xmax, ymax, 32)

celticKnot xc, yc, 30

SUB celticKnot (xc, yc, thick)
    DIM distr, r, r1, hex, hd2, nHex, x0, y0, c AS _UNSIGNED LONG

    distr = 5 * thick
    r = 4 * thick
    r1 = 3 * thick
    hex = pi * 2 / 6
    hd2 = hex / 2

    FOR nHex = 1 TO 6
        IF nHex <= 2 THEN c = &HFFFFFFFF ELSE c = &HFF444444
        'circles with origins in main circle
        x0 = xc + distr * COS(nHex * hex - hd2)
        y0 = yc + distr * SIN(nHex * hex - hd2)

        'outer radius
        CIRCLE (x0, y0), r, c
        'inner radius
        CIRCLE (x0, y0), r1, c

        ' circles with outside origins
        x0 = xc + (2 * distr - 1.5 * thick) * COS(nHex * hex)
        y0 = yc + (2 * distr - 1.5 * thick) * SIN(nHex * hex)
        IF nHex = 1 THEN c = &HFF0000FF ELSE c = &HFF444444
        'outer radius
        CIRCLE (x0, y0), r, c
        'inner radius
        CIRCLE (x0, y0), r1, c


--- End code ---

This code draws the circle "skeleton" from which I eyeballed 12 Arcs with 12 Start Angles and 12 End Angles for an Arc Sub to draw in one "inside" circle ring and one "outside" ring. The 2nd inside ring highlighted is there to help show where bridges go on the overlap "inner" rings. Once that set is ready just repeat 6 times around the origin.

--- Code: ---SUB arc (x, y, r, raStart, raStop, c AS _UNSIGNED LONG)
    '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

    DIM al, a
    IF raStop < raStart THEN
        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)
        FOR a = raStart TO raStop STEP 1 / al
            PSET (x + r * COS(a), y + r * SIN(a)), c
    END IF

--- End code ---

I was thinking I might automate the arc data by point and click with mouse for the start and end angles of arcs because the 2nd part of the challenge or extra credit goes to being able to change the width of the rings.

EDIT: Sorry for misspelling of Thread Title

Update: Apparently one can do everything mathematically given 3 radii and "width to render the image."

To eliminate eye-balling start and end arcs, I have worked up code for the 2 points intersect of 2 circles when they do intersect.

Hopefully this will allow me to draw a variety of ring widths with math only.


[0] Message Index

[#] Next page

Go to full version