UnderwareDESIGN

PlayBASIC => Resources => Source Codes => Topic started by: kevin on March 20, 2008, 06:48:44 AM

Title: Drawing a Grid (graph paper)
Post by: kevin on March 20, 2008, 06:48:44 AM
  This snippet makes a basic 'grid' styled image.   The resulting image is then tiled to created the graph paper styled effect.  While you could draw the grid real time, caching the pattern to an image is much more efficient.


[pbcode]
   img= MakeGridPatternImg(32,4,32,4,10,rgb(120,130,140),rgb(150,150,150),rgb(210,200,200))

   TileIMage img,0,0,false

   Sync
   waitkey
      



Function MakeGridPatternImg(GridWidth,GridWidthStepX,GridHeight,GridHeightStepY,Segs, BG_RGB, SubDiv_RGB, HighLight_RGB)
   oldRgb=Getink()
   oldSurface=GetSurface()
   w   =GridWidth   *Segs   
   h   =GridHeight   *Segs   

   ThisIMage=NewImage(w,h)
   RenderToImage thisimage
   Cls BG_RGB

   ink SubDiv_RGB
   For Ylp=0 to H-1 step    GridWidthStepX   
      For Xlp=0 to w-1 step GridHeightStepY
         line 0,ylp,w,ylp                     
         line xlp,0,xlp,h                     
      next   
   next   

   ink HighLight_RGB
   For Ylp=0 to H-1 step GridHeight
      For Xlp=0 to w-1 step GridWidth
         line 0,ylp,w,ylp                     
         line xlp,0,xlp,h                     
      next   
   next   

   ; restore old surface and ink colour
   RenderToImage OldSurface   
   ink oldrgb
EndFunction ThisImage

[/pbcode]
Title: Re: Drawing a Grid (graph paper)
Post by: ATLUS on March 20, 2008, 10:08:34 AM
It cool thanks!!!