Author Topic: One more pattern challenge  (Read 7567 times)

0 Members and 1 Guest are viewing this topic.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: One more pattern challenge
« Reply #30 on: July 08, 2019, 01:33:55 pm »
The original post was just a pattern challenge, but then Petr comes along and posts that dog collar thingy... with text! That got me hooked.  I wanted to figure out how to modify the statements to allow for a longer message, which I accomplished, because as you all know, I'm text challenged!

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: One more pattern challenge
« Reply #31 on: July 08, 2019, 04:37:08 pm »
Hi Pete,

Apparently I am overlap challenged :D

It is a nice bit of code you've worked out.

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: One more pattern challenge
« Reply #32 on: July 08, 2019, 05:33:26 pm »
I came real, real close.... if a black screen could be considered close. ;)

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: One more pattern challenge
« Reply #33 on: July 08, 2019, 05:44:17 pm »
I came real, real close.... if a black screen could be considered close. ;)

Why not?

After all, Windows considered a blue screen to be a working product...
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: One more pattern challenge
« Reply #34 on: July 08, 2019, 07:47:26 pm »
I could not give up on overlap thing, got it now I think. The speedy DoubleRing did not work for pixel precision so back to old and even slower method (found a few holes):
Code: QB64: [Select]
  1. _TITLE "One More Pattern Challenge matching Steves" 'bplus 2019-07-08
  2. CONST xmax = 800, ymax = 760, PI = 3.141592653589793
  3. SCREEN _NEWIMAGE(xmax, ymax, 32)
  4. DIM x, y, offset, side, n, i, pAngle, lastx, lasty, r, midx, midy, x0, y0, toggle
  5. pallet(3) = &HFFFFD700: pallet(4) = &HFFC0C0C0: pallet(5) = &HFFFF0000
  6. pallet(6) = &HFFFFFFFF: pallet(7) = &HFF0000FF
  7. FOR x = xmax TO 0 STEP -200
  8.     offset = toggle * 200
  9.     FOR y = 0 TO ymax + 200 STEP 400
  10.         ring x, y + offset, 200, 195
  11.         side = 193
  12.         FOR n = 3 TO 7
  13.             pAngle = 2 * PI / n
  14.             FOR i = 0 TO n + 1
  15.                 x0 = x + side * COS(i * pAngle + PI / 2)
  16.                 y0 = y + offset + side * SIN(i * pAngle + PI / 2)
  17.                 IF i > 1 THEN
  18.                     drawLink lastx, lasty, 2.5, x0, y0, 2.5, pallet(n)
  19.                     midx = (x0 + lastx) / 2: midy = (y0 + lasty) / 2
  20.                 END IF
  21.                 lastx = x0: lasty = y0
  22.             NEXT
  23.             r = ((midx - x) ^ 2 + (midy - (y + offset)) ^ 2) ^ .5 - 3.5
  24.             IF n < 7 THEN ring x, y + offset, r, r - 5
  25.             side = r - 9
  26.         NEXT
  27.     NEXT
  28.     toggle = (toggle + 1) MOD 2
  29.  
  30. SUB ring (x, y, outerR, innerR)
  31.     DIM pm2, pd3, pd6, a, x1, y1, x2, y2, c AS _UNSIGNED LONG
  32.     pm2 = PI * 2: pd3 = PI / 3: pd6 = pd3 / 2 'pd6 aligns red at bottom cyan at top, nice Steve!
  33.     FOR a = 0 TO pm2 STEP .00001 ' <<<<<<<<<<<< increased, still finding holes
  34.         x1 = x + outerR * COS(a - pd6): y1 = y + outerR * SIN(a - pd6)
  35.         x2 = x + innerR * COS(a - pd6): y2 = y + innerR * SIN(a - pd6)
  36.         IF a < pd3 THEN
  37.             c = _RGB32(255 * a / pd3, 255, 0)
  38.         ELSEIF a < 2 * pd3 THEN
  39.             c = _RGB32(255, 255 - 255 * (a - pd3) / pd3, 0)
  40.         ELSEIF a < 3 * pd3 THEN
  41.             c = _RGB32(255, 0, 255 * (a - 2 * pd3) / pd3)
  42.         ELSEIF a < 4 * pd3 THEN
  43.             c = _RGB32(255 - 255 * (a - 3 * pd3) / pd3, 0, 255)
  44.         ELSEIF a < 5 * pd3 THEN
  45.             c = _RGB32(0, 255 * (a - 4 * pd3) / pd3, 255)
  46.         ELSE
  47.             c = _RGB32(0, 255, 255 - 255 * (a - 5 * pd3) / pd3)
  48.         END IF
  49.         LINE (x1, y1)-(x2, y2), c
  50.     NEXT
  51.  
  52. SUB drawLink (x1, y1, r1, x2, y2, r2, c AS _UNSIGNED LONG)
  53.     DIM a, a1, a2, x3, x4, x5, x6, y3, y4, y5, y6
  54.     a = _ATAN2(y2 - y1, x2 - x1)
  55.     a1 = a + _PI(1 / 2): a2 = a - _PI(1 / 2)
  56.     x3 = x1 + r1 * COS(a1): y3 = y1 + r1 * SIN(a1)
  57.     x4 = x1 + r1 * COS(a2): y4 = y1 + r1 * SIN(a2)
  58.     x5 = x2 + r2 * COS(a1): y5 = y2 + r2 * SIN(a1)
  59.     x6 = x2 + r2 * COS(a2): y6 = y2 + r2 * SIN(a2)
  60.     ftri x3, y3, x4, y4, x6, y6, c
  61.     ftri x5, y5, x6, y6, x3, y3, c
  62.     fcirc x1, y1, r1, c: fcirc x2, y2, r2, c
  63.  
  64. SUB ftri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  65.     DIM a&
  66.     a& = _NEWIMAGE(1, 1, 32)
  67.     _DEST a&
  68.     PSET (0, 0), K
  69.     _DEST 0
  70.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  71.     _FREEIMAGE a& '<<< this is important!
  72.  
  73. SUB fcirc (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  74.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  75.     DIM X AS INTEGER, Y AS INTEGER
  76.     Radius = ABS(R): RadiusError = -Radius: X = Radius: Y = 0
  77.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  78.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  79.     WHILE X > Y
  80.         RadiusError = RadiusError + Y * 2 + 1
  81.         IF RadiusError >= 0 THEN
  82.             IF X <> Y + 1 THEN
  83.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  84.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  85.             END IF
  86.             X = X - 1
  87.             RadiusError = RadiusError - X * 2
  88.         END IF
  89.         Y = Y + 1
  90.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  91.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  92.     WEND
  93.  
« Last Edit: July 08, 2019, 07:56:27 pm by bplus »