Hello developers,

I've written a thing for my game that other people might find useful. It
allows you to change the colours in an svg document.

It does so by parsing through the tree under the element you specify, and
changing all fill, stroke, and stop-color elements it finds.
It also follows any references to gradients or patterns, and clones the
nodes doing the reference.

http://otherleg.com/svg/EgColorTweaker.svg


The actual work is being done by

http://otherleg.com/svg/colorTweaker.js

with the function setLightLevel:

// Search through the specified node and its children, and multiply fill
and/or stroke by level.
// svgNode - the root node from which to change the levels
// level   - light level to set, consisting of {r:red_level, g:green_level,
b:blue_level}
//           Each level should be a number between 0 and 2, where 0 is all
black, 2 is all white, and 1 is normal.
// groupId - Set this when you're setting multiple different light levels
in the same doc.
//           Each separate lit group should be given a different groupId.
This is so that
//           gradients and patterns get cloned properly.
function setLightLevel(svgNode, level, groupId)


If you just wish to change the brightness (as I did originally) it's
actually easier to change to opacity of the group instead, and just put a
black element (or white if you want to increase the brightness) with the
same outline behind it. The third area in the example shows this. Note that
if you're changing a lot of elements to different brightnesses (as I am
with my tile-based game), it's creating an off-screen buffer for each one,
I think. Depending on what you're doing, it's probably slower than parsing
through the tree changing the colours.

Cheers,

Andrew.


[Non-text portions of this message have been removed]



------------------------------------

-----
To unsubscribe send a message to: svg-developers-unsubscr...@yahoogroups.com
-or-
visit http://groups.yahoo.com/group/svg-developers and click "edit my 
membership"
----Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/svg-developers/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/svg-developers/join
    (Yahoo! ID required)

<*> To change settings via email:
    svg-developers-dig...@yahoogroups.com 
    svg-developers-fullfeatu...@yahoogroups.com

<*> To unsubscribe from this group, send an email to:
    svg-developers-unsubscr...@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/

Reply via email to