Author Topic: Noise generator  (Read 3404 times)

0 Members and 1 Guest are viewing this topic.

Offline loudar

  • Newbie
  • Posts: 73
  • improve it bit by bit.
    • View Profile
Noise generator
« on: August 21, 2020, 11:05:35 am »
Does what it says!

Types:
0: sets a point
1: draws sine waves
2: empty rectangles
3: rectangles with a sinus curve stretched to the height of the rectangle

Feel free to add more or use it in a different context!

Code: QB64: [Select]
  1. 'noise generator
  2.  
  3.  
  4. SCREEN _NEWIMAGE(1280, 720, 32)
  5.  
  6. steps = 10 'maximum alpha for one pixel
  7. clustersize = 100
  8. count = 10000
  9. minwidth = 20
  10. minheight = 20
  11.  
  12. maxntype = 3
  13.  
  14. ntype = -1: DO: ntype = ntype + 1
  15.     IF ntype = 0 THEN count = count * 10: steps = steps * 20
  16.     IF ntype = 2 THEN steps = steps * 10
  17.  
  18.     CLS
  19.     d = 0: DO: d = d + 1 'd serves as index for Drawn pixels
  20.  
  21.         x(1) = RND * _WIDTH
  22.         y(1) = RND * _HEIGHT
  23.         x(2) = (RND * (clustersize - minwidth)) + minwidth
  24.         x(2) = x(1) + (x(2) - (x(2) / 2))
  25.         y(2) = (RND * (clustersize - minheight)) + minheight
  26.         y(2) = y(1) + (y(2) - (y(2) / 2))
  27.         t = RND * steps
  28.         IF y(2) > y(1) THEN ydif = y(2) - y(1) ELSE ydif = y(1) - y(2)
  29.         IF x(2) > x(1) THEN xdif = x(2) - x(1) ELSE xdif = x(1) - x(2)
  30.  
  31.         SELECT CASE ntype
  32.             CASE 0
  33.                 PSET (x(1), y(1)), _RGBA(255, 255, 255, t)
  34.             CASE 1
  35.                 s = 0: DO: s = s + 1
  36.                     PSET (s, y(1) + (SIN(s / xdif) * ydif)), _RGBA(255, 255, 255, t)
  37.                     PSET (s, y(1) + (SIN(s / xdif) * ydif) + 1), _RGBA(255, 255, 255, t)
  38.                 LOOP UNTIL s = _WIDTH
  39.             CASE 2
  40.                 LINE (x(1), y(1))-(x(2), y(2)), _RGBA(255, 255, 255, t), B
  41.             CASE 3
  42.                 c = 0: DO: c = c + 1
  43.                     f = c / ydif
  44.                     x = SIN(f * (_PI / 2)) * xdif
  45.                     'x = xdif - x
  46.                     LINE (x(1), y(1) + c)-(x(1) + x, y(1) + c), _RGBA(255, 255, 255, t)
  47.                 LOOP UNTIL c = INT(ydif)
  48.         END SELECT
  49.  
  50.     LOOP UNTIL d = count 'tries to make good contrast
  51.     _DISPLAY
  52.  
  53.     IF ntype = 0 THEN count = count / 10: steps = steps / 20
  54.     IF ntype = 2 THEN steps = steps / 10
  55.     SLEEP
  56. LOOP UNTIL ntype = maxntype
Check out what I do besides coding: http://loudar.myportfolio.com/

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: Noise generator
« Reply #1 on: August 21, 2020, 12:29:49 pm »
Good one.

Funny story, I rather liked that second shot as a wispy filament type background for potential picture projects. So I go to screen capture, but Doh!! it's a sleep statement, so every time I go to hit the <alt> <PrtSc> the screen jumps to the next image. LOL I felt like a monkey with his hand stuck in a cookie jar.

I got it by substituting a keydown do loop for sleep.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Noise generator
« Reply #2 on: August 21, 2020, 03:07:59 pm »
Yes that 2nd pattern looks almost like looking down on ocean.