QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: bplus on June 27, 2019, 06:55:47 pm

Title: Cresent Pattern Challenge from JB
Post by: bplus on June 27, 2019, 06:55:47 pm
Can you draw this pattern:

  [ This attachment cannot be displayed inline in 'Print Page' view ]  
Title: Re: Cresent Pattern Challenge from JB
Post by: SMcNeill on June 27, 2019, 08:08:50 pm
Sure I can, and in the easiest way imaginable!
Title: Re: Cresent Pattern Challenge from JB
Post by: bplus on June 27, 2019, 09:45:26 pm
;-)) Pretty hefty .bas file there Steve! But that's smart thinking. :)

Maybe someone can do it in a couple less MB's.

  [ This attachment cannot be displayed inline in 'Print Page' view ]  
Title: Re: Cresent Pattern Challenge from JB
Post by: SMcNeill on June 27, 2019, 10:00:36 pm
Honestly, since it’s a black and white pattern, one can turn those data statements into a simple set of on/off counters.  3 white, 13 black, 33 white... 

Instead of saving data as pixel by pixel, save that data as number of white, number of black, number of white...  (3, 13, 33...)

It’d compress down to a fraction of the size.  (Maybe even as small as your screenshot.  ;-D)
Title: Re: Cresent Pattern Challenge from JB
Post by: Ashish on June 28, 2019, 01:43:37 am
Hi. I tried doing this in approx. 2KB, but I can not get closer than this. ;)

 [ This attachment cannot be displayed inline in 'Print Page' view ]    

Code: QB64: [Select]
  1. _TITLE "Pattern Challenge Program by Ashish"
  2. SCREEN _NEWIMAGE(800, 600, 32)
  3. buffer& = _COPYIMAGE(0)
  4. CLS , _RGB(255, 255, 255)
  5. _DEST buffer&
  6. CLS , 1
  7. rad = 50
  8. FOR y = rad TO _HEIGHT STEP rad * SQR(3)
  9.     IF a = 0 THEN
  10.         a = 1
  11.         k = 0
  12.         FOR x = 0 TO _WIDTH STEP rad * 2
  13.             IF k = 0 THEN
  14.                 k = 1
  15.                 pattern x, y, rad, 0
  16.             ELSE
  17.                 k = 0
  18.                 pattern x, y, rad, 0.85
  19.             END IF
  20.         NEXT x
  21.     ELSE
  22.         a = 0
  23.         k = 0
  24.         FOR x = rad TO _WIDTH STEP rad * 2
  25.             IF k = 0 THEN
  26.                 k = 1
  27.                 pattern x, y, rad, 0
  28.             ELSE
  29.                 k = 0
  30.                 pattern x, y, rad, 0.85
  31.             END IF
  32.  
  33.         NEXT x
  34.     END IF
  35. _SOURCE buffer&
  36. FOR i = 0 TO _WIDTH - 1
  37.     FOR j = 0 TO _HEIGHT - 1
  38.         IF POINT(i, j) = _RGB(255, 255, 255) THEN PSET (i, j), _RGB(0, 0, 0)
  39. NEXT j, i
  40. _PUTIMAGE (0, 0), buffer&
  41. SUB pattern (x, y, r, off_ang)
  42.     CIRCLE (x, y), r, _RGB(254, 254, 254)
  43.     FOR i = off_ang TO _PI(2) + off_ang STEP _PI(1 / 6) '2pi/12
  44.         circ (x + (COS(i) * r + x)) / 2, (y + (SIN(i) * r + y)) / 2, r / 2, r / 2, _RGB(254, 254, 254), i, _PI + i
  45.     NEXT
  46.     FOR i = off_ang TO _PI(2) + off_ang STEP _PI(1 / 6) '2pi/12
  47.         IF n = 0 THEN
  48.             n = 1
  49.             PAINT (COS(i) * 0.8 * r + x, SIN(i) * 0.8 * r + y), _RGB(255, 255, 255), _RGB(254, 254, 254)
  50.         ELSE n = 0
  51.         END IF
  52.     NEXT
  53. SUB circ (x, y, rx, ry, c~&, theta1, theta2)
  54.     FOR i = theta1 TO theta2 STEP 0.01
  55.         LINE (COS(i) * rx + x, SIN(i) * ry + y)-(COS(i + 0.01) * rx + x, SIN(i + 0.01) * ry + y), c~&
  56.     NEXT
  57.  
Title: Re: Cresent Pattern Challenge from JB
Post by: Petr on June 28, 2019, 05:53:18 am
Hi BPlus. Mine is not so good as your.
Second radius is ellipse?

Code: QB64: [Select]
  1.  
  2. DIM Frames(9) AS LONG
  3.  
  4.  
  5. FOR f = 1 TO 9
  6.     R = R - _PI(2) / 9
  7.     Frames(f) = _NEWIMAGE(101, 101, 256)
  8.     _DEST Frames(f)
  9.     FOR pi = R TO R + _PI(2) STEP _PI(2) / 6
  10.         sx = 50 + COS(pi) * 25
  11.         sy = 50 + SIN(pi) * 25
  12.         sx2 = 50 + COS(pi + .3) * 25
  13.         sy2 = 50 + SIN(pi + .3) * 25
  14.         sx3 = 50 + COS(pi + _PI(2) / 6 + .2) * 20
  15.         sy3 = 50 + SIN(pi + _PI(2) / 6 + .2) * 20
  16.  
  17.         FOR c = 0 TO _PI(1.1) STEP .001
  18.             PSET (sx + COS(c + pi) * 25, sy + SIN(c + pi) * 25)
  19.             PSET (sx2 + COS(c + pi) * 25, sy2 + SIN(c + pi) * 25)
  20.         NEXT c
  21.         PAINT (sx3, sy3), 15, 15
  22.     NEXT
  23.     _CLEARCOLOR 0
  24.  
  25. SCREEN _NEWIMAGE(800, 600, 256)
  26. _PALETTECOLOR 0, &HFFFFFFFF
  27. _PALETTECOLOR 15, &HFF000000
  28.  
  29. f = 0
  30.  
  31.     CLS
  32.     g = 0
  33.     FOR y = 0 TO 600 STEP 90
  34.         g = g + 1
  35.         FOR x = -100 TO 800 STEP 96
  36.             f = f + 1
  37.             IF f > 9 THEN f = 1
  38.             IF g MOD 2 = 0 THEN p = 50 ELSE p = 0
  39.             _PUTIMAGE (x + p, y), Frames(f)
  40.         NEXT x
  41.     NEXT y
  42.     _LIMIT 20
  43.     _DISPLAY
  44.  
Title: Re: Cresent Pattern Challenge from JB
Post by: Ashish on June 28, 2019, 08:27:49 am
@Petr
That has nearly damaged my eyesight. :D
Title: Re: Cresent Pattern Challenge from JB
Post by: Petr on June 28, 2019, 08:52:20 am
Hi Ashish. Am sorry :-D  Bplus destroyed my brain :-D
Title: Re: Cresent Pattern Challenge from JB
Post by: FellippeHeitor on June 28, 2019, 09:20:58 am
@Petr and @Ashish,

You guys are definitely going places.
Title: Re: Cresent Pattern Challenge from JB
Post by: _vince on June 28, 2019, 11:08:38 am
Code: QB64: [Select]
  1.  
  2. declare sub swirl(x, y, r)
  3. pi = 4*atn(1)
  4. r = 70
  5.  
  6.  
  7. line (0,0)-(640,480),,bf
  8.  
  9. for yy = 0 to 5
  10. for xx = 0 to 5  
  11.     swirl xx*2*r + r*(yy and 1), 0 + yy*2*r*cos(pi/6), r
  12.  
  13.  
  14. sub swirl(x, y, r)
  15.     dim a as double, b as double
  16.  
  17.     for i=0 to 6
  18.         xx = x + 0.5*r*cos(i*pi/3)
  19.         yy = y + 0.5*r*sin(i*pi/3)
  20.        
  21.         a = i*pi/3
  22.        
  23.         pset (xx + 0.5*r*cos(a), yy + 0.5*r*sin(a)), 0
  24.         for b=a to a + pi step 0.01
  25.             line -(xx + 0.5*r*cos(b), yy + 0.5*r*sin(b)), 0
  26.         next
  27.        
  28.         pset (xx + 0.5*r*cos(a), yy + 0.5*r*sin(a)), 0
  29.         for b=0 to pi step 0.01
  30.             line -(xx + 0.5*r*cos(b)*cos(a) - 0.28*r*sin(b)*sin(a), yy + 0.5*r*cos(b)*sin(a) + 0.28*r*sin(b)*cos(a)), 0
  31.         next
  32.        
  33.         paint (xx - 0.4*r*sin(a), yy + 0.4*r*cos(a)), 0
  34.     next
  35.  
Title: Re: Cresent Pattern Challenge from JB
Post by: bplus on June 28, 2019, 11:19:33 am
@Petr and @Ashish,

You guys are definitely going places.

Yeppers!

Ashish, your trailing edge is a radius of a circle as the leading edge, a result I failed to achieve, nice!

Petr, your code has 2 lines more than mine and yours moves! also nice!

Oh Vince just posted! Dang! wow, nice concise code!!!



My trailing edge is not a radius of a circle, I'm not even sure it is ellipse.
If leading edge y = SQR(radius^2 - x^2) then trailing edge is a fraction of y, so I can make the crescent as thick or thin as I want. EDIT minus not plus

Yeah Petr, now I've got to get the cresents twirling too! ;-)) Plus.... :)


PS sorry for my poor spelling of crescent (the spell checker worked!)
Title: Re: Cresent Pattern Challenge from JB
Post by: Ashish on June 28, 2019, 11:34:35 am
@Vince
Perfect one!
Title: Re: Cresent Pattern Challenge from JB
Post by: TempodiBasic on June 28, 2019, 11:39:29 am
Hi guys
for  now I'm debugging my idea

to get the slices  putting a circle up to another circle.. :-)

I must stop my idea for now. Job is calling!

here bugged code (only forn now)
Code: QB64: [Select]
  1. CONST d = 100
  2. SCREEN _NEWIMAGE(800, 600, 32)
  3. _TITLE "Cresent"
  4. PAINT (1, 1), _RGB32(255, 255, 255)
  5. DIM NumX AS INTEGER, NumY AS INTEGER, i AS INTEGER, i2 AS INTEGER
  6. NumX = _CEIL(_WIDTH / d): NumY = _CEIL(_HEIGHT / d)
  7. FOR i = 0 TO NumX
  8.     FOR i2 = 0 TO NumY
  9.         IF i2 MOD 2 = 0 THEN k = 0 ELSE k = d / 4
  10.         x = (i * d) + k
  11.         y = i2 * d
  12.         r = d / 2
  13.         c~& = _RGB32(0, 0, 0)
  14.         CIRCLE (x, y), r, c~&
  15.         MakeSlice x, y, r, c~&
  16.     NEXT i2
  17.  
  18. SUB MakeSlice (xp AS INTEGER, yp AS INTEGER, r AS INTEGER, col AS _UNSIGNED LONG)
  19.     DIM a AS INTEGER, ax AS INTEGER, ay AS INTEGER, ar AS INTEGER, col2 AS _UNSIGNED LONG
  20.     ar = INT(r / 2)
  21.     FOR a = 1 TO 12 STEP 1
  22.         ax = SIN(15 * a) * ar
  23.         ay = COS(15 * a) * ar
  24.         IF a MOD 2 = 0 THEN col2 = col ELSE col2 = _RGB32(255, 255, 255)
  25.         CIRCLE (ax + xp, ay + yp), ar, col
  26.         PAINT STEP(0, 0), col2, col
  27.      NEXT

Here partial result:
  [ This attachment cannot be displayed inline in 'Print Page' view ]  

I'll change circle with fillcircle of library of QB64 and I'll search the right number of circle to draw
Title: Re: Cresent Pattern Challenge from JB
Post by: Petr on June 28, 2019, 01:57:54 pm
Very nice, _vince!
Title: Re: Cresent Pattern Challenge from JB
Post by: bplus on June 28, 2019, 02:48:58 pm
Yes, Vince code is really nice compared to mine used to create the screen shot in original post:
Code: QB64: [Select]
  1. CONST xmax = 800, ymax = 600
  2. _TITLE "Cresent" 'mod B+ makeover started 2019-06-27
  3. SCREEN _NEWIMAGE(xmax, ymax, 32)
  4. _SCREENMOVE 300, 40
  5.  
  6. DIM polyR, stepX, stepY, y, x, xoff
  7. COLOR &HFF000000, &HFFFFFFFF
  8. polyR = 32
  9. stepX = polyR * 4
  10. stepY = polyR * 2 * SQR(3)
  11. FOR y = 16 TO ymax - 16 STEP stepY
  12.     xoff = (xoff + 1) MOD 2
  13.     FOR x = 0 TO xmax + 7 * polyR STEP stepX
  14.         cresentX6 x - xoff * 1.5 * stepX, y
  15.     NEXT
  16.  
  17. SUB cresentX6 (x0, y0)
  18.     DIM r, x, y, py, x1, y1, x2, y2, a, dist1, a1, x3, y3, dist2, a2, x4, y4
  19.     r = 32
  20.     FOR x = -r TO r STEP .005
  21.         y = SQR(r ^ 2 - x ^ 2)
  22.         py = .53 * y
  23.         x1 = x + x0 + r
  24.         y1 = y + y0
  25.         x2 = x1
  26.         y2 = py + y0
  27.         LINE (x1, y1)-(x2, y2)
  28.         FOR a = 0 TO 2 * _PI STEP _PI(1 / 3)
  29.             dist1 = SQR((x1 - x0) ^ 2 + (y1 - y0) ^ 2)
  30.             a1 = _ATAN2(y1 - y0, x1 - x0)
  31.             x3 = x0 + dist1 * COS(a1 + a)
  32.             y3 = y0 + dist1 * SIN(a1 + a)
  33.  
  34.             dist2 = SQR((x2 - x0) ^ 2 + (y2 - y0) ^ 2)
  35.             a2 = _ATAN2(y2 - y0, x2 - x0)
  36.             x4 = x0 + dist2 * COS(a2 + a)
  37.             y4 = y0 + dist2 * SIN(a2 + a)
  38.             LINE (x3, y3)-(x4, y4)
  39.         NEXT
  40.     NEXT
  41.  
  42.  

I was working up something to post at JB forum but JB does not have PAINT (nor POINT).

I have reworked Vince code without PAINT so I can show it off at JB! ;-))
Code: QB64: [Select]
  1. _DEFINE A-Z AS _FLOAT : _TITLE "Crescent by Vince B+ Mod W/O PAINT" 'b+ 2019-06-28
  2. CONST K = &HFFFFFFFF, pi = _PI, r = 70
  3. SCREEN _NEWIMAGE(700, 623, 32)
  4. FOR yy = 0 TO 4
  5.     FOR xx = 0 TO 5
  6.         swirl xx * 2 * r + r * (yy AND 1), 0 + yy * 2 * r * COS(pi / 6)
  7.     NEXT
  8. SUB swirl (x, y)
  9.     FOR i = 0 TO 5
  10.         xx = x + 0.5 * r * COS(i * pi / 3) - r  'Edit: this and next, removed variables not used
  11.         yy = y + 0.5 * r * SIN(i * pi / 3) + r
  12.         a = i * pi / 3
  13.         FOR b = a TO a + pi STEP .0001
  14.             c = b - a
  15.             LINE (xx + 0.5 * r * COS(b), yy + 0.5 * r * SIN(b))-(xx + 0.5 * r * COS(c) * COS(a) - 0.28 * r * SIN(c) * SIN(a), yy + 0.5 * r * COS(c) * SIN(a) + 0.28 * r * SIN(c) * COS(a)), K
  16.         NEXT
  17.     NEXT
  18.  
I reversed the B&W to save a line, to get lines to 20:
  [ This attachment cannot be displayed inline in 'Print Page' view ]  
Title: Re: Cresent Pattern Challenge from JB
Post by: TempodiBasic on June 28, 2019, 03:57:41 pm
Good news for all you math guys

my graphic idea has an overlapping logic bug ...
but it does the same something.

  [ This attachment cannot be displayed inline in 'Print Page' view ]  
Code: QB64: [Select]
  1. CONST d = 100
  2. SCREEN _NEWIMAGE(800, 600, 32)
  3. _TITLE "Cresent"
  4. PAINT (1, 1), _RGB32(255, 255, 255)
  5. DIM NumX AS INTEGER, NumY AS INTEGER, i AS INTEGER, i2 AS INTEGER
  6. NumX = _CEIL(_WIDTH / d): NumY = _CEIL(_HEIGHT / d)
  7. FOR i = 0 TO NumX
  8.     FOR i2 = 0 TO NumY
  9.         IF i2 MOD 2 = 0 THEN k = 0 ELSE k = d / 4
  10.         x = (i * d) + k
  11.         y = i2 * d
  12.         r = d / 2
  13.         c~& = _RGB32(0, 0, 0)
  14.         MakeSlice x, y, r, c~&
  15.     NEXT i2
  16.  
  17. SUB MakeSlice (xp AS INTEGER, yp AS INTEGER, r AS INTEGER, col AS _UNSIGNED LONG)
  18.     DIM a AS INTEGER, ax AS INTEGER, ay AS INTEGER, ar AS INTEGER, col2 AS _UNSIGNED LONG
  19.     ar = INT(r / 2)
  20.     FOR a = 6 TO 3 STEP -1
  21.         col2 = col
  22.         ax = SIN(a) * ar
  23.         ay = COS(a) * ar
  24.         'CIRCLE (ax + xp, ay + yp), ar, col2
  25.         'PAINT STEP(0, 0), col2, col2
  26.         CALL CircleFill(ax + xp, ay + yp, ar, col2)
  27.         ax = SIN(a + 6) * ar
  28.         ay = COS(a + 6) * ar
  29.         '       CIRCLE (ax + xp, ay + yp), ar, _RGB32(255, 255, 255)
  30.         '        PAINT STEP(0, 0), _RGB32(255, 255, 255), _RGB32(255, 255, 255)
  31.         CALL CircleFill(ax + xp, ay + yp, ar, _RGB32(255, 255, 255))
  32.     NEXT
  33.  
  34. SUB CircleFill (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  35.     ' CX = center x coordinate
  36.     ' CY = center y coordinate
  37.     '  R = radius
  38.     '  C = fill color
  39.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  40.     DIM X AS INTEGER, Y AS INTEGER
  41.     Radius = ABS(R)
  42.     RadiusError = -Radius
  43.     X = Radius
  44.     Y = 0
  45.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  46.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  47.     WHILE X > Y
  48.         RadiusError = RadiusError + Y * 2 + 1
  49.         IF RadiusError >= 0 THEN
  50.             IF X <> Y + 1 THEN
  51.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  52.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  53.             END IF
  54.             X = X - 1
  55.             RadiusError = RadiusError - X * 2
  56.         END IF
  57.         Y = Y + 1
  58.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  59.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  60.     WEND
  61.  

to complete the image a workaround may  be to join two specular images of that showed on the screen... but it is so complex near your fantastic linear math code!
Title: Re: Cresent Pattern Challenge from JB
Post by: bplus on June 28, 2019, 04:27:39 pm
Hi TempodiBasic,

It's difficult trying to fit coding in with job and sleep, I remember burning the candle from both ends in 1993 or so...


Anyway for your overlap problem try drawing 1/2 circles, arcs!, instead of full circles. Get one going right, then worry about wallpapering the screen with them.

And thanks for using your precious time for this crazy thing. :-)
Title: Re: Cresent Pattern Challenge from JB
Post by: TempodiBasic on June 28, 2019, 06:12:00 pm
@Bplus

Thanks

about
Quote
Anyway for your overlap problem try drawing 1/2 circles, arcs!, instead of full circles.
I cannot face  again with  PAINT and CIRCLE lacking color.... not now!
And I have no knownledge that CircleFill and its brothers can draw arches!
... or is there  no lacking color for halfcircle?
Instead to have an urticaria attack I left my keyboard and go walking with my dog before to go sleep!
See the next time. GoodNight
Title: Re: Cresent Pattern Challenge from JB
Post by: _vince on June 28, 2019, 08:29:21 pm
I found bplus's thread:
http://justbasiccom.proboards.com/thread/304/pattern-challenge?page=1&scrollTo=1804 (http://justbasiccom.proboards.com/thread/304/pattern-challenge?page=1&scrollTo=1804)

The original image is slightly different than bplus's and is easier to draw, technotitlick is on the right track, just needs some fine tuning.  I like bplus's better though, looks like calligraphy.

Since some of you are playing with rotating the swirls, one neat effect is to have each rotating at different speeds, cleverly chosen, for a nice hypnotic effect.
Title: Re: Cresent Pattern Challenge from JB
Post by: _vince on June 28, 2019, 08:40:15 pm
reminds me of geometry problems from school where you have to find unknown distances and angles in a partially labelled diagrams, fun exercise
Title: Re: Cresent Pattern Challenge from JB
Post by: bplus on June 28, 2019, 08:48:56 pm
I found bplus's thread:
http://justbasiccom.proboards.com/thread/304/pattern-challenge?page=1&scrollTo=1804 (http://justbasiccom.proboards.com/thread/304/pattern-challenge?page=1&scrollTo=1804)

The original image is slightly different than bplus's and is easier to draw, technotitlick is on the right track, just needs some fine tuning.  I like bplus's better though, looks like calligraphy.

Since some of you are playing with rotating the swirls, one neat effect is to have each rotating at different speeds, cleverly chosen, for a nice hypnotic effect.

Hi _vince,

The original image is easier to draw? The original image is a Hexagonal shape of twirls and at slight angle, which I imagine would be harder to replicate.
Title: Re: Cresent Pattern Challenge from JB
Post by: bplus on June 28, 2019, 08:54:13 pm
Hi TempodiBasic,

This must be what you are trying to say:
Code: QB64: [Select]
  1. _TITLE "Crescent Pattern by Half Circle Arcs"
  2. CONST xmax = 800, ymax = 600, pi = 3.14159265
  3. SCREEN _NEWIMAGE(xmax, ymax, 32)
  4.  
  5. crescent xmax / 2, ymax / 2, 50
  6.  
  7. SUB crescent (x0, y0, r6) 'r6 is radius of 6 crescent pattern
  8.     DIM a12, a, r1, x12, y12, stopa
  9.     r1 = r6 / 2 ' the radius of each crescent
  10.     a12 = 2 * pi / 12 ' 30 degrees to draw 12 arcs about x0, y0
  11.     FOR a = 0 TO 2 * pi STEP a12 'draw 12 arcs
  12.         'we need origin of the 12 arcs
  13.         x12 = x0 + r1 * COS(a)
  14.         y12 = y0 + r1 * SIN(a)
  15.         'arc start angle = a end angle = a + pi = 1/2 circle
  16.         IF a + pi > 2 * pi THEN
  17.             stopa = 2 * pi - (a + pi)
  18.             CIRCLE (x12, y12), r1, , a, 2 * pi '<<< as I've said before CIRCLE sub sucks!
  19.             CIRCLE (x12, y12), r1, , 0, stopa
  20.         ELSE
  21.             CIRCLE (x12, y12), r1, , a, a + pi
  22.         END IF
  23.     NEXT
  24.  

The operator of the CIRCLE command is probably partly to blame. :P
Title: Re: Cresent Pattern Challenge from JB
Post by: bplus on June 28, 2019, 08:59:09 pm
Never fear, B+ is here:
Code: QB64: [Select]
  1. _TITLE "Crescent Pattern by Half Circle Arcs"
  2. CONST xmax = 800, ymax = 600, pi = 3.14159265
  3. SCREEN _NEWIMAGE(xmax, ymax, 32)
  4.  
  5. crescent xmax / 2, ymax / 2, 50
  6.  
  7. SUB crescent (x0, y0, r6) 'r6 is radius of 6 crescent pattern
  8.     DIM a12, a, r1, x12, y12
  9.     r1 = r6 / 2 ' the radius of each crescent
  10.     a12 = 2 * pi / 12 ' 30 degrees to draw 12 arcs about x0, y0
  11.     FOR a = 0 TO 2 * pi STEP a12 'draw 12 arcs
  12.         'we need origin of the 12 arcs
  13.         x12 = x0 + r1 * COS(a)
  14.         y12 = y0 + r1 * SIN(a)
  15.         'arc start angle = a end angle = a + pi = 1/2 circle
  16.         arc x12, y12, r1, a, a + pi, &HFF0000FF
  17.     NEXT
  18.  
  19.  
  20. SUB arc (x, y, r, raStart, raStop, c AS _UNSIGNED LONG)
  21.     'x, y origin, r = radius, c = color
  22.  
  23.     'raStart is first angle clockwise from due East = 0 degrees
  24.     ' arc will start drawing there and clockwise until raStop angle reached
  25.  
  26.     DIM al, a
  27.     IF raStop < raStart THEN
  28.         arc x, y, r, raStart, _PI(2), c
  29.         arc x, y, r, 0, raStop, c
  30.     ELSE
  31.         ' modified to easier way suggested by Steve
  32.         'Why was the line method not good? I forgot.
  33.         al = _PI * r * r * (raStop - raStart) / _PI(2)
  34.         FOR a = raStart TO raStop STEP 1 / al
  35.             PSET (x + r * COS(a), y + r * SIN(a)), c
  36.         NEXT
  37.     END IF
  38.  

hmm... looks like we need arcs a little longer than half circles.  :o
Title: Re: Cresent Pattern Challenge from JB
Post by: bplus on June 28, 2019, 09:50:05 pm
Outline looks OK, the start angle is the outer point, I was thinking wrongly it was the end angle.
Code: QB64: [Select]
  1. _TITLE "Crescent Pattern by Half Circle Arcs"
  2. CONST xmax = 800, ymax = 600, pi = 3.14159265
  3. SCREEN _NEWIMAGE(xmax, ymax, 32)
  4.  
  5. crescent xmax / 2, ymax / 2, 50
  6.  
  7. SUB crescent (x0, y0, r6) 'r6 is radius of 6 crescent pattern
  8.     DIM a12, a, r1, x12, y12
  9.     r1 = r6 / 2 ' the radius of each crescent
  10.     a12 = 2 * pi / 12 ' 30 degrees to draw 12 arcs about x0, y0
  11.     FOR a = 0 TO 2 * pi STEP a12 'draw 12 arcs
  12.         'we need origin of the 12 arcs
  13.         x12 = x0 + r1 * COS(a)
  14.         y12 = y0 + r1 * SIN(a)
  15.         'arc start angle = a end angle = a + pi = 1/2 circle
  16.         arc x12, y12, r1, a - pi / 6, a + pi, &HFF0000FF '<<<<<<<<<<<<<<<<<<<<<<<<<<<<  start angle earlier
  17.     NEXT
  18.  
  19.  
  20. SUB arc (x, y, r, raStart, raStop, c AS _UNSIGNED LONG)
  21.     'x, y origin, r = radius, c = color
  22.  
  23.     'raStart is first angle clockwise from due East = 0 degrees
  24.     ' arc will start drawing there and clockwise until raStop angle reached
  25.  
  26.     DIM al, a
  27.     IF raStop < raStart THEN
  28.         arc x, y, r, raStart, _PI(2), c
  29.         arc x, y, r, 0, raStop, c
  30.     ELSE
  31.         ' modified to easier way suggested by Steve
  32.         'Why was the line method not good? I forgot.
  33.         al = _PI * r * r * (raStop - raStart) / _PI(2)
  34.         FOR a = raStart TO raStop STEP 1 / al
  35.             PSET (x + r * COS(a), y + r * SIN(a)), c
  36.         NEXT
  37.     END IF
  38.  
Title: Re: Cresent Pattern Challenge from JB
Post by: _vince on June 28, 2019, 10:00:25 pm
im on freebasic so ill just post the algorithm, but this one needed some manual fiddling, close enough for me

mine isnt pixel perfect for a few precision reasons, i challenge someone to perfectly reproduce the JB forum image, bonus points for antialiased edges
Code: [Select]
sw = 1920
sh = 1080

'fill in

xx = sw/2
yy = sh/2
a = pi/2 - pi/4 - pi/15 + 0.05 - 0.15
b = pi/6
c = 0.2
r = 100

for i = 0 to 5
x = xx + 2*r*cos(i*pi/3 + c)
y = yy + 2*r*sin(i*pi/3 + c)
for j = 0 to 5
p = x + 2*r*cos(j*pi/3 + c)
q = y + 2*r*sin(j*pi/3 + c)

rr = 1.03*r
for k = 0 to 5
u = k*pi/3 + a

circle (p + 0.5*rr*cos(u), q - 0.5*rr*sin(u)), 0.5*rr,, u+b, u+pi
circle (p + 0.5*rr*cos(u+ b), q - 0.5*rr*sin(u+ b)), 0.5*rr,, u, u+pi+b
'paint (p + 0.5*rr*cos(u+0.2), q - 0.5*rr*sin(u+0.2))
next
next
next

Title: Re: Cresent Pattern Challenge from JB
Post by: bplus on June 28, 2019, 10:43:59 pm
Looks good _vince!

I'm up to twirling:
Code: QB64: [Select]
  1. _TITLE "Crescent Pattern by Half Circle Arcs"
  2. CONST xmax = 800, ymax = 600, pi = 3.14159265
  3. SCREEN _NEWIMAGE(xmax, ymax, 32)
  4. DIM aof
  5. COLOR &HFF000000, &HFFFFFFFF
  6.     CLS
  7.     aof = aof + 4 * pi / 36
  8.     crescent xmax / 2, ymax / 2, 50, aof
  9.     _DISPLAY
  10.     _LIMIT 10
  11. SUB crescent (x0, y0, r6, aoff) 'r6 is radius of 6 crescent pattern
  12.     DIM a12, a, r1, x12, y12, i, px, py
  13.     r1 = r6 / 2 ' the radius of each crescent
  14.     a12 = 2 * pi / 12 ' 30 degrees to draw 12 arcs about x0, y0
  15.     FOR i = 0 TO 11 'draw 12 arcs
  16.         'we need origin of the 12 arcs
  17.         x12 = x0 + r1 * COS(i * a12 + aoff)
  18.         y12 = y0 + r1 * SIN(i * a12 + aoff)
  19.         'arc start angle = a end angle = a + pi = 1/2 circle
  20.         arc x12, y12, r1, i * a12 + aoff - pi / 6, i * a12 + aoff + pi, &HFFFFFFFE '<<<<<<<<<<<<<<<<<<<<<<<<<<<<  start angle earlier
  21.     NEXT
  22.     FOR i = 0 TO 11
  23.         IF i MOD 2 = 0 THEN
  24.             px = x0 + r1 * COS(i * a12 + aoff + pi / 12)
  25.             py = y0 + r1 * SIN(i * a12 + aoff + pi / 12)
  26.             'CIRCLE (px, py), 2 'test for paint
  27.             PAINT (px, py), &HFF000000, &HFFFFFFFE 'leaks try line arc
  28.         END IF
  29.     NEXT
  30.  
  31.  
  32. SUB arc (x, y, r, raStart, raStop, c AS _UNSIGNED LONG)
  33.     'x, y origin, r = radius, c = color
  34.  
  35.     'raStart is first angle clockwise from due East = 0 degrees
  36.     ' arc will start drawing there and clockwise until raStop angle reached
  37.  
  38.     DIM al, a
  39.     IF raStop < raStart THEN
  40.         arc x, y, r, raStart, _PI(2), c
  41.         arc x, y, r, 0, raStop, c
  42.     ELSE
  43.         ' modified to easier way suggested by Steve
  44.         'Why was the line method not good? I forgot.
  45.         al = _PI * r * r * (raStop - raStart) / _PI(2)
  46.         FOR a = raStart TO raStop STEP 1 / al
  47.             PSET (x + r * COS(a), y + r * SIN(a)), c
  48.         NEXT
  49.     END IF
  50.  
Title: Re: Cresent Pattern Challenge from JB
Post by: TempodiBasic on June 29, 2019, 05:03:00 am
@Bplus

thanks to translate my poor discussion
Quote
I cannot face  again with  PAINT and CIRCLE lacking color.... not now!
And I have no knownledge that CircleFill and its brothers can draw arches!
... or is there  no lacking color for halfcircle?

in code experience that others can have
Quote
Hi TempodiBasic,

This must be what you are trying to say:
OPTION _EXPLICIT
_TITLE "Crescent Pattern by Half Circle Arcs"
CONST xmax = 800, ymax = 600, pi = 3.14159265
SCREEN _NEWIMAGE(xmax, ymax, 32)
 
crescent xmax / 2, ymax / 2, 50
 
SUB crescent (x0, y0, r6) 'r6 is radius of 6 crescent pattern
    DIM a12, a, r1, x12, y12, stopa
    r1 = r6 / 2 ' the radius of each crescent
    a12 = 2 * pi / 12 ' 30 degrees to draw 12 arcs about x0, y0
    FOR a = 0 TO 2 * pi STEP a12 'draw 12 arcs
        'we need origin of the 12 arcs
        x12 = x0 + r1 * COS(a)
        y12 = y0 + r1 * SIN(a)
        'arc start angle = a end angle = a + pi = 1/2 circle
        IF a + pi > 2 * pi THEN
            stopa = 2 * pi - (a + pi)
            CIRCLE (x12, y12), r1, , a, 2 * pi '<<< as I've said before CIRCLE sub sucks!
            CIRCLE (x12, y12), r1, , 0, stopa
        ELSE
            CIRCLE (x12, y12), r1, , a, a + pi
        END IF
    NEXT
END SUB
 

However great I see that now we have a new function for toolbox section!  :-)

Code: QB64: [Select]
  1.  
  2. SUB arc (x, y, r, raStart, raStop, c AS _UNSIGNED LONG)
  3.     'x, y origin, r = radius, c = color
  4.  
  5.     'raStart is first angle clockwise from due East = 0 degrees
  6.     ' arc will start drawing there and clockwise until raStop angle reached
  7.  
  8.     DIM al, a
  9.     IF raStop < raStart THEN
  10.         arc x, y, r, raStart, _PI(2), c
  11.         arc x, y, r, 0, raStop, c
  12.     ELSE
  13.         ' modified to easier way suggested by Steve
  14.         'Why was the line method not good? I forgot.
  15.         al = _PI * r * r * (raStop - raStart) / _PI(2)
  16.         FOR a = raStart TO raStop STEP 1 / al
  17.             PSET (x + r * COS(a), y + r * SIN(a)), c
  18.         NEXT
  19.     END IF

Very cool boys and girls of QB64! Very very cool!
Title: Re: Cresent Pattern Challenge from JB
Post by: bplus on June 29, 2019, 11:12:10 am
TempodiBasic, you are not the only one confused by Drawing Arcs with CIRCLE. I learned Basic trig functions before using CIRCLE for Arcs and I find it hard to think backwards for CIRCLE command.

Why the CIRCLE command works Counter-Clockwise with the start and end angles is beyond me but it is inconsistent with all the Basic trig functions that go Clockwise around origin. It doesn't even make sense with the Y-axis increasing from due East 0 degrees or radians.

So yeah, if you need a Arc command that works consistently with the other Basic commands or functions put this Arc sub in your toolbox. It's even been reviewed by Steve. :-))

I think it always gets enough points to avoid leaks if you use the line as a border for PAINTing. Originally I used a line to connect the dots to assure no leaks (and you can do with less dots) but Steve did not like that one so I changed to just dots.

@Steve if you remember the reason, I wouldn't mind being reminded. :-)

Update: with twirling the patterns, they draw too slow to do a screen full of twirlers, so I will use Petr's method of snap shot images. I also like the shape of crescent pattern drawn originally, trailing edge is ellipse or ellipse like but not a circle arc or at least not a painted circular arc that leaves holes in middle and won't look right close to surrounding crescent patterns. Maybe I will try a line method to fill between leading and trailing edge of circular arcs first.
Title: Re: Cresent Pattern Challenge from JB
Post by: SMcNeill on June 29, 2019, 11:45:01 am
A different approach to this (I think; I haven't tried all the other demos fully, yet):

Code: [Select]
DEFLNG A-Z
SCREEN _NEWIMAGE(640, 480, 32)
DIM Colors(-1 TO 0)
Colors(-1) = &HFFFF0000 'Red
Colors(0) = &HFF0000FF 'Blue


FOR i = 0 TO 8
    k = NOT k
    x = 25 * SIN(_D2R(30 * i)) + 50
    y = 25 * COS(_D2R(30 * i)) + 50
    CIRCLE (x, y), 25, Colors(k)
    PAINT (x, y), Colors(k)
NEXT

halfimage = _NEWIMAGE(50, 100, 32)
_PUTIMAGE , 0, halfimage, (50, 0)-(100, 100)
fullimage = _NEWIMAGE(100, 100, 32)
_DEST fullimage
DisplayImage halfimage, 50, 0, 0, 1
DisplayImage halfimage, 0, 0, 180, 4
_DEST 0

CLS , Colors(-1)

DO
    angle = (angle + 1) MOD 360
    FOR y = -50 TO _HEIGHT + 50 STEP 82
        Insert = NOT Insert
        FOR x = -50 TO _WIDTH + 50 STEP 100
            DisplayImage fullimage, x + Insert * 50, y, angle, 0
        NEXT
    NEXT
    _LIMIT 120
    _DISPLAY
LOOP UNTIL _KEYHIT


SUB PlacePattern (Xwhere, Ywhere, WhichPattern)
    DisplayImage WhichPattern, Xwhere, Ywhere, 0, 1
    DisplayImage tempimage, Xwhere - 50, Ywhere, 180, 4
END SUB



SUB DisplayImage (Image AS LONG, x AS INTEGER, y AS INTEGER, angle AS SINGLE, mode AS _BYTE)
    'Image is the image handle which we use to reference our image.
    'x,y is the X/Y coordinates where we want the image to be at on the screen.
    'angle is the angle which we wish to rotate the image.
    'mode determines HOW we place the image at point X,Y.
    'Mode 0 we center the image at point X,Y
    'Mode 1 we place the Top Left corner of oour image at point X,Y
    'Mode 2 is Bottom Left
    'Mode 3 is Top Right
    'Mode 4 is Bottom Right


    DIM px(3) AS INTEGER, py(3) AS INTEGER, w AS INTEGER, h AS INTEGER
    DIM sinr AS SINGLE, cosr AS SINGLE, i AS _BYTE
    w = _WIDTH(Image): h = _HEIGHT(Image)
    SELECT CASE mode
        CASE 0 'center
            px(0) = -w \ 2: py(0) = -h \ 2: px(3) = w \ 2: py(3) = -h \ 2
            px(1) = -w \ 2: py(1) = h \ 2: px(2) = w \ 2: py(2) = h \ 2
        CASE 1 'top left
            px(0) = 0: py(0) = 0: px(3) = w: py(3) = 0
            px(1) = 0: py(1) = h: px(2) = w: py(2) = h
        CASE 2 'bottom left
            px(0) = 0: py(0) = -h: px(3) = w: py(3) = -h
            px(1) = 0: py(1) = 0: px(2) = w: py(2) = 0
        CASE 3 'top right
            px(0) = -w: py(0) = 0: px(3) = 0: py(3) = 0
            px(1) = -w: py(1) = h: px(2) = 0: py(2) = h
        CASE 4 'bottom right
            px(0) = -w: py(0) = -h: px(3) = 0: py(3) = -h
            px(1) = -w: py(1) = 0: px(2) = 0: py(2) = 0
    END SELECT
    sinr = SIN(angle / 57.2957795131): cosr = COS(angle / 57.2957795131)
    FOR i = 0 TO 3
        x2 = (px(i) * cosr + sinr * py(i)) + x: y2 = (py(i) * cosr - px(i) * sinr) + y
        px(i) = x2: py(i) = y2
    NEXT
    _MAPTRIANGLE (0, 0)-(0, h - 1)-(w - 1, h - 1), Image TO(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
    _MAPTRIANGLE (0, 0)-(w - 1, 0)-(w - 1, h - 1), Image TO(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
END SUB

Title: Re: Cresent Pattern Challenge from JB
Post by: SMcNeill on June 29, 2019, 11:51:27 am
And a slight mod to the above, to give the "cogs" directionality, so that they appear as if they'd actually be turning as we'd expect to see in a machine.

Code: [Select]
DEFLNG A-Z
SCREEN _NEWIMAGE(640, 480, 32)
DIM Colors(-1 TO 0)
Colors(-1) = &HFFFF0000 'Red
Colors(0) = &HFF0000FF 'Blue


FOR i = 0 TO 8
    k = NOT k
    x = 25 * SIN(_D2R(30 * i)) + 50
    y = 25 * COS(_D2R(30 * i)) + 50
    CIRCLE (x, y), 25, Colors(k)
    PAINT (x, y), Colors(k)
NEXT

halfimage = _NEWIMAGE(50, 100, 32)
_PUTIMAGE , 0, halfimage, (50, 0)-(100, 100)
fullimage = _NEWIMAGE(100, 100, 32)
_DEST fullimage
DisplayImage halfimage, 50, 0, 0, 1
DisplayImage halfimage, 0, 0, 180, 4
_DEST 0

CLS ', Colors(-1)

DO
    angle = (angle + 1) MOD 360
    FOR y = -50 TO _HEIGHT + 50 STEP 82
        Insert = NOT Insert
        IF Insert THEN direction = -1 ELSE direction = 1
        FOR x = -50 TO _WIDTH + 50 STEP 100
            DisplayImage fullimage, x + Insert * 50, y, direction * angle, 0
        NEXT
    NEXT
    _DISPLAY
LOOP UNTIL _KEYHIT


SUB PlacePattern (Xwhere, Ywhere, WhichPattern)
    DisplayImage WhichPattern, Xwhere, Ywhere, 0, 1
    DisplayImage tempimage, Xwhere - 50, Ywhere, 180, 4
END SUB



SUB DisplayImage (Image AS LONG, x AS INTEGER, y AS INTEGER, angle AS SINGLE, mode AS _BYTE)
    'Image is the image handle which we use to reference our image.
    'x,y is the X/Y coordinates where we want the image to be at on the screen.
    'angle is the angle which we wish to rotate the image.
    'mode determines HOW we place the image at point X,Y.
    'Mode 0 we center the image at point X,Y
    'Mode 1 we place the Top Left corner of oour image at point X,Y
    'Mode 2 is Bottom Left
    'Mode 3 is Top Right
    'Mode 4 is Bottom Right


    DIM px(3) AS INTEGER, py(3) AS INTEGER, w AS INTEGER, h AS INTEGER
    DIM sinr AS SINGLE, cosr AS SINGLE, i AS _BYTE
    w = _WIDTH(Image): h = _HEIGHT(Image)
    SELECT CASE mode
        CASE 0 'center
            px(0) = -w \ 2: py(0) = -h \ 2: px(3) = w \ 2: py(3) = -h \ 2
            px(1) = -w \ 2: py(1) = h \ 2: px(2) = w \ 2: py(2) = h \ 2
        CASE 1 'top left
            px(0) = 0: py(0) = 0: px(3) = w: py(3) = 0
            px(1) = 0: py(1) = h: px(2) = w: py(2) = h
        CASE 2 'bottom left
            px(0) = 0: py(0) = -h: px(3) = w: py(3) = -h
            px(1) = 0: py(1) = 0: px(2) = w: py(2) = 0
        CASE 3 'top right
            px(0) = -w: py(0) = 0: px(3) = 0: py(3) = 0
            px(1) = -w: py(1) = h: px(2) = 0: py(2) = h
        CASE 4 'bottom right
            px(0) = -w: py(0) = -h: px(3) = 0: py(3) = -h
            px(1) = -w: py(1) = 0: px(2) = 0: py(2) = 0
    END SELECT
    sinr = SIN(angle / 57.2957795131): cosr = COS(angle / 57.2957795131)
    FOR i = 0 TO 3
        x2 = (px(i) * cosr + sinr * py(i)) + x: y2 = (py(i) * cosr - px(i) * sinr) + y
        px(i) = x2: py(i) = y2
    NEXT
    _MAPTRIANGLE (0, 0)-(0, h - 1)-(w - 1, h - 1), Image TO(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
    _MAPTRIANGLE (0, 0)-(w - 1, 0)-(w - 1, h - 1), Image TO(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
END SUB
Title: Re: Cresent Pattern Challenge from JB
Post by: bplus on June 29, 2019, 12:57:42 pm
Hi Steve,

That is about the simplest, most direct, easy to understand (and math lazy) way to assemble a twirler yet, though I haven't studied Petr's or quite follow _vince method (even though I modified it to line fill method from PAINT).

I always thought a horizontal row of cogs would alternate in spinning, the way you have them packed I think they would not be able to spin at all (assuming they are all touching). ???


To all,

I did work out a line filled circular arc crescent pattern and it looks much better than the one filled with PAINT method, it might be judged too complex compared to Steve's method of rendering. Can he do tri-color twirlers?

Code: QB64: [Select]
  1. _TITLE "Crescent Line Filled Circle Arcs" 'b+ 2019-06-29
  2. CONST xmax = 800, ymax = 600, pi = 3.14159265
  3. SCREEN _NEWIMAGE(xmax, ymax, 32)
  4. DIM aof
  5. COLOR &HFF000000, &HFFFFFFFF
  6.     CLS
  7.     'aof = 0 'ALL Stop   to view fill: hey that's a darn good fill!!!!
  8.     aof = aof + pi / 18
  9.     crescentLFCA xmax / 2, ymax / 2, 50, aof
  10.     _DISPLAY
  11.     _LIMIT 30
  12. 'cresecent Line Filled Circular Arcs  combines arc drawing sub with crescentPattern sub
  13. SUB crescentLFCA (x0, y0, r6, aoff) 'r6 is radius of 6 crescent pattern
  14.     DIM a12, r1, a6, x6, y6, x6m12, y6m12, i, al, a, x1, y1, x2, y2, c~&
  15.     r1 = r6 / 2 ' the radius of each crescent
  16.     a12 = 2 * pi / 12 ' 30 degrees to draw 12 arcs about x0, y0
  17.     a6 = 2 * pi / 6
  18.     FOR i = 1 TO 6 'draw 6 crescents find x, y of leading and trailing edges
  19.         x6 = x0 + r1 * COS(i * a6 + aoff): y6 = y0 + r1 * SIN(i * a6 + aoff) 'origins of leading edges
  20.         x6m12 = x0 + r1 * COS(i * a6 - a12 + aoff): y6m12 = y0 + r1 * SIN(i * a6 - a12 + aoff) 'origins of trailing edges
  21.         al = _PI * r1 * r1 * (pi + pi / 6) / _PI(2)
  22.         FOR a = (i * a6 + aoff - pi / 6) TO (i * a6 + aoff + pi) STEP 1 / al 'draw arc chords for dist a
  23.             x1 = x6 + r1 * COS(a): y1 = y6 + r1 * SIN(a) ' point on leading edge
  24.             x2 = x6m12 + r1 * COS(a): y2 = y6m12 + r1 * SIN(a) 'eqivalent point on trailing edge
  25.             IF i MOD 3 = 0 THEN
  26.                 c~& = &HFF990000
  27.             ELSEIF i MOD 3 = 1 THEN
  28.                 c~& = &HFF008800
  29.             ELSEIF i MOD 3 = 2 THEN
  30.                 c~& = &HFF000099
  31.             END IF
  32.             LINE (x1, y1)-(x2, y2), c~&
  33.         NEXT
  34.     NEXT
  35.  

  [ This attachment cannot be displayed inline in 'Print Page' view ]  

Here is wallpaper version for tiny wall:
Code: QB64: [Select]
  1. _TITLE "Crescent Line Filled Circular Arcs Wallpaper"
  2. CONST xmax = 200, ymax = 240, pi = 3.14159265
  3. SCREEN _NEWIMAGE(xmax, ymax, 32)
  4. DIM aof, polyr, stepX, stepY, y, xoff, x
  5. polyr = 20
  6. stepX = polyr * 2 + 1
  7. stepY = polyr * 1 * SQR(3) + 1
  8. COLOR , &HFFFFFFFF
  9.     CLS
  10.     xoff = 0
  11.     FOR y = polyr / 2 TO ymax - polyr / 2 STEP stepY
  12.         xoff = (xoff + 1) MOD 2
  13.         FOR x = 0 TO xmax + 7 * polyr STEP stepX
  14.             crescentLFCA x - xoff * 1.5 * stepX, y, polyr, aof
  15.         NEXT
  16.     NEXT
  17.     aof = aof + pi / 36
  18.     _DISPLAY
  19.     _LIMIT 200
  20.  
  21. 'cresecent Line Filled Circular Arcs  combines arc drawing sub with crescentPattern sub
  22. SUB crescentLFCA (x0, y0, r6, aoff) 'r6 is radius of 6 crescent pattern
  23.     DIM a12, r1, a6, x6, y6, x6m12, y6m12, i, al, a, x1, y1, x2, y2, c~&
  24.     r1 = r6 / 2 ' the radius of each crescent
  25.     a12 = 2 * pi / 12 ' 30 degrees to draw 12 arcs about x0, y0
  26.     a6 = 2 * pi / 6
  27.     FOR i = 1 TO 6 'draw 6 crescents find x, y of leading and trailing edges
  28.         x6 = x0 + r1 * COS(i * a6 + aoff): y6 = y0 + r1 * SIN(i * a6 + aoff) 'origins of leading edges
  29.         x6m12 = x0 + r1 * COS(i * a6 - a12 + aoff): y6m12 = y0 + r1 * SIN(i * a6 - a12 + aoff) 'origins of trailing edges
  30.         al = _PI * r1 * r1 * (pi + pi / 6) / _PI(2)
  31.         FOR a = (i * a6 + aoff - pi / 6) TO (i * a6 + aoff + pi) STEP 1 / al 'draw arc chords for dist a
  32.             x1 = x6 + r1 * COS(a): y1 = y6 + r1 * SIN(a) ' point on leading edge
  33.             x2 = x6m12 + r1 * COS(a): y2 = y6m12 + r1 * SIN(a) 'eqivalent point on trailing edge
  34.             IF i MOD 3 = 0 THEN
  35.                 c~& = &HFF990000
  36.             ELSEIF i MOD 3 = 1 THEN
  37.                 c~& = &HFF008800
  38.             ELSEIF i MOD 3 = 2 THEN
  39.                 c~& = &HFF000099
  40.             END IF
  41.             LINE (x1, y1)-(x2, y2), c~&
  42.         NEXT
  43.     NEXT
  44.  
Title: Re: Cresent Pattern Challenge from JB
Post by: SMcNeill on June 29, 2019, 01:12:19 pm
Hi Steve,

That is about the simplest, most direct, easy to understand (and math lazy) way to assemble a twirler yet, though I haven't studied Petr's or quite follow _vince method (even though I modified it to line fill method from PAINT).

I always thought a horizontal row of cogs would alternate in spinning, the way you have them packed I think they would not be able to spin at all (assuming they are all touching). ???


To all,

I did work out a line filled circular arc crescent pattern and it looks much better than the one filled with PAINT method, it might be judged too complex compared to Steve's method of rendering. Can he do tri-color twirlers?

Looking at these, they appear to me to be more like designs on the edge of a wheel, than they do to be actual gears.  As such, the idea that each row would rotate in an opposite direction is rather quite natural (at least to my way of thinking).  The first row of "wheels" all rotate to the right, and the row under them would rotate to the left, with the next row rotating back to the right -- which is why I coded it the way I have.

As for using multiple colors, that's an easy modification as well:

Code: [Select]
DEFLNG A-Z
SCREEN _NEWIMAGE(640, 480, 32)
DIM Colors(3)
Colors(0) = &HFFFF0000 'Red
Colors(1) = &HFF0000FF 'Blue
Colors(2) = &HFF00FF00 'Green
Colors(3) = &HFFF0F00F 'Something... I just made up a value!

FOR i = 0 TO 8
    k = i MOD 4
    x = 25 * SIN(_D2R(30 * i)) + 50
    y = 25 * COS(_D2R(30 * i)) + 50
    CIRCLE (x, y), 25, Colors(k)
    PAINT (x, y), Colors(k)
NEXT

halfimage = _NEWIMAGE(50, 100, 32)
_PUTIMAGE , 0, halfimage, (50, 0)-(100, 100)
fullimage = _NEWIMAGE(100, 100, 32)
_DEST fullimage
DisplayImage halfimage, 50, 0, 0, 1
DisplayImage halfimage, 0, 0, 180, 4
_DEST 0

CLS ', Colors(-1)

DO
    angle = (angle + 1) MOD 360
    FOR y = -50 TO _HEIGHT + 50 STEP 82
        Insert = NOT Insert
        IF Insert THEN direction = -1 ELSE direction = 1
        FOR x = -50 TO _WIDTH + 50 STEP 100
            DisplayImage fullimage, x + Insert * 50, y, direction * angle, 0
        NEXT
    NEXT
    _DISPLAY
LOOP UNTIL _KEYHIT


SUB PlacePattern (Xwhere, Ywhere, WhichPattern)
    DisplayImage WhichPattern, Xwhere, Ywhere, 0, 1
    DisplayImage tempimage, Xwhere - 50, Ywhere, 180, 4
END SUB



SUB DisplayImage (Image AS LONG, x AS INTEGER, y AS INTEGER, angle AS SINGLE, mode AS _BYTE)
    'Image is the image handle which we use to reference our image.
    'x,y is the X/Y coordinates where we want the image to be at on the screen.
    'angle is the angle which we wish to rotate the image.
    'mode determines HOW we place the image at point X,Y.
    'Mode 0 we center the image at point X,Y
    'Mode 1 we place the Top Left corner of oour image at point X,Y
    'Mode 2 is Bottom Left
    'Mode 3 is Top Right
    'Mode 4 is Bottom Right


    DIM px(3) AS INTEGER, py(3) AS INTEGER, w AS INTEGER, h AS INTEGER
    DIM sinr AS SINGLE, cosr AS SINGLE, i AS _BYTE
    w = _WIDTH(Image): h = _HEIGHT(Image)
    SELECT CASE mode
        CASE 0 'center
            px(0) = -w \ 2: py(0) = -h \ 2: px(3) = w \ 2: py(3) = -h \ 2
            px(1) = -w \ 2: py(1) = h \ 2: px(2) = w \ 2: py(2) = h \ 2
        CASE 1 'top left
            px(0) = 0: py(0) = 0: px(3) = w: py(3) = 0
            px(1) = 0: py(1) = h: px(2) = w: py(2) = h
        CASE 2 'bottom left
            px(0) = 0: py(0) = -h: px(3) = w: py(3) = -h
            px(1) = 0: py(1) = 0: px(2) = w: py(2) = 0
        CASE 3 'top right
            px(0) = -w: py(0) = 0: px(3) = 0: py(3) = 0
            px(1) = -w: py(1) = h: px(2) = 0: py(2) = h
        CASE 4 'bottom right
            px(0) = -w: py(0) = -h: px(3) = 0: py(3) = -h
            px(1) = -w: py(1) = 0: px(2) = 0: py(2) = 0
    END SELECT
    sinr = SIN(angle / 57.2957795131): cosr = COS(angle / 57.2957795131)
    FOR i = 0 TO 3
        x2 = (px(i) * cosr + sinr * py(i)) + x: y2 = (py(i) * cosr - px(i) * sinr) + y
        px(i) = x2: py(i) = y2
    NEXT
    _MAPTRIANGLE (0, 0)-(0, h - 1)-(w - 1, h - 1), Image TO(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
    _MAPTRIANGLE (0, 0)-(w - 1, 0)-(w - 1, h - 1), Image TO(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
END SUB

The above has a real pretty little FOUR color pattern, which (I think, at least) helps to showcase the directional spin on our wheels.  ;)
Title: Re: Cresent Pattern Challenge from JB
Post by: Petr on June 29, 2019, 02:57:38 pm
I apologize in advance for the fact that this is only partially related to the topic. How to rotate the image - My frame method is memory -intensive as I have shown them. Turning with Steve's method in turn consumes a small amount of power. The worst method is direct rotation and direct rendering of everything at once. It depends on the particular program, when it fits best.
With both rotation method and with SaveImage can every from us easy sprite image files to do. If you set rotation center to correct place, you can rotate just piece of image  for example, just the character's hand, but not the whole character....

Bplus here hidden draw galaxy...



Code: [Select]
OPTION _EXPLICIT
_TITLE "Crescent Line Filled Circle Arcs" 'b+ 2019-06-29
CONST xmax = 800, ymax = 600, pi = 3.14159265
DIM aof
DIM Frames(35) AS LONG, CreateFrames AS INTEGER, X AS SINGLE, Z AS SINGLE, angle AS SINGLE, height AS SINGLE, f AS _BYTE

FOR CreateFrames = 0 TO 35
    Frames(CreateFrames) = _NEWIMAGE(101, 101, 32)
    _DEST Frames(CreateFrames)
    CLS
    'aof = 0 'ALL Stop   to view fill: hey that's a darn good fill!!!!
    aof = aof + pi / 18
    crescentLFCA 50, 50, 50, aof
    _CLEARCOLOR &HFF000000
NEXT
_DEST 0
transform Frames()


_DISPLAYORDER _SOFTWARE , _HARDWARE

DO
    Circled X, Z, angle, 1.3
    angle = angle + .01

    FOR height = 1.2 - Z TO 1.2 - Z + .1 STEP .01 'this is BAD METHOD, because i am too lasy. For best power muss be next segment defined and draw between segment A and segment B with MAPTRIANGLE.
        view3D 0 + X, height, -4 + Z, Frames(), f
    NEXT

    LOCATE 1, 1: PRINT "BPlus created color galaxy!"
    _DISPLAY
    f = f - 1: IF f < LBOUND(frames) THEN f = UBOUND(frames)
    _LIMIT 20
LOOP
'cresecent Line Filled Circular Arcs  combines arc drawing sub with crescentPattern sub
SUB crescentLFCA (x0, y0, r6, aoff) 'r6 is radius of 6 crescent pattern
    DIM a12, r1, a6, x6, y6, x6m12, y6m12, i, al, a, x1, y1, x2, y2, c~&
    r1 = r6 / 2 ' the radius of each crescent
    a12 = 2 * pi / 12 ' 30 degrees to draw 12 arcs about x0, y0
    a6 = 2 * pi / 6
    FOR i = 1 TO 6 'draw 6 crescents find x, y of leading and trailing edges
        x6 = x0 + r1 * COS(i * a6 + aoff): y6 = y0 + r1 * SIN(i * a6 + aoff) 'origins of leading edges
        x6m12 = x0 + r1 * COS(i * a6 - a12 + aoff): y6m12 = y0 + r1 * SIN(i * a6 - a12 + aoff) 'origins of trailing edges
        al = _PI * r1 * r1 * (pi + pi / 6) / _PI(2)
        FOR a = (i * a6 + aoff - pi / 6) TO (i * a6 + aoff + pi) STEP 1 / al 'draw arc chords for dist a
            x1 = x6 + r1 * COS(a): y1 = y6 + r1 * SIN(a) ' point on leading edge
            x2 = x6m12 + r1 * COS(a): y2 = y6m12 + r1 * SIN(a) 'eqivalent point on trailing edge
            IF i MOD 3 = 0 THEN
                c~& = &HFF990000
            ELSEIF i MOD 3 = 1 THEN
                c~& = &HFF008800
            ELSEIF i MOD 3 = 2 THEN
                c~& = &HFF000099
            END IF
            LINE (x1, y1)-(x2, y2), c~&
        NEXT
    NEXT
END SUB

SUB transform (arr() AS LONG)
    DIM t AS INTEGER, img32 AS LONG
    FOR t = LBOUND(arr) TO UBOUND(arr)
        img32 = _COPYIMAGE(arr(t))
        arr(t) = _COPYIMAGE(img32, 33)
        _FREEIMAGE img32
    NEXT
END SUB

SUB view3D (x AS SINGLE, y AS SINGLE, z AS SINGLE, arr() AS LONG, frameNR AS INTEGER)
    DIM w AS INTEGER, h AS INTEGER, width3d AS _BYTE, height3d AS _BYTE, depth3d AS _BYTE

    w = _WIDTH(arr(frameNR))
    h = _HEIGHT(arr(frameNR))

    width3d = 1
    height3d = 1
    depth3d = 1

    _MAPTRIANGLE (0, 0)-(w, 0)-(0, h), arr(frameNR) TO(x - width3d, y - height3d, z - 3 * depth3d)-(x + width3d, y - height3d, z - 3 * depth3d)-(x - width3d, y - height3d, z + 3 * depth3d)
    _MAPTRIANGLE (w, 0)-(0, h)-(w, h), arr(frameNR) TO(x + width3d, y - height3d, z - 3 * depth3d)-(x - width3d, y - height3d, z + 3 * depth3d)-(x + width3d, y - height3d, z + 3 * depth3d)
END SUB

SUB Circled (GetX, GetZ, angle, radius)
    GetX = SIN(angle) * radius
    GetZ = COS(angle) * radius
END SUB
Title: Re: Cresent Pattern Challenge from JB
Post by: bplus on June 29, 2019, 04:29:57 pm
Thanks Petr for taking code to a higher place :D

Eye Champagne:
Code: QB64: [Select]
  1. _TITLE "Cresent Pattern in Cog Layout" 'b+ 2019-06-29 using part of Petr's mod and Steve's cog idea, I mod again
  2. CONST xmax = 800, ymax = 600, pi = 3.14159265
  3. SCREEN _NEWIMAGE(xmax, ymax, 32)
  4. _SCREENMOVE 300, 40
  5. DIM SHARED clr, r, g, b
  6. DIM Frames(35) AS LONG, CreateFrames AS INTEGER, x, y, aof, f AS INTEGER, yAlt, xAlt, i
  7.  
  8. FOR CreateFrames = 0 TO 35
  9.     Frames(CreateFrames) = _NEWIMAGE(101, 101, 32)
  10.     _DEST Frames(CreateFrames)
  11.     CLS
  12.     'aof = 0 'ALL Stop   to view fill: hey that's a darn good fill!!!!
  13.     aof = aof + pi / 18
  14.     crescentLFCA 50, 50, 50, aof
  15.     _CLEARCOLOR &HFF000000
  16.  
  17. COLOR , &HFFFFFFFF
  18.     FOR i = 0 TO xmax
  19.         chColor
  20.         LINE (i, 0)-(i, ymax)
  21.     NEXT
  22.     f = (f + 1) MOD 36
  23.     FOR y = 0 TO ymax - 100 STEP 100
  24.         yAlt = (yAlt + 1) MOD 2
  25.         xAlt = yAlt
  26.         FOR x = 0 TO xmax - 100 STEP 200
  27.             IF xAlt THEN
  28.                 _PUTIMAGE (x, y)-STEP(100, 100), Frames(f), 0, (0, 0)-(100, 100)
  29.                 _PUTIMAGE (x + 100, y)-STEP(100, 100), Frames(f), 0, (100, 0)-(0, 100)
  30.             ELSE
  31.                 _PUTIMAGE (x, y)-STEP(100, 100), Frames(f), 0, (100, 0)-(0, 100)
  32.                 _PUTIMAGE (x + 100, y)-STEP(100, 100), Frames(f), 0, (0, 0)-(100, 100)
  33.             END IF
  34.         NEXT
  35.     NEXT
  36.     _DISPLAY
  37.     _LIMIT 10
  38.  
  39. 'cresecent Line Filled Circular Arcs  combines arc drawing sub with crescentPattern sub
  40. SUB crescentLFCA (x0, y0, r6, aoff) 'r6 is radius of 6 crescent pattern
  41.     DIM a12, r1, a6, x6, y6, x6m12, y6m12, i, al, a, x1, y1, x2, y2, c~&
  42.     r1 = r6 / 2 ' the radius of each crescent
  43.     a12 = 2 * pi / 12 ' 30 degrees to draw 12 arcs about x0, y0
  44.     a6 = 2 * pi / 6
  45.     al = _PI * r1 * r1 * (pi + pi / 6) / _PI(2) '<<<<<<<<<<<<<<<< this needs to be calc only once
  46.     FOR i = 1 TO 6 'draw 6 crescents find x, y of leading and trailing edges
  47.         x6 = x0 + r1 * COS(i * a6 + aoff): y6 = y0 + r1 * SIN(i * a6 + aoff) 'origins of leading edges
  48.         x6m12 = x0 + r1 * COS(i * a6 - a12 + aoff): y6m12 = y0 + r1 * SIN(i * a6 - a12 + aoff) 'origins of trailing edges
  49.         FOR a = (i * a6 + aoff - pi / 6) TO (i * a6 + aoff + pi) STEP 1 / al 'draw arc chords for dist a
  50.             x1 = x6 + r1 * COS(a): y1 = y6 + r1 * SIN(a) ' point on leading edge
  51.             x2 = x6m12 + r1 * COS(a): y2 = y6m12 + r1 * SIN(a) 'eqivalent point on trailing edge
  52.             IF i MOD 3 = 0 THEN
  53.                 c~& = &HFF990000
  54.             ELSEIF i MOD 3 = 1 THEN
  55.                 c~& = &HFF008800
  56.             ELSEIF i MOD 3 = 2 THEN
  57.                 c~& = &HFF000099
  58.             END IF
  59.             LINE (x1, y1)-(x2, y2), c~&
  60.         NEXT
  61.     NEXT
  62.  
  63. SUB chColor ()
  64.     IF r = 0 THEN r = RND * 255
  65.     IF g = 0 THEN g = RND * 255
  66.     IF b = 0 THEN b = RND * 255
  67.     clr = clr + .3
  68.     COLOR _RGB32(127 + 127 * SIN(r * clr), 127 + 127 * SIN(g * clr), 127 + 127 * SIN(b * clr))
  69.     IF clr > 40000 THEN r = RND: g = RND: b = RND: clr = 0
  70.  
  71.  
Title: Re: Cresent Pattern Challenge from JB
Post by: bplus on June 29, 2019, 07:52:13 pm
Hi _vince,

I got as far as I could translating your algo to QB64. First I had to cut down screen size and scale radius.
Then replace CIRCLE commands with my Arc code because kept getting illegal calls with CIRCLE.
Then to get a decent draw I had to change sign on y coordinate as noted below.
OK got a hexagonal shape of twirls but! they are misaligned a bit, the crescents are at wrong angles for nice draw.
Then go to PAINT and the PAINT points all fit in crescents but the first is drawn outside the crescent drawn causing paint to paint entire the screen.

I think there is just one angle that needs fixing so everything lines up correctly.

Code: QB64: [Select]
  1. _TITLE "Cresent Pattern in Hexagon Layout" 'b+ translated algo 2019-06-29
  2.  
  3. CONST sw = 1068, sh = 600, pi = 3.14159265
  4. SCREEN _NEWIMAGE(sw, sh, 32)
  5. _SCREENMOVE 300, 40
  6.  
  7. 'sw = 1920     ' 1.78 ratio 600 X 1.78 = 1068
  8. 'sh = 1080
  9.  
  10. 'fill in
  11. DIM xx, yy, a, b, c, r, i AS INTEGER, x, y, j AS INTEGER, p, q, rr, k AS INTEGER, u
  12.  
  13. xx = sw / 2
  14. yy = sh / 2
  15. a = pi / 2 - pi / 4 - pi / 15 + 0.05 - 0.15
  16. b = pi / 6
  17. c = 0.2
  18. r = 100 / 1.78
  19.  
  20. FOR i = 0 TO 5
  21.     x = xx + 2 * r * COS(i * pi / 3 + c)
  22.     y = yy + 2 * r * SIN(i * pi / 3 + c)
  23.     FOR j = 0 TO 5
  24.         p = x + 2 * r * COS(j * pi / 3 + c)
  25.         q = y + 2 * r * SIN(j * pi / 3 + c)
  26.  
  27.         rr = 1.03 * r
  28.         FOR k = 0 TO 5
  29.             u = k * pi / 3 + a
  30.  
  31.             ' In next lines I change  y coordinate  q - ... to q + ... or get crap!
  32.             arc p + 0.5 * rr * COS(u), q + 0.5 * rr * SIN(u), 0.5 * rr, u + b, u + pi, &HFF0000FF
  33.             arc p + 0.5 * rr * COS(u + b), q + 0.5 * rr * SIN(u + b), 0.5 * rr, u, u + pi + b, &HFF0000FF
  34.  
  35.             'test paint points oops they are all outside the last drawn crescent!
  36.             CIRCLE (p + 0.5 * rr * COS(u + 0.2), q + 0.5 * rr * SIN(u + 0.2)), 2 'test point
  37.             'PAINT (p + 0.5 * rr * COS(u + 0.2), q + 0.5 * rr * SIN(u + 0.2)), &HFFFFFFFF, &HFF0000FF
  38.             _DELAY 2
  39.  
  40.  
  41.         NEXT
  42.     NEXT
  43.  
  44. SUB arc (x, y, r, raStart, raStop, c AS _UNSIGNED LONG)
  45.     'x, y origin, r = radius, c = color
  46.  
  47.     'raStart is first angle clockwise from due East = 0 degrees
  48.     ' arc will start drawing there and clockwise until raStop angle reached
  49.  
  50.     DIM al, a
  51.     IF raStop < raStart THEN
  52.         arc x, y, r, raStart, _PI(2), c
  53.         arc x, y, r, 0, raStop, c
  54.     ELSE
  55.         ' modified to easier way suggested by Steve
  56.         'Why was the line method not good? I forgot.
  57.         al = _PI * r * r * (raStop - raStart) / _PI(2)
  58.         FOR a = raStart TO raStop STEP 1 / al
  59.             PSET (x + r * COS(a), y + r * SIN(a)), c
  60.         NEXT
  61.     END IF
  62.  

I think you can find the angle faster than I.

This gave me idea how to layout a Hexagon pattern though! :-)
Title: Re: Cresent Pattern Challenge from JB
Post by: bplus on June 29, 2019, 10:46:45 pm
OK Tricolor Crescent Pattern on slightly tilted Hexagonal Layout:

Code: QB64: [Select]
  1. _TITLE "Crescent LFCA Hexagonal Layout" 'b+ 2019-06-29   LFCA = Lined Filled Circular Arcs
  2. CONST xmax = 800, ymax = 600, pi = 3.14159265
  3. SCREEN _NEWIMAGE(xmax, ymax, 32)
  4.  
  5. TYPE xy
  6.     x AS INTEGER
  7.     y AS INTEGER
  8. DIM h(45) AS xy, tilt, hex, x0, y0, a, i, r, j, k, cnt
  9. r = 50
  10. tilt = -pi / 8 'looks to match original challenge
  11. hex = 2 * pi / 6
  12. x0 = xmax / 2
  13. y0 = ymax / 2
  14. FOR a = tilt TO 2 * pi STEP hex
  15.     h(i).x = x0 + 2 * r * COS(a)
  16.     h(i).y = y0 + 2 * r * SIN(a)
  17.     i = i + 1
  18. FOR k = 0 TO i - 1
  19.     'PRINT k, h(k).x, h(k).y
  20.     CIRCLE (h(k).x, h(k).y), 2
  21. FOR j = 0 TO 5
  22.     FOR a = tilt TO 2 * pi - tilt - 1 STEP hex
  23.         h(i).x = h(j).x + 2 * r * COS(a)
  24.         h(i).y = h(j).y + 2 * r * SIN(a)
  25.         'PRINT i, h(i).x, h(i).y
  26.         CIRCLE (h(i).x, h(i).y), 4
  27.         i = i + 1
  28.     NEXT
  29. i = i - 1
  30. FOR j = 0 TO i - 1
  31.     FOR k = j + 1 TO i
  32.         IF h(j).x THEN
  33.             IF h(j).x = h(k).x AND h(j).y = h(k).y THEN h(k).x = 0
  34.         END IF
  35.     NEXT
  36. COLOR , &HFFFFFFFF
  37. FOR j = 0 TO i
  38.     IF h(j).x <> 0 THEN cnt = cnt + 1: PRINT h(j).x, h(j).y: crescentLFCA h(j).x, h(j).y, r, -3 * tilt
  39. PRINT "n pts = "; cnt
  40.  
  41. 'cresecent Line Filled Circular Arcs  combines arc drawing sub with crescentPattern sub
  42. SUB crescentLFCA (x0, y0, r6, aoff) 'r6 is radius of 6 crescent pattern
  43.     DIM a12, r1, a6, x6, y6, x6m12, y6m12, i, al, a, x1, y1, x2, y2, c~&
  44.     r1 = r6 / 2 ' the radius of each crescent
  45.     a12 = 2 * pi / 12 ' 30 degrees to draw 12 arcs about x0, y0
  46.     a6 = 2 * pi / 6
  47.     al = 10 * _PI * r1 * r1 * (pi + pi / 6) / _PI(2)
  48.     FOR i = 1 TO 6 'draw 6 crescents find x, y of leading and trailing edges
  49.         x6 = x0 + r1 * COS(i * a6 + aoff): y6 = y0 + r1 * SIN(i * a6 + aoff) 'origins of leading edges
  50.         x6m12 = x0 + r1 * COS(i * a6 - a12 + aoff): y6m12 = y0 + r1 * SIN(i * a6 - a12 + aoff) 'origins of trailing edges
  51.         FOR a = (i * a6 + aoff - pi / 6) TO (i * a6 + aoff + pi) STEP 1 / al 'draw arc chords for dist a
  52.             x1 = x6 + r1 * COS(a): y1 = y6 + r1 * SIN(a) ' point on leading edge
  53.             x2 = x6m12 + r1 * COS(a): y2 = y6m12 + r1 * SIN(a) 'eqivalent point on trailing edge
  54.             IF i MOD 3 = 0 THEN
  55.                 c~& = &HFF990000
  56.             ELSEIF i MOD 3 = 1 THEN
  57.                 c~& = &HFF008800
  58.             ELSEIF i MOD 3 = 2 THEN
  59.                 c~& = &HFF000099
  60.             END IF
  61.             LINE (x1, y1)-(x2, y2), c~&
  62.         NEXT
  63.     NEXT
  64.  

The angles of tilt were eyeballed but turns out it was about -pi/8 then I had to turn the crescent patterns until they matched up at the nice round number of -3*tilt.
Title: Re: Cresent Pattern Challenge from JB
Post by: _vince on June 30, 2019, 08:36:16 pm
Nice work bplus, that's pretty much it.  I think the way the original image has them interconnected is by giving the arcs a radius slightly larger than half the radius of the invisible circle within which they're embedded, which explains the rr = 1.01*r line in my code but in yours it looks like you connected them with a thin rectangle.  Anyways, I think we've beaten this pattern to death, lets find more!