Author Topic: Noise Effect  (Read 4038 times)

0 Members and 1 Guest are viewing this topic.

Offline MrFreyer

  • Newbie
  • Posts: 34
    • View Profile
Noise Effect
« on: November 05, 2019, 05:37:32 pm »
...just a little noise-effect I want to share.

Code: QB64: [Select]
  1. DEFINT A-Z
  2.  
  3.  
  4. desktop.height = _DESKTOPHEIGHT
  5.  
  6. screenwindow.WIDTH = 800
  7. screenwindow.height = 600
  8.  
  9. SCREEN _NEWIMAGE(screenwindow.WIDTH, screenwindow.height, 32)
  10. _SCREENMOVE (desktop.width * 0.5 - screenwindow.WIDTH * 0.5), 0
  11.  
  12. CONST pixelbytes = 4 '4 bytes per pixel (RGBA)
  13.  
  14. DIM pixelcolorRed AS _UNSIGNED _BYTE
  15. DIM pixelcolorGreen AS _UNSIGNED _BYTE
  16. DIM pixelcolorBlue AS _UNSIGNED _BYTE
  17.  
  18. DIM screenMemoryblock AS _MEM
  19.  
  20. screenMemoryblock = _MEMIMAGE(0)
  21.  
  22.     FOR y = 0 TO screenwindow.height - 1
  23.         FOR x = 0 TO screenwindow.WIDTH - 1
  24.  
  25.             pixelcolorRed = (RND * 254) + 1 'pick random red pixelcolor-value from 1 to 255
  26.             pixelcolorGreen = (RND * 254) + 1 'pick random green pixelcolor-value from 1 to 255
  27.             pixelcolorBlue = (RND * 254) + 1 'pick random blue pixelcolor-value from 1 to 255
  28.  
  29.             _MEMPUT screenMemoryblock, screenMemoryblock.OFFSET + (x * pixelbytes) + (y * (screenwindow.WIDTH * pixelbytes)), pixelcolorRed
  30.             _MEMPUT screenMemoryblock, screenMemoryblock.OFFSET + ((x * pixelbytes) + 1) + (y * (screenwindow.WIDTH * pixelbytes)), pixelcolorGreen
  31.             _MEMPUT screenMemoryblock, screenMemoryblock.OFFSET + ((x * pixelbytes) + 2) + (y * (screenwindow.WIDTH * pixelbytes)), pixelcolorBlue
  32.  
  33.         NEXT x
  34.     NEXT y
  35.  
  36.     _DISPLAY
  37.  
  38.  


EDIT:
...and the same program with PRESET instead of _MEMPUT. Would be slightly slower.
Code: QB64: [Select]
  1. DEFINT A-Z
  2.  
  3.  
  4. desktop.height = _DESKTOPHEIGHT
  5.  
  6. screenwindow.WIDTH = 800
  7. screenwindow.height = 600
  8.  
  9. SCREEN _NEWIMAGE(screenwindow.WIDTH, screenwindow.height, 32)
  10. _SCREENMOVE (desktop.WIDTH * 0.5 - screenwindow.WIDTH * 0.5), 0
  11.  
  12. DIM pixelcolorRed AS _UNSIGNED _BYTE
  13. DIM pixelcolorGreen AS _UNSIGNED _BYTE
  14. DIM pixelcolorBlue AS _UNSIGNED _BYTE
  15.  
  16.     FOR y = 0 TO screenwindow.height - 1
  17.         FOR x = 0 TO screenwindow.WIDTH - 1
  18.  
  19.             pixelcolorRed = (RND * 254) + 1 'pick random red pixelcolor-value from 1 to 255
  20.             pixelcolorGreen = (RND * 254) + 1 'pick random green pixelcolor-value from 1 to 255
  21.             pixelcolorBlue = (RND * 254) + 1 'pick random blue pixelcolor-value from 1 to 255
  22.  
  23.             PRESET (x, y), _RGB(pixelcolorRed, pixelcolorGreen, pixelcolorBlue)
  24.  
  25.         NEXT x
  26.     NEXT y
  27.  
  28.     _DISPLAY
  29.  
  30.  
« Last Edit: November 06, 2019, 04:05:25 am by MrFreyer »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Noise Effect (with _MEMGET / _MEMPUT)
« Reply #1 on: November 05, 2019, 09:36:40 pm »
LOL pretty cool effect!

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Noise Effect (with _MEMGET / _MEMPUT)
« Reply #2 on: November 05, 2019, 09:45:10 pm »
When I read "Noise Effect" I reached for the headphones.... Cool... "visual" static... Ok. You can stop laughing now...
Logic is the beginning of wisdom.