Manipulating individual tiles in an SVG pattern -


i'm trying create interactive grid web game (html, js, etc.), in every cell should change it's fill on hover/click. need both regular square grid, , triangular grid. want vector based scale nicely fit different screen sizes. thought easiest way create pattern , fill on rectangle. code have far:

<pattern id="basetile" width="10" height="10" patternunits="userspaceonuse"> <path id="tile" d="m 0,0 l 0,10 10,10 10,0 z" fill="none" stroke="gray" stroke-width="1"/> </pattern> 

for square, , triangular grid:

<pattern id="basetile" width="10" height="10" patternunits="userspaceonuse"> <path d="m 5,0 l 10,2.5 10,7.5 5,10 0,7.5 0,2.5 z" fill="none" stroke="gray" stroke-width=".1" /> <path d="m 5,0 l 5,10" fill="none" stroke="gray" stroke-width=".1" /> <path d="m 0,2.5 l 10,7.5" fill="none" stroke="gray" stroke-width=".1" /> <path d="m 0,7.5 l 10,2.5" fill="none" stroke="gray" stroke-width=".1" /> <path d="m 0,0 l 0,2.5 m 0,7.5 l 0,10" fill="none" stroke="gray" stroke-width=".1" /> <path d="m 10,0 l 10,2.5 m 10,7.5 l 10,10" fill="none" stroke="gray" stroke-width=".1" /> </pattern> 

they produce grids need, don't know how target each cell individually. i'm guessing since i've found no information on this, it's not possible, , other solution other should used. ideas?

edit: want able cycle through different fills on mouse click. square grid, i'm using code found here: http://bl.ocks.org/bunkat/2605010 triangular lattice, have absolutely no idea begin. that's why thought of .

ps: should add have no programming experience, i'm trying make nonogram game teach myself javascript.

patterns purely decorative. targetting single tile within pattern targetting single colour within gradient. better not think them distinct "tiles", , instead think of sheet of repeating wallpaper.

so do? well, going need distinct element each piece want able manipulate. since same, you'll want use <use> elements repeat graphics. you'll need bit of math figure out how position triangles right, no worse had figure out pattern. of course easiest create elements loop in js script, although hard code original elements in <defs> section.

moreover, don't specify what want individual cells. if going changing appearance, might remember can set styles on <use> element , these inherited re-used graphics. if don't set fill/stroke directly, can change them styling <use>, instead of having separate, differently coloured template swap in.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -