Grid with single index

1

Hello, what's the best way to make a grid by Javascript and HTML? I need to be able to draw or change the area color of each blank space. I made it that way but it does not answer because when I try to change the color of a single square it ends up changing either the entire line or the entire column.

for(var i = 0;i < linha;i++) {
    for (var n = 0;n < coluna;n++) {
        grid_x[i] = i * 40;
        grid_y[n] = n * 40;
        res_x[i] = i * 40;
        res_y[n] = n * 40;
        c[i] = false * i
        dRs(grid_x[i],grid_y[n],grid_w,grid_h,1,"#747474",c[i])
    }
}
function dRs(x,y,w,h,l,s,c) {
    context.beginPath();
    context.lineWidth= l;
    context.strokeStyle= s;
    context.rect(x,y,w,h);      
    context.stroke();
}
    
asked by anonymous 02.08.2014 / 14:52

1 answer

1

Deny if you intend to create a game I suggest you look for an engine to help you, because there are several other issues that not only change the color or perform an event.

The jsgamesoup is very simple and full of examples. may be an initial starting point.

Here's a simple example of how to resolve your issue:

mudacor grid

Remembering that you work with events, onclick, and for each change you need to paint again.

engine jsgamesoup

    
30.09.2014 / 14:07