Author Topic: Worley Noise Demo  (Read 9592 times)

0 Members and 1 Guest are viewing this topic.

This topic contains a post which is marked as Best Answer. Press here if you would like to see it.

Offline Phlashlite

  • Newbie
  • Posts: 50
    • View Profile
Worley Noise Demo
« on: January 30, 2022, 10:31:41 am »
Ported Worley Noise generator. Enjoy!

-Phlashlite



Code: QB64: [Select]
  1. _TITLE "Worley Noise Demo"
  2.  
  3. 'Based on:
  4. 'Coding in the Cabana
  5. 'The Coding Train / Daniel SULffman
  6. 'https://thecodingtrain.com/CodingInTheCabana/004-worley-noise.html
  7. '[youtube]https://youtu.be/4066MndcyCk[/youtube]
  8.  
  9. 'QB64 Port by Phlashlite
  10. 'Other resources used: https://www.carljohanrosen.com/share/CellNoiseAndProcessing.pdf
  11.  
  12. 'This version only calculates noise for a 2D Vector.  But, a third dimension (or more)
  13. 'could easily be added.
  14.  
  15.  
  16. TYPE Coordinates
  17.     cx AS INTEGER
  18.     cy AS INTEGER
  19.  
  20. '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  21. CONST WDTH = 400
  22. CONST HGHT = 400
  23. CONST CellCount = 20 'Number of random points to scatter
  24. CONST Nth = 1 'Adjustable within the number of CellPnts(CellCount), -> 1 to CellCount - 1
  25. '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  26.  
  27. DIM SHARED CellPnts(CellCount) AS Coordinates
  28. DIM SHARED Distances(CellCount) AS INTEGER
  29.  
  30. Start = LBOUND(Distances) '__________________Used for sorting in SUB Main...
  31. Finish = UBOUND(Distances) '_________________... ... .... ^
  32.  
  33. '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  34. 'The greater GradS, the lighter the overall feel is.  Playing with these adjusts
  35. 'the "tightnes" of the gradient between light and dark.  The larger the delta,
  36. 'the smoother the gradient
  37.  
  38. GradS = 200 '_______________________________Used to adjust color gradient...  (< 0)
  39. GradF = -100 '________________________________in SUB Main, Map! Function call (<-> 0)
  40. '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  41.  
  42.     Setup
  43.     Main
  44.  
  45.     'Demo random settings and text.___________________________________________________
  46.     GradS = Rndm(1, 300)
  47.     GradF = Rndm(-100, 500)
  48.     PRINT "IM STILL WORKING!  Give me a few seconds... "
  49.     _DISPLAY
  50.     '__________________________________________________________________________
  51.  
  52.  
  53. SUB Setup
  54.     SCREEN _NEWIMAGE(WDTH, HGHT, 32)
  55.  
  56.     'Distribute the random points
  57.     FOR i = 1 TO CellCount
  58.         CellPnts(i).cx = RND * WDTH
  59.         CellPnts(i).cy = RND * HGHT
  60.  
  61.         'Visual queue, not "required". Turn off "_DISPLAY" below to see these.
  62.         CIRCLE (CellPnts(i).cx, CellPnts(i).cy), 2, _RGB(255, 0, 0)
  63.     NEXT
  64.  
  65.  
  66. SUB Main
  67.     'Where the magic happens.
  68.  
  69.     'Adjust STEP to play with an interlaced or screen grid type effect.
  70.     FOR x = 0 TO WDTH STEP 1 '___________________________From every screen point...
  71.         FOR y = 0 TO HGHT STEP 1 '_______________________... ... ... ^
  72.             FOR i = 1 TO CellCount STEP 1 '______________To every "CellPnts"
  73.  
  74.                 'Check the distance between and store value in Distances()
  75.                 Distances(i) = dist(x, y, CellPnts(i).cx, CellPnts(i).cy)
  76.  
  77.                 'Sort Distances()
  78.                 CALL QuickSort(Start, Finish, Distances())
  79.  
  80.                 '"Map!" the initial distance() between a specific screen point and a
  81.                 'CellPnts to a user definable distance.  Affects the color .gradient
  82.                 '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  83.                 Gradient = map!(Distances(Nth), Distances(Start), Distances(Finish), GradS, GradF)
  84.  
  85.                 'Draw it
  86.                 PSET (x, y), _RGB(Gradient, Gradient, Gradient)
  87.                 '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  88.             NEXT
  89.         NEXT
  90.     NEXT
  91.  
  92.     _DISPLAY 'Comment this line to watch the screen be drawn.  It's slooooow.
  93.  
  94.  
  95.  
  96. '______________________________________________________________________________
  97.  
  98. ' Map function I found or translated from somewhere.
  99. ' The Coding Train" guy on youtube, where I translated the rain code from explained it in one of his videos.
  100.  
  101. FUNCTION map! (value!, minRange!, maxRange!, newMinRange!, newMaxRange!)
  102.     map! = ((value! - minRange!) / (maxRange! - minRange!)) * (newMaxRange! - newMinRange!) + newMinRange!
  103.  
  104. '______________________________________________________________________________
  105. FUNCTION dist (x1, y1, x2, y2)
  106.     'The dist() function calculates the Euclidean distance between two points in 2D.
  107.     '2D formula:
  108.     '  dist = sqr{(x1-x2)^2+(y1-y2)^2}
  109.     dist = SQR((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2))
  110. '______________________________________________________________________________
  111.  
  112. 'Standard random numbers in a range of mn! (min) to mx! (max)
  113.  
  114. FUNCTION Rndm! (mn!, mx!)
  115.     IF mn! > mx! THEN
  116.         SWAP mn!, mx!
  117.     END IF
  118.     Rndm! = RND * (mx! - mn!) + mn!
  119.  
  120. '______________________________________________________________________________
  121. SUB QuickSort (start AS INTEGER, finish AS INTEGER, array() AS INTEGER)
  122.     'Straight from the QB64 wiki
  123.     DIM Hi AS INTEGER, Lo AS INTEGER, Middle AS INTEGER
  124.     Hi = finish
  125.     Lo = start
  126.     Middle = array((Lo + Hi) / 2) 'find middle of array
  127.  
  128.     DO
  129.         DO WHILE array(Lo) < Middle
  130.             Lo = Lo + 1
  131.         LOOP
  132.  
  133.         DO WHILE array(Hi) > Middle
  134.             Hi = Hi - 1
  135.         LOOP
  136.  
  137.         IF Lo <= Hi THEN
  138.             SWAP array(Lo), array(Hi)
  139.             Lo = Lo + 1
  140.             Hi = Hi - 1
  141.         END IF
  142.     LOOP UNTIL Lo > Hi
  143.  
  144.     IF Hi > start THEN CALL QuickSort(start, Hi, array())
  145.     IF Lo < finish THEN CALL QuickSort(Lo, finish, array())
  146.  
  147.  
  148. '______________________________________________________________________________
  149.  
  150. 'Original P5js code:
  151.  
  152. '// Worley Noise
  153. '// Coding in the Cabana
  154. '// The Coding Train / Daniel SULffman
  155. '// https://thecodingtrain.com/CodingInTheCabana/004-worley-noise.html
  156. '// [youtube]https://youtu.be/4066MndcyCk[/youtube]
  157. '// p5 port: https://editor.p5js.org/codingtrain/sketches/QsiCWVczZ
  158.  
  159. 'function setup() {
  160. '  createCanvas(100, 100);
  161. '  pixelDensity(1);
  162. '  for (let i = 0; i < 20; i++) {
  163. '    points[i] = createVector(random(width), random(height), random(width));
  164. '  }
  165. '}
  166.  
  167. 'function draw() {
  168. '  LLadPixels();
  169. '  for (let x = 0; x < width; x++) {
  170. '    for (let y = 0; y < height; y++) {
  171. '      let distances = [];
  172. '      for (let i = 0; i < points.length; i++) {
  173. '        let v = points[i];
  174. '        let z = frameCount % width;
  175. '        let d = dist(x, y, z, v.x, v.y, v.z);
  176. '        distances[i] = d;
  177. '      }
  178. '      let sorted = sort(distances);
  179. '      let r = map(sorted[0], 0, 150, 0, 255);
  180. '      let g = map(sorted[1], 0, 50, 255, 0);
  181. '      let b = map(sorted[2], 0, 200, 255, 0);
  182. '      let index = (x + y * width) * 4;
  183. '      pixels[index + 0] = r;
  184. '      pixels[index + 1] = g;
  185. '      pixels[index + 2] = b;
  186. '      pixels[index + 3] = 255;
  187. '    }
  188. '  }
  189. '  updatePixels();
  190. '}
  191.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Worley Noise Demo
« Reply #1 on: January 30, 2022, 11:25:39 am »
Ha, that reminds me of this: https://qb64forum.alephc.xyz/index.php?topic=3890.msg132266#msg132266

Playing with Voronoi code.

Offline Phlashlite

  • Newbie
  • Posts: 50
    • View Profile
Re: Worley Noise Demo
« Reply #2 on: January 30, 2022, 11:38:00 am »
Ha, that reminds me of this: https://qb64forum.alephc.xyz/index.php?topic=3890.msg132266#msg132266

Playing with Voronoi code.

@bplus
Yep, they are very similar!  I am working on cloud textures... But this is very slow.  Both the education and the code... LOL

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Worley Noise Demo
« Reply #3 on: January 30, 2022, 11:44:54 am »
You know I think there is a fractal for cloud making, @Phlashlite is that different than what you're after?

Offline Phlashlite

  • Newbie
  • Posts: 50
    • View Profile
Re: Worley Noise Demo
« Reply #4 on: January 30, 2022, 11:46:50 am »
You know I think there is a fractal for cloud making, @Phlashlite is that different than what you're after?

Don't know.  Haven't seen it... LOL.  Maybe.

Offline Phlashlite

  • Newbie
  • Posts: 50
    • View Profile
Re: Worley Noise Demo
« Reply #5 on: January 30, 2022, 12:11:34 pm »
@bplus

Like a Diamond-square algorithm?  Possibly.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Worley Noise Demo
« Reply #6 on: January 30, 2022, 01:00:41 pm »
Yeah checking it now, but QB64 is bugging out with a recursive attempt, so after lunch I will try a non recursive effort which I am pretty sure might work.

Marked as best answer by Phlashlite on February 01, 2022, 07:09:13 pm

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Worley Noise Demo
« Reply #7 on: January 31, 2022, 12:35:44 pm »
I think I am getting closer, my original try with recursion was buggy as heck and then I discovered I had to color the corners of the new squares being used to determine middle dot, so now it's almost looking like clouds.

Clouds Picasso style!
Code: QB64: [Select]
  1. Screen _NewImage(800, 600, 32)
  2. DefLng A-Z
  3. 'seed
  4. fcirc 0, 0, 2, _RGB32(200)
  5. fcirc _Width - 1, 0, 2, _RGB32(164)
  6. fcirc _Width - 1, _Height - 1, 2, _RGB32(184)
  7. fcirc 0, _Height - 1, 2, _RGB32(128)
  8.  
  9.     Cls
  10.     fcirc 0, 0, 2, _RGB32(200)
  11.     fcirc _Width - 1, 0, 2, _RGB32(164)
  12.     fcirc _Width - 1, _Height - 1, 2, _RGB32(184)
  13.     fcirc 0, _Height - 1, 2, _RGB32(128)
  14.  
  15.     cloud 0, 0, _Width - 1, _Height - 1
  16.     _Display
  17.     _Limit 1
  18.  
  19. Sub cloud (x1, y1, x2, y2) ' corners of square or rect
  20.     Dim c As Long
  21.     mx = (x1 + x2) / 2
  22.     my = (y1 + y2) / 2
  23.     If (mx <= x1 + 1) Or (my <= y + 1) Then Exit Sub
  24.     c = _Red32(Point(x1, y1)) + _Red32(Point(x2, y1)) + _Red32(Point(x1, y2)) + _Red32(Point(x2, y2))
  25.     If Rnd < .50 Then fcirc mx, my, 3, _RGB32((c + c / 4 + Rnd * 64 - 32) / 5) Else fcirc mx, my, 2, _RGB32(c)
  26.     'AHA! need to color corners of future squares  NOT just the middle!
  27.     fcirc mx, y1, 3, _RGB32((c + c / 4 + Rnd * 64 - 32) / 5)
  28.     fcirc x1, my, 3, _RGB32((c + c / 4 + Rnd * 64 - 32) / 5)
  29.     fcirc x2, my, 3, _RGB32((c + c / 4 + Rnd * 64 - 32) / 5)
  30.     fcirc mx, y2, 3, _RGB32((c + c / 4 + Rnd * 64 - 32) / 5)
  31.     cloud x1, y1, mx, my
  32.     cloud mx, y1, x2, my
  33.     cloud x1, my, mx, y2
  34.     cloud mx, my, x2, y2
  35.  
  36. Sub fcirc (CX As Long, CY As Long, R As Long, C As _Unsigned Long)
  37.     Dim Radius As Long, RadiusError As Long
  38.     Dim X As Long, Y As Long
  39.     Radius = Abs(R): RadiusError = -Radius: X = Radius: Y = 0
  40.     If Radius = 0 Then PSet (CX, CY), C: Exit Sub
  41.     Line (CX - X, CY)-(CX + X, CY), C, BF
  42.     While X > Y
  43.         RadiusError = RadiusError + Y * 2 + 1
  44.         If RadiusError >= 0 Then
  45.             If X <> Y + 1 Then
  46.                 Line (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  47.                 Line (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  48.             End If
  49.             X = X - 1
  50.             RadiusError = RadiusError - X * 2
  51.         End If
  52.         Y = Y + 1
  53.         Line (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  54.         Line (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  55.     Wend
  56.  
  57.  
  58.  

Needs some blending, shmearing :)

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: Worley Noise Demo
« Reply #8 on: January 31, 2022, 12:56:27 pm »
very opulent flooring!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Worley Noise Demo
« Reply #9 on: January 31, 2022, 02:44:13 pm »
very opulent flooring!

Yeah that maybe a better app than trying to make clouds. I tried smear but the blocks are too distinct to blur out easily.

Offline Phlashlite

  • Newbie
  • Posts: 50
    • View Profile
Re: Worley Noise Demo
« Reply #10 on: February 01, 2022, 10:46:59 pm »
@bplus  I'll have to study it.  It might work for what I'm looking for... with some modification of course!... Thanks!


Clouds Picasso style!


Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Worley Noise Demo
« Reply #11 on: February 02, 2022, 05:43:32 am »
Perlin Noise might be better approach.

FellippeHeitor

  • Guest
Re: Worley Noise Demo
« Reply #12 on: February 02, 2022, 06:38:41 am »
Code: QB64: [Select]
  1. 'noise function related variables
  2. DIM SHARED perlin_octaves AS SINGLE, perlin_amp_falloff AS SINGLE
  3.  
  4. DIM SHARED noiseScale AS _FLOAT
  5. noiseScale = 0.02
  6.  
  7. SCREEN _NEWIMAGE(300, 300, 32)
  8.  
  9.     CLS , _RGB32(51)
  10.  
  11.     COLOR _RGB32(255)
  12.     _PRINTSTRING (0, 0), "Move your mouse"
  13.  
  14.     FOR x = 0 TO _WIDTH
  15.         noiseVal = noise((_MOUSEX + x) * noiseScale, _MOUSEY * noiseScale, 0)
  16.         COLOR _RGB32(noiseVal * 255)
  17.         LINE (x, _MOUSEY + noiseVal * 80)-(x, _HEIGHT)
  18.     NEXT
  19.     _DISPLAY
  20.     _LIMIT 60
  21.  
  22. FUNCTION noise! (x AS SINGLE, y AS SINGLE, z AS SINGLE)
  23.     STATIC p5NoiseSetup AS _BYTE
  24.     STATIC perlin() AS SINGLE
  25.     STATIC PERLIN_YWRAPB AS SINGLE, PERLIN_YWRAP AS SINGLE
  26.     STATIC PERLIN_ZWRAPB AS SINGLE, PERLIN_ZWRAP AS SINGLE
  27.     STATIC PERLIN_SIZE AS SINGLE
  28.  
  29.     CONST true = -1, false = 0
  30.  
  31.     IF NOT p5NoiseSetup THEN
  32.         p5NoiseSetup = true
  33.  
  34.         PERLIN_YWRAPB = 4
  35.         PERLIN_YWRAP = INT(1 * (2 ^ PERLIN_YWRAPB))
  36.         PERLIN_ZWRAPB = 8
  37.         PERLIN_ZWRAP = INT(1 * (2 ^ PERLIN_ZWRAPB))
  38.         PERLIN_SIZE = 4095
  39.  
  40.         perlin_octaves = 4
  41.         perlin_amp_falloff = 0.5
  42.  
  43.         REDIM perlin(PERLIN_SIZE + 1) AS SINGLE
  44.         DIM i AS SINGLE
  45.         FOR i = 0 TO PERLIN_SIZE + 1
  46.             perlin(i) = RND
  47.         NEXT
  48.     END IF
  49.  
  50.     x = ABS(x)
  51.     y = ABS(y)
  52.     z = ABS(z)
  53.  
  54.     DIM xi AS SINGLE, yi AS SINGLE, zi AS SINGLE
  55.     xi = INT(x)
  56.     yi = INT(y)
  57.     zi = INT(z)
  58.  
  59.     DIM xf AS SINGLE, yf AS SINGLE, zf AS SINGLE
  60.     xf = x - xi
  61.     yf = y - yi
  62.     zf = z - zi
  63.  
  64.     DIM r AS SINGLE, ampl AS SINGLE, o AS SINGLE
  65.     r = 0
  66.     ampl = .5
  67.  
  68.     FOR o = 1 TO perlin_octaves
  69.         DIM of AS SINGLE, rxf AS SINGLE
  70.         DIM ryf AS SINGLE, n1 AS SINGLE, n2 AS SINGLE, n3 AS SINGLE
  71.         of = xi + INT(yi * (2 ^ PERLIN_YWRAPB)) + INT(zi * (2 ^ PERLIN_ZWRAPB))
  72.  
  73.         rxf = 0.5 * (1.0 - COS(xf * _PI))
  74.         ryf = 0.5 * (1.0 - COS(yf * _PI))
  75.  
  76.         n1 = perlin(of AND PERLIN_SIZE)
  77.         n1 = n1 + rxf * (perlin((of + 1) AND PERLIN_SIZE) - n1)
  78.         n2 = perlin((of + PERLIN_YWRAP) AND PERLIN_SIZE)
  79.         n2 = n2 + rxf * (perlin((of + PERLIN_YWRAP + 1) AND PERLIN_SIZE) - n2)
  80.         n1 = n1 + ryf * (n2 - n1)
  81.  
  82.         of = of + PERLIN_ZWRAP
  83.         n2 = perlin(of AND PERLIN_SIZE)
  84.         n2 = n2 + rxf * (perlin((of + 1) AND PERLIN_SIZE) - n2)
  85.         n3 = perlin((of + PERLIN_YWRAP) AND PERLIN_SIZE)
  86.         n3 = n3 + rxf * (perlin((of + PERLIN_YWRAP + 1) AND PERLIN_SIZE) - n3)
  87.         n2 = n2 + ryf * (n3 - n2)
  88.  
  89.         n1 = n1 + (0.5 * (1.0 - COS(zf * _PI))) * (n2 - n1)
  90.  
  91.         r = r + n1 * ampl
  92.         ampl = ampl * perlin_amp_falloff
  93.         xi = INT(xi * (2 ^ 1))
  94.         xf = xf * 2
  95.         yi = INT(yi * (2 ^ 1))
  96.         yf = yf * 2
  97.         zi = INT(zi * (2 ^ 1))
  98.         zf = zf * 2
  99.  
  100.         IF xf >= 1.0 THEN xi = xi + 1: xf = xf - 1
  101.         IF yf >= 1.0 THEN yi = yi + 1: yf = yf - 1
  102.         IF zf >= 1.0 THEN zi = zi + 1: zf = zf - 1
  103.     NEXT
  104.     noise! = r
  105.  
  106. SUB noiseDetail (lod!, falloff!)
  107.     IF lod! > 0 THEN perlin_octaves = lod!
  108.     IF falloff! > 0 THEN perlin_amp_falloff = falloff!
  109.  
  110. FUNCTION map! (value!, minRange!, maxRange!, newMinRange!, newMaxRange!)
  111.     map! = ((value! - minRange!) / (maxRange! - minRange!)) * (newMaxRange! - newMinRange!) + newMinRange!
  112.  

From https://github.com/AshishKingdom/p5js.bas/blob/master/p5js.bas
« Last Edit: February 02, 2022, 06:57:41 am by FellippeHeitor »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Worley Noise Demo
« Reply #13 on: February 02, 2022, 11:32:49 am »
 
Code: QB64: [Select]
  1. 'noise function related variables
  2. DIM SHARED perlin_octaves AS SINGLE, perlin_amp_falloff AS SINGLE
  3.  
  4. DIM SHARED noiseScale AS _FLOAT
  5. noiseScale = 0.02
  6.  
  7. SCREEN _NEWIMAGE(300, 300, 32)
  8.  
  9.     CLS , _RGB32(51)
  10.  
  11.     COLOR _RGB32(255)
  12.     _PRINTSTRING (0, 0), "Move your mouse"
  13.  
  14.     FOR x = 0 TO _WIDTH
  15.         noiseVal = noise((_MOUSEX + x) * noiseScale, _MOUSEY * noiseScale, 0)
  16.         COLOR _RGB32(noiseVal * 255)
  17.         LINE (x, _MOUSEY + noiseVal * 80)-(x, _HEIGHT)
  18.     NEXT
  19.     _DISPLAY
  20.     _LIMIT 60
  21.  
  22. FUNCTION noise! (x AS SINGLE, y AS SINGLE, z AS SINGLE)
  23.     STATIC p5NoiseSetup AS _BYTE
  24.     STATIC perlin() AS SINGLE
  25.     STATIC PERLIN_YWRAPB AS SINGLE, PERLIN_YWRAP AS SINGLE
  26.     STATIC PERLIN_ZWRAPB AS SINGLE, PERLIN_ZWRAP AS SINGLE
  27.     STATIC PERLIN_SIZE AS SINGLE
  28.  
  29.     CONST true = -1, false = 0
  30.  
  31.     IF NOT p5NoiseSetup THEN
  32.         p5NoiseSetup = true
  33.  
  34.         PERLIN_YWRAPB = 4
  35.         PERLIN_YWRAP = INT(1 * (2 ^ PERLIN_YWRAPB))
  36.         PERLIN_ZWRAPB = 8
  37.         PERLIN_ZWRAP = INT(1 * (2 ^ PERLIN_ZWRAPB))
  38.         PERLIN_SIZE = 4095
  39.  
  40.         perlin_octaves = 4
  41.         perlin_amp_falloff = 0.5
  42.  
  43.         REDIM perlin(PERLIN_SIZE + 1) AS SINGLE
  44.         DIM i AS SINGLE
  45.         FOR i = 0 TO PERLIN_SIZE + 1
  46.             perlin(i) = RND
  47.         NEXT
  48.     END IF
  49.  
  50.     x = ABS(x)
  51.     y = ABS(y)
  52.     z = ABS(z)
  53.  
  54.     DIM xi AS SINGLE, yi AS SINGLE, zi AS SINGLE
  55.     xi = INT(x)
  56.     yi = INT(y)
  57.     zi = INT(z)
  58.  
  59.     DIM xf AS SINGLE, yf AS SINGLE, zf AS SINGLE
  60.     xf = x - xi
  61.     yf = y - yi
  62.     zf = z - zi
  63.  
  64.     DIM r AS SINGLE, ampl AS SINGLE, o AS SINGLE
  65.     r = 0
  66.     ampl = .5
  67.  
  68.     FOR o = 1 TO perlin_octaves
  69.         DIM of AS SINGLE, rxf AS SINGLE
  70.         DIM ryf AS SINGLE, n1 AS SINGLE, n2 AS SINGLE, n3 AS SINGLE
  71.         of = xi + INT(yi * (2 ^ PERLIN_YWRAPB)) + INT(zi * (2 ^ PERLIN_ZWRAPB))
  72.  
  73.         rxf = 0.5 * (1.0 - COS(xf * _PI))
  74.         ryf = 0.5 * (1.0 - COS(yf * _PI))
  75.  
  76.         n1 = perlin(of AND PERLIN_SIZE)
  77.         n1 = n1 + rxf * (perlin((of + 1) AND PERLIN_SIZE) - n1)
  78.         n2 = perlin((of + PERLIN_YWRAP) AND PERLIN_SIZE)
  79.         n2 = n2 + rxf * (perlin((of + PERLIN_YWRAP + 1) AND PERLIN_SIZE) - n2)
  80.         n1 = n1 + ryf * (n2 - n1)
  81.  
  82.         of = of + PERLIN_ZWRAP
  83.         n2 = perlin(of AND PERLIN_SIZE)
  84.         n2 = n2 + rxf * (perlin((of + 1) AND PERLIN_SIZE) - n2)
  85.         n3 = perlin((of + PERLIN_YWRAP) AND PERLIN_SIZE)
  86.         n3 = n3 + rxf * (perlin((of + PERLIN_YWRAP + 1) AND PERLIN_SIZE) - n3)
  87.         n2 = n2 + ryf * (n3 - n2)
  88.  
  89.         n1 = n1 + (0.5 * (1.0 - COS(zf * _PI))) * (n2 - n1)
  90.  
  91.         r = r + n1 * ampl
  92.         ampl = ampl * perlin_amp_falloff
  93.         xi = INT(xi * (2 ^ 1))
  94.         xf = xf * 2
  95.         yi = INT(yi * (2 ^ 1))
  96.         yf = yf * 2
  97.         zi = INT(zi * (2 ^ 1))
  98.         zf = zf * 2
  99.  
  100.         IF xf >= 1.0 THEN xi = xi + 1: xf = xf - 1
  101.         IF yf >= 1.0 THEN yi = yi + 1: yf = yf - 1
  102.         IF zf >= 1.0 THEN zi = zi + 1: zf = zf - 1
  103.     NEXT
  104.     noise! = r
  105.  
  106. SUB noiseDetail (lod!, falloff!)
  107.     IF lod! > 0 THEN perlin_octaves = lod!
  108.     IF falloff! > 0 THEN perlin_amp_falloff = falloff!
  109.  
  110. FUNCTION map! (value!, minRange!, maxRange!, newMinRange!, newMaxRange!)
  111.     map! = ((value! - minRange!) / (maxRange! - minRange!)) * (newMaxRange! - newMinRange!) + newMinRange!
  112.  

From https://github.com/AshishKingdom/p5js.bas/blob/master/p5js.bas
Noise per Fell.PNG


Yeah I tried running p5js Perlin Noise when Ashish mentioned it at Discord. Wouldn't work possible from the 2.0 change in using variables with Function names.

But the above is only 1D, not cloudy at all, but reminds me of landscape building.

https://en.wikipedia.org/wiki/Perlin_noise
Mentions Dot Product which I dont know if you are using in p5js?

Offline Phlashlite

  • Newbie
  • Posts: 50
    • View Profile
Re: Worley Noise Demo
« Reply #14 on: February 02, 2022, 12:32:29 pm »
@bplus  Actually, there is a method of using Perlin noise to distribute the points for the Worley noise that is interesting.

Also, if one is industrious, it can be sped up by 15% to 20% by avoiding unnecessary calculations as described in this paper:

https://jcgt.org/published/0008/01/02/paper.pdf

I also tried 2 stepping the x,y loops which sped it up by a factor of 4... but I would need to fuzz the neighbors which might end up just killing those gains...

Anyway, I am working on it :).

I appreciate the interactions here.  Thanks all!