grid

Blitz3D Forums/Blitz3D Beginners Area/grid

Gord(Posted 2006) [#1]
I am thinking of doing an icon editor but have no idea how to do a background grid. Any ideas?


GfK(Posted 2006) [#2]
This should get you started:

[edit] Updated to show an icon-sized preview. Haven't had time to thoroughly test/optimise.

Graphics 800,600
SetBuffer BackBuffer()

Global gridsize% = 31
Global tilesize% = 15
Global mx%,my%
Global DrawColor = 1
Global icon = CreateImage(gridsize+1,gridsize+1)

Dim Grid(gridsize,gridsize)

While Not KeyDown(1)
	Cls
	UpdateMouse()
	DrawIcon()
	DrawGrid()
	Flip
Wend

Function DrawGrid()
	For x = 0 To gridsize
		For y = 0 To gridsize
			Select grid(x,y)
				Case 1
					Color 255,0,0
					Rect x*tilesize,y*tilesize,tilesize+1,tilesize+1
			End Select
			Color 255,255,255
			Rect x*tilesize,y*tilesize,tilesize+1,tilesize+1,False
		Next
	Next
End Function

Function UpdateMouse()
	mx = MouseX()/tilesize
	my = MouseY()/tilesize
	If mx <= gridsize And my <= gridsize
		If MouseHit(1)
			If grid(mx,my) = 0
				DrawColor = 1
			Else
				DrawColor = 0
			EndIf
		EndIf
		If MouseDown(1)
			grid(mx,my) = drawcolor
			UpdateIcon(mx,my)
		EndIf
		If grid(mx,my) = 1
			Color 255,255,0
		Else
			Color 128,0,0
		EndIf
		Rect mx*tilesize,my*tilesize,(x*tilesize)+tilesize,(y*tilesize)+tilesize
	EndIf
		
End Function

Function UpdateIcon(x,y)
	SetBuffer ImageBuffer(icon)
	If grid(x,y) = 1
		Color 255,0,0
	Else
		Color 0,0,0
	EndIf
	Plot x,y
	
	SetBuffer BackBuffer()
End Function

Function DrawIcon()
	DrawImage icon,gridsize*(tilesize+1),50
End Function



H&K(Posted 2006) [#3]
In what sence do a backgrond grid?

If you simply mean a guide grind
Loop the number of Horizontal gides you need, for example for YNum= 0 to NumberNeeded -1
Draw the horizontal from 0,YNum*GridSquareSize to ScreenSize-1,YNum*GridSquareSize
Same for Verticle

But do this AFTER the other drawing. It is in fact a Foreground grid

Edit. Or just cut and paste the code above if you mean Tiles

I feel so mean now for not pasteing real code ;o


Gord(Posted 2006) [#4]
Thanks both. Very usefull. I tried c# at first but got no real help from a c# website.