Author Topic: Persian Carpets  (Read 5641 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Persian Carpets
« on: February 28, 2018, 09:46:20 am »
Maybe Persian wash clothes ;)

I heard a call from the wilderness for the Mighty bplus carpets (inspired so by Cellular Automata).

Yeah I guess they might look similar in still shots, totally different process though, Persian Carpets uses POINT:
Code: QB64: [Select]
  1. CONST xmax = 700
  2. CONST ymax = 600
  3. SCREEN _NEWIMAGE(xmax, ymax, 32)
  4. _TITLE "RECURSIVE FILL TESTER by bplus"
  5.  
  6. xoff = (xmax - 512) / 2: yoff = (ymax - 512) / 2 + 20
  7. seedSpacer = 16
  8.     seedColor& = _RGB(RND * 100 + 155, RND * 100 + 155, RND * 100 + 155)
  9.     WHILE 1
  10.         IF k$ = " " THEN
  11.             EXIT WHILE
  12.         ELSEIF k$ = "h" THEN
  13.             seedSpacer = seedSpacer \ 2
  14.             IF seedSpacer = 1 THEN seedSpacer = 2
  15.         ELSEIF k$ = "d" THEN
  16.             seedSpacer = seedSpacer * 2
  17.             IF seedSpacer = 512 THEN seedSpacer = 256
  18.         END IF
  19.         CLS
  20.         PRINT "            seed spacer:"; seedSpacer; "  seed color: "; seedColor&; "  Rnd mixer: "; mixer
  21.         FOR y = 0 TO 512 STEP seedSpacer
  22.             FOR x = 0 TO 512 STEP seedSpacer
  23.                 PSET (x + xoff, y + yoff), seedColor&
  24.             NEXT
  25.         NEXT
  26.         mixer = RND * 10
  27.         rfill 0 + xoff, 0 + yoff, 512 + xoff, 512 + yoff
  28.         _DISPLAY
  29.         LOCATE 3, 1
  30.         INPUT " Seed spacer: h=half, d=double   seed color: spacebar to change,  enter next screen > ", k$
  31.     WEND
  32. SUB rfill (l, t, r, b)
  33.     IF l < r - 2 AND t < b - 2 THEN
  34.         mx = INT((r - l) / 2) + l: my = INT((b - t) / 2) + t
  35.         pc& = INT((POINT(l, t) + POINT(r, t) + POINT(l, b) + POINT(r, b)) * mixer)
  36.         IF _RED32(pc&) / 255 < .25 THEN
  37.             r% = 0
  38.         ELSEIF _RED32(pc&) / 255 < .5 THEN
  39.             r% = 128
  40.         ELSEIF _RED(pc&) / 255 < .75 THEN
  41.             r% = 192
  42.         ELSE
  43.             r% = 255
  44.         END IF
  45.         IF _GREEN32(pc&) / 255 < .25 THEN
  46.             g% = 0
  47.         ELSEIF _GREEN32(pc&) / 255 < .5 THEN
  48.             g% = 128
  49.         ELSEIF _GREEN32(pc&) / 255 < .75 THEN
  50.             g% = 192
  51.         ELSE
  52.             g% = 255
  53.         END IF
  54.         IF _BLUE32(pc&) / 255 < .5 THEN
  55.             b% = 0
  56.         ELSEIF _BLUE32(pc&) / 255 < .5 THEN
  57.             b% = 128
  58.         ELSEIF _BLUE32(pc&) / 255 < .75 THEN
  59.             b% = 192
  60.         ELSE
  61.             b% = 255
  62.         END IF
  63.         LINE (mx - 1, my - 1)-(mx + 1, my + 1), _RGB(r%, g%, b%), BF
  64.         rfill l, t, mx, my
  65.         rfill mx, t, r, my
  66.         rfill l, my, mx, b
  67.         rfill mx, my, r, b
  68.     ELSE
  69.         EXIT SUB
  70.     END IF
  71.  

Well if it made an impression, then must be Golden Oldie from NET
Persian Carpet tester.PNG
* Persian Carpet tester.PNG (Filesize: 94.82 KB, Dimensions: 702x600, Views: 520)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Persian Carpets
« Reply #1 on: February 28, 2018, 09:51:44 am »
How about a magic Carpet ride?

Code: QB64: [Select]
  1. ' Wavy Persian Carpets.bas SmallBASIC 0.12.9 (B+=MGA) 2017-09-27
  2. ' originally based on Anne M Burns Persian Carpet
  3.  
  4. CONST xmax = 1000
  5. CONST ymax = 700
  6.  
  7. CONST W = 128
  8. CONST H = 128
  9.  
  10. SCREEN _NEWIMAGE(xmax, ymax, 32)
  11. _TITLE "Wavy Persian Carpets by bplus, press spacebar to wave another"
  12. xo = (xmax - W) / 2: yo = (ymax - H) / 2
  13. lft = xo: rght = W + xo: top = yo: bot = H + yo
  14.     REDIM carpet&(W, H)
  15.     r& = _RGB(RND * 200 + 55, RND * 200 + 55, RND * 200 + 55)
  16.     LINE (lft, top)-(rght, top), r&
  17.     LINE (lft, bot)-(rght, bot), r&
  18.     LINE (lft, top)-(lft, bot), r&
  19.     LINE (rght, top)-(rght, bot), r&
  20.     DetermineColor lft, rght, top, bot
  21.     _DISPLAY
  22.     FOR y = 0 TO H
  23.         FOR x = 0 TO W
  24.             carpet&(x, y) = POINT(xo + x, yo + y)
  25.         NEXT
  26.     NEXT
  27.     'check point worked
  28.     CLS
  29.     PRINT "Check graphic, press any (except spacebar) to continue..."
  30.     FOR y = 0 TO H
  31.         FOR x = 0 TO W
  32.             PSET (x + 100, y + 100), carpet&(x, y)
  33.         NEXT
  34.     NEXT
  35.     _DISPLAY
  36.     SLEEP
  37.  
  38.     da# = _PI(2) / 30: aInc# = _PI(2) / 50: a# = 0
  39.     bOrbit! = .1: br! = 4: spacer = 5: walk! = 0: dir = 1
  40.     WHILE 1
  41.         IF _KEYHIT = 32 THEN EXIT WHILE
  42.         a# = a# + aInc#
  43.         bOrbit! = bOrbit! + .1 * dir
  44.         IF bOrbit! >= 15.1 THEN bOrbit! = 15.0: dir = dir * -1
  45.         IF bOrbit! <= 0 THEN bOrbit! = .1: dir = dir * -1
  46.         CLS
  47.         FOR y = 0 TO H
  48.             FOR x = 0 TO W
  49.                 bAngle# = (x + y) * da# + a#
  50.                 xBall = (2 * SIN(bAngle#) + COS(bAngle#)) / 2 * bOrbit! + x * spacer
  51.                 yBall = (COS(bAngle#) + SIN(bAngle#)) / 2 * bOrbit! + y * spacer
  52.                 COLOR carpet&(x, y)
  53.                 fcirc (xBall + 10 + walk!) MOD (xmax + 640), (yBall + 10 + .12 * walk!) MOD (ymax + 640), br!
  54.             NEXT
  55.         NEXT
  56.         walk! = walk! + .1 * bOrbit!
  57.         _DISPLAY
  58.         _LIMIT 60
  59.     WEND
  60.  
  61. REM Determine the color based on function f, and draw cross in quadrant
  62. SUB DetermineColor (lft, rght, top, bot)
  63.     IF (lft < rght - 1) THEN
  64.         middlecol = INT((lft + rght) / 2)
  65.         middlerow = INT((top + bot) / 2)
  66.         c& = f&(lft, rght, top, bot)
  67.         LINE (lft + 1, middlerow)-(rght - 1, middlerow), c&
  68.         LINE (middlecol, top + 1)-(middlecol, bot - 1), c&
  69.         DetermineColor lft, middlecol, top, middlerow
  70.         DetermineColor middlecol, rght, top, middlerow
  71.         DetermineColor lft, middlecol, middlerow, bot
  72.         DetermineColor middlecol, rght, middlerow, bot
  73.     ELSE
  74.         EXIT SUB
  75.     END IF
  76.  
  77. 'create 4x4x4 very bright contrasting colors
  78. FUNCTION f& (lft, rght, top, bot)
  79.     p& = POINT(lft, top) + POINT(rght, top) + POINT(lft, bot) + POINT(rght, bot)
  80.     IF _RED32(p&) / 255 < .25 THEN
  81.         r% = 0
  82.     ELSEIF _RED32(p&) / 255 < .5 THEN
  83.         r% = 128
  84.     ELSEIF _RED32(p&) / 255 < .75 THEN
  85.         r% = 192
  86.     ELSE
  87.         r% = 255
  88.     END IF
  89.     IF _GREEN32(p&) / 255 < .25 THEN
  90.         g% = 0
  91.     ELSEIF _GREEN32(p&) / 255 < .5 THEN
  92.         g% = 128
  93.     ELSEIF _GREEN32(p&) / 255 < .75 THEN
  94.         g% = 192
  95.     ELSE
  96.         g% = 255
  97.     END IF
  98.     IF _BLUE32(p&) / 255 < .5 THEN
  99.         b% = 0
  100.     ELSEIF _BLUE32(p&) / 255 < .5 THEN
  101.         b% = 128
  102.     ELSEIF _BLUE32(p&) / 255 < .75 THEN
  103.         b% = 192
  104.     ELSE
  105.         b% = 255
  106.     END IF
  107.     f& = _RGB(r, g, b)
  108.  
  109. 'Steve McNeil's  copied from his forum   note: Radius is too common a name
  110. SUB fcirc (CX AS LONG, CY AS LONG, R AS LONG)
  111.     DIM subRadius AS LONG, RadiusError AS LONG
  112.     DIM X AS LONG, Y AS LONG
  113.  
  114.     subRadius = ABS(R)
  115.     RadiusError = -subRadius
  116.     X = subRadius
  117.     Y = 0
  118.  
  119.     IF subRadius = 0 THEN PSET (CX, CY): EXIT SUB
  120.  
  121.     ' Draw the middle span here so we don't draw it twice in the main loop,
  122.     ' which would be a problem with blending turned on.
  123.     LINE (CX - X, CY)-(CX + X, CY), , BF
  124.  
  125.     WHILE X > Y
  126.         RadiusError = RadiusError + Y * 2 + 1
  127.         IF RadiusError >= 0 THEN
  128.             IF X <> Y + 1 THEN
  129.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), , BF
  130.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), , BF
  131.             END IF
  132.             X = X - 1
  133.             RadiusError = RadiusError - X * 2
  134.         END IF
  135.         Y = Y + 1
  136.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), , BF
  137.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), , BF
  138.     WEND
  139.  
  140.  
Wavy Persian Carpet.PNG
* Wavy Persian Carpet.PNG (Filesize: 142.87 KB, Dimensions: 998x703, Views: 519)

Offline Donald Foster

  • Newbie
  • Posts: 63
    • View Profile
Re: Persian Carpets
« Reply #2 on: February 28, 2018, 12:44:12 pm »
bplus,

Those are amazing. I have no clue how they are done. The images that you and Walter makes with your demos are incredible.

Donald

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Persian Carpets
« Reply #3 on: February 28, 2018, 02:15:13 pm »
The mighty bplus strikes again! :D

Thanks Donald!