Vectrosity Demo: Grid

Here’s another complete script example of a dynamic grid using Vectrosity, where a GUI slider controls the pixel size of each grid square. Try it out now by dragging the slider, below.

import System.Collections.Generic;
import Vectrosity;

var gridPixels = 50;
private var gridLine : VectorLine;

function Start () {
    gridLine = new VectorLine("Grid", new List.<Vector2>(), 1.0);
    MakeGrid();
}

function OnGUI () {
    GUI.Label (Rect(10, 10, 30, 25), gridPixels.ToString());
    gridPixels = GUI.HorizontalSlider (Rect(40, 15, 590, 25), gridPixels, 5, 200);
    if (GUI.changed) {
        MakeGrid();
    }
}

function MakeGrid () {
    var numberOfGridPoints = ((Screen.width/gridPixels + 1) + (Screen.height/gridPixels + 1)) * 2;
    gridLine.Resize (numberOfGridPoints);

    var index = 0;
    for (x = 0; x < Screen.width; x += gridPixels) {
        gridLine.points2[index++] = Vector2(x, 0);
        gridLine.points2[index++] = Vector2(x, Screen.height-1);
    }
    for (y = 0; y < Screen.height; y += gridPixels) {
        gridLine.points2[index++] = Vector2(0, y);
        gridLine.points2[index++] = Vector2(Screen.width-1, y);
    }

    gridLine.Draw();
}

Get Vectrosity now >