News:

Building a 3D Ray Tracer  By stevmjon

Main Menu

Drawing a Grid (graph paper)

Started by kevin, March 20, 2008, 06:48:44 AM

Previous topic - Next topic

kevin

  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.


PlayBASIC Code: [Select]
   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



ATLUS