PixelRunLength
Steps = PixelRunLength(StartX, StartY, StepX, StepY, MatchColour)
 
Parameters:

    StartX = The Starting X position
    StartY = The Starting Y position
    StepX = X delta
    StepY = Y delta
    MatchColour = The RGB Colour your
Returns:

    Steps = The number of matching pixels in this row
 

     The PixelRunLength() function finds the length of a run of pixels.



FACTS:


      * PixelRunLength Scans the current surface and is clipped to only scan inside the viewport.

      * Important: PixelRunLength is lower level function. Unlike 99% of the other functions in PlayBASIC PixelRunLength doesn't include any surface locking and buffer seeding. Therefore, Before you can use PixelRunLength safely. You must lock the draw surface (LockBuffer), then it's highly recommended you read a pixel from this surface using Point(). This will ensure the address of the surface are seeded correctly internally for PixelRunLength





Mini Tutorial:


This example calculates the number of pixels (of the same colour) to the Top,Bottom, Left and Right of the mouse pointer.



  
  
  
; start of DO/loop
  Do
     
   ; clear the screen to black
     Cls RGB(0,0,0)
     
   ; Display the Fps of the program
     Print FPS()
     
   ; draw a circle in the middle of the screen
     Circle 400,300,100,true
     
     
   ; get the mouse X & Y coords
     mx=MouseX()
     my=MouseY()
     
   ; lock the current buffer
     LockBuffer
     
   ; Get the pixel colour at the mouse position
     ThisRgb=Point(mx,my)
     
   ; calc the number of pixels above this point that are the same
     RunsUp=PixelRunLength(mx,my,0,-1,ThisRgb)-1
     
   ; calc the number of pixels bellow this point that are the same
     RunsDown=PixelRunLength(mx,my,0,1,ThisRgb)-1
     
   ; calc length of the left and right row of pixels
     RunsLeft=PixelRunLength(mx,my,-1,0,ThisRgb)-1
     RunsRight=PixelRunLength(mx,my,1,0,ThisRgb)-1
     
   ; draw the results
     LineC mx,my,mx,my-RunsUp,RGB(255,0,0)
     LineC mx,my,mx,my+RunsDown,RGB(255,0,0)
     
     LineC mx,my,mx-RunsLeft,my,RGB(255,0,0)
     LineC mx,my,mx+RunsRight,my,RGB(255,0,0)
     
   ; unclock the screen buffer
     UnLockBuffer
     
   ; refresh the screen to the user
     Sync
     
   ; loop back to the DO statement
  Loop
  
  




This example would output.

  
  no Text output
  

 
Related Info: Dot | FastDot | FastPoint | LockBuffer | Point :
 


(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com