home *** CD-ROM | disk | FTP | other *** search
/ Game Programming for Teens / GameProgrammingForTeens.iso / Source / chapter06 / demo06-07.bb < prev    next >
Encoding:
Text File  |  2004-08-28  |  1.2 KB  |  61 lines

  1. ; demo06-07.bb - A ReadPixelFast/WritePixeFast Example 
  2.  
  3. Graphics 800,600 
  4.  
  5. Print "Press any key to use ReadPixel" 
  6. ;wait for user to do something
  7. WaitKey 
  8.  
  9. ;load rectangle image
  10. image =LoadImage("rectangle.bmp") 
  11.  
  12. ;Draw the intro screen
  13. DrawImage image,0,0 
  14. DrawImage image,100,100
  15.  
  16. ;Hold up  a second
  17. Delay (1000)
  18.  
  19. ;Create a pixel array that will hold the entire screen
  20. Dim pixelarray(GraphicsWidth(),GraphicsHeight()) 
  21.  
  22. ;lock the buffer REQUIRED
  23. LockBuffer 
  24.  
  25. ;Copy all of the pixels of the screen to the array
  26. For rows=0 To GraphicsWidth() 
  27.  
  28.     For cols=0 To GraphicsHeight() 
  29.     
  30.         ;Copy the current pixel
  31.         pixelarray(rows,cols)=ReadPixelFast(rows,cols) 
  32.     Next 
  33. Next 
  34.  
  35. ;Unlock the buffer
  36. UnlockBuffer 
  37.  
  38. Cls 
  39. Locate 0,0 
  40. Print "Press another key to copy pixels backwards"
  41.  
  42. ;Wait for key press
  43. WaitKey
  44.  
  45. ;Lock the buffer to allow WritePixelFast
  46. LockBuffer 
  47.  
  48. ; Use WritePixelFast to redraw the screen using the color information we got earlier 
  49. For rows=0 To GraphicsWidth() 
  50.     For cols=0 To GraphicsHeight() 
  51.         ;Draw the current pixels
  52.         WritePixelFast rows,cols,pixelarray(GraphicsWidth()-rows,cols) 
  53.     Next 
  54. Next 
  55.  
  56. ; Unlock buffer after using WritePixelFast 
  57. UnlockBuffer 
  58.  
  59. Print "Press a key to exit"
  60. WaitKey
  61.