Spectra (Spectra256)

Discussion about writing code for Inkscape.
rosros
Posts: 68
Joined: Fri Aug 24, 2007 12:54 am

Spectra (Spectra256)

Postby rosros » Wed Aug 10, 2011 6:27 pm

It's a small gradient creator/editor I wrote in python a few years ago.
I have made a few minor corrections. Only "map" gradients are supported.
http://rosros-3.deviantart.com/art/Spectra256-252042986
Inkscape can import gimp gradients (ggr). I wrote most of the code for ggr export,
and I might add this to Spectra256.
HTH

~suv
Posts: 2272
Joined: Sun May 10, 2009 2:07 am

Re: Spectra (Spectra256)

Postby ~suv » Wed Aug 10, 2011 7:40 pm

rosros wrote:I wrote most of the code for ggr export, and I might add this to Spectra256.
That would make it an interesting helper tool for Inkscape :)

(BTW - the default INI file for linux in the archive has the wrong name and can't be found by Spectra256a.pyw

Code: Select all

$ python -V
Python 2.6.7
$ python Spectra256a.pyw
Traceback (most recent call last):
  File "Spectra256a.pyw", line 910, in <module>
    myapp = MyApp()
  File "Spectra256a.pyw", line 115, in __init__
    inifile = open(os.getcwd() + os.sep + "spectra256-linux.ini")
IOError: [Errno 2] No such file or directory: '/tmp/test/spectra256_by_rosros_3-d4625m2/spectra256-linux.ini'
$

Code: Select all

$ cp spectra255-linux.ini spectra256-linux.ini
helps. Your tool is also usable on osx, not just linux ;-) )

~suv
Posts: 2272
Joined: Sun May 10, 2009 2:07 am

Re: Spectra (Spectra256)

Postby ~suv » Wed Aug 10, 2011 7:53 pm

From the Help text:
3. GENERATION AND EDITING OF GRADIENTS
Any well-formed formula (in Python) is acceptable;
the main parameters/variables to be used are:

yR the red color component, integer from 0 to 255
yG the green color component, integer from 0 to 255
yB the blue color component, integer from 0 to 255
x the "step" of the gradient, from 0 to 255

Many example formulas are provided.
Admittedly, I didn't spend much time searching - any hints where to find the mentioned examples of formulas for gradient maps?

rosros
Posts: 68
Joined: Fri Aug 24, 2007 12:54 am

Re: Spectra (Spectra256)

Postby rosros » Wed Aug 10, 2011 8:13 pm

I have added a few formulas and gradients. The program should work with minor corrections on all systems that run python;
I have only WXP and Linux for testing.

~suv
Posts: 2272
Joined: Sun May 10, 2009 2:07 am

Re: Spectra (Spectra256)

Postby ~suv » Wed Aug 10, 2011 8:49 pm

rosros wrote:I have added a few formulas and gradients.
Thx - much appreciated :)

rosros
Posts: 68
Joined: Fri Aug 24, 2007 12:54 am

Re: Spectra (Spectra256)

Postby rosros » Tue Aug 16, 2011 1:14 am

I have added the code to support the ggr format; which is now available both for import and for export (opening and saving).
The internal representation of the gradient is a list of 256 4-color (RGBA) tuples; when saving to 'map' the A component is discarded. When saving to ggr, there is a limited amount of simplification (in order to avoid having always 256-segment ggr gradients); unwanted nodes can be deleted on inkscape canvas too.

~suv
Posts: 2272
Joined: Sun May 10, 2009 2:07 am

Re: Spectra (Spectra256)

Postby ~suv » Tue Aug 16, 2011 2:00 am

Having trouble getting the latest version to work properly: loaded formulas do not auto-update (some of the provided samples in 'formulas255' seem to completely fail, some can be updated by reselecting the RGB colorspace; HSV colorspace completely fails with an error message [1]) - using python 2.6.7 on Mac OS X 10.5.8 (started on the command line with 'python Spectra256c.pyw').

[1]error message when selecting HSV from the 'Color Space' menu:

Code: Select all

$ python --version
Python 2.6.7
$ python Spectra256c.pyw
Exception in Tkinter callback
Traceback (most recent call last):
  File "/Volumes/green/mp-inkscape/with-a-long-long-long-directory-name/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk/Tkinter.py", line 1410, in __call__
    return self.func(*args)
  File "Spectra256c.pyw", line 489, in colorspaceHSV
    self.updateScreen()
  File "Spectra256c.pyw", line 1004, in updateScreen
    rdpoint0, grpoint0, blpoint0 = rgb_to_hsv(rd/255.0, gr/255.0, bl/255.0)
NameError: global name 'rgb_to_hsv' is not defined


rosros
Posts: 68
Joined: Fri Aug 24, 2007 12:54 am

Re: Spectra (Spectra256)

Postby rosros » Tue Aug 16, 2011 2:09 am

I have fixed the 'rgb_to_hsv' matter and also checked some formulas. It now works correctly in my systems (Linux and WXP).

rosros
Posts: 68
Joined: Fri Aug 24, 2007 12:54 am

Re: Spectra (Spectra256)

Postby rosros » Tue Aug 23, 2011 7:07 pm

Now the svg gradient import works (in version 20110823); one can save an Inkscape gradient in ggr format for use in The Gimp (or for re-import in Inkscape).

rosros
Posts: 68
Joined: Fri Aug 24, 2007 12:54 am

Spectra V. 20130513

Postby rosros » Mon May 13, 2013 5:02 pm

Main updates:
User:
Colorspaces: RGB, HSV, RYB (Itten's), CMY, CMYK
Palettes: generation and modification, new formulas for
generation (complementary, triadic and tetradic), HTML color
chart generation, sorting of colors
Palettes and gradients: saving with 'colordistance' to reduce
the number of colors.
Programming:
Removed class structure, changed geometry manager to
tkinter pack, removed dependencies.
https://sourceforge.net/projects/spectrag/
rosros

Lazur
Posts: 4717
Joined: Tue Jun 14, 2016 10:38 am

Re: Spectra (Spectra256)

Postby Lazur » Mon May 13, 2013 5:16 pm

Looks interesting, haven't checked this topic before.
How can non-linear gimp gradients be exported to inkscape's svg ones?

rosros
Posts: 68
Joined: Fri Aug 24, 2007 12:54 am

Re: Spectra (Spectra256)

Postby rosros » Mon May 13, 2013 5:35 pm

If color segments are linear only in svg gradients, one could save the gradient in Spectra
as a map gradient (255 nodes), then open it and re-save it as Gimp gradient for
direct drag and drop on Inkscape canvas.
The number of steps (nodes) can be reduced by increasing the colordistance.
rosros

Lazur
Posts: 4717
Joined: Tue Jun 14, 2016 10:38 am

Re: Spectra (Spectra256)

Postby Lazur » Tue May 14, 2013 1:30 am

I was thinking for the opposite way.
Svg allows linear interpolation between colours, but in gimp there are options of others.
There was a small discussion on that:

http://www.inkscapeforum.com/viewtopic.php" onclick="readonly();return false;"download/file822c.png" class="postimage" alt="Image" />

Not that I found where that menu was in gimp, but I would draw gradients to add some depth to the objects, like, on these cylinders:

Image