Tuesday, January 17, 2012

Conical Gradients in Inkscape

Let's Draw a Colour Wheel in Inkscape

Inkscape doesn't yet (circa Jan 2012) support conical gradients, but it is getting some sexy love in this area, hopefully soon. Until then, this article shows one way to do it. Look here for an alternative.

Recipe

1. Create a circle and unset its colour.


Click the big question mark ( ? ) to unset the selected object's colour:



2. Duplicate the circle with ctrl-d (Edit | Duplicate), move it aside and using the Circle tool (F5), modify its arc to be (360 / 255) 1.4117 degrees. The arc End textbox will show 1.4112 but it holds the higher precision number internally, I believe.



3. Move the rotation point of the circle to the top left hand corner.  Use the select and transform tool (F1) and click the arc twice (not double-click) to enable rotation mode. Drag the cross at the centre of the arc to the top left hand corner.




4. Open the Clones dialog (Edit | Clone | Create Tiled Clones...)



Symmetry Tab:

5. Choose P1: simple translation and set the  Rows, columns to 1, 255



Shift Tab:

6. Check the per column Exclude tile box.




Scale Tab: No scale

Rotation Tab:

7. Set the per column rotation to 1.4117 degrees. It will show you that it's only 1.4 degrees, but it uses more precision behind the scenes, apparently.



Blur & Opacity Tab: No Blur or fade.

Color Tab:

8. Set the per column Hue percentage to (100 / 255) 0.4 %.  (Percent seems to be a weird unit for this setting.) The formula of
100 / 255 is percentage-points / hue-points.


9. Click the coloured rectangle beside the Initial color label and set H, S, L, A to 0, 255, 128, 255.



Trace Tab: No Trace.

10. Click the Create button and you should see:



Notice the spiral artefacts around the edges and particularly along the vertical line between dark blue and purple. We will group and blur these cloned circle segments (arcs) to remove that distortion.

If you forgot to set the rotation point in step 3, you will instead see:



Use ctrl-z to undo and go back and do step 3.

11. Using the select and rotation tool (F1), draw a box around the whole colour-wheel to select all of the clones. Use ctrl-g to group them.

12. Using the blur setting on the Fill and Stroke dialog (ctrl-shift-f), set the blur to 2.



Which results in:



If you're happy with that then you can stop here, but if you would like a crisp edge to your colour wheel instead of the fuzz the blur created then we need to clip it with the black circle.

13. Select the black circle and make sure it is the top-most object on the layer by pressing the Home key (Object | Raise to top).

14. With the black circle still selected, shift+click the grouped colour wheel and open the Align and Distribute dialog (with ctrl+shift+a or Object | Align and Distribute) and click the Center on vertical axis button and then the Center on horizontal axis button.

 
 
Once the two are aligned, you can just see the blurred colours beneath the black circle:



15. Clip the colour wheel with the black circle by choosing Object | Clip | set.

Done! And your colour wheel should look like this:


Not too shabby. Enjoy. :-)

5 comments:

  1. How about using this technique to create a aluminum button. A download would be nice for this and the aluminum.

    ReplyDelete
    Replies
    1. I am having trouble picturing the look of your aluminium button (how the gradient flows), but you could approach that by setting the Hue to a grey starting colour and changing the Luminance instead of the Hue in the Color tab when creating the tiled clones.

      Delete
    2. It's all kinds of ugly, but here is a quick dabble:

      Aluminium Button Demo in Inkscape

      Delete
  2. A very useful tutorial but you need more detailed instructions especially for the the steps to create the sliver:
    1) Select the circle tool in the toolbox (or F5)
    2) Drag out a circle. Don't worry if it isn't perfect. We'll make it perfect in the next step.
    3) Object -> transform (or Shift+Ctrl+M)
    4) Click the tab that says "Scale".
    5) In the dropdown box, select px (short for pixel).
    6) Enter 250 for the width and height and click apply.
    7) Select the transform tool in the toolbox (or F1)
    8) Press Ctrl+D to duplicate the circle.
    9) In the transform dialog box, click the Move tab.
    10 Enter -550 in the box marked "Horizontal".
    11) Make sure "Relative move" is checked, then press Apply.
    12) Move your cursor over the center of the new circle.
    13) Hold ctrl and roll the wheel on your mouse toward the screen to zoom in. You can also move your cursor to the center then press the plus key.
    14) Press the circle tool in the tool box again (or F5)
    15) Move your cursor over the small white circle on the right of the large circle. It will turn red when your over it.
    16) Click and hold the left mouse button. Then drag the red circle down just slightly until the large circle is just a sliver of what is once was, then release the mouse button.
    17) Select the transform tool in the toolbox (or F1)
    18) Click on the sliver you just created.
    19) Zoom in more if needed. You should see a small black plus sign in the center of the sliver.
    20) view -> snap
    21) Click and hold the left mouse button over the small black plus sign to grab it.
    22) Drag the plus sign to the upper left of the sliver. Move it slowly near the upper left and it will snap in place.
    23) Click the silver again to select it and put it in move mode.
    24) Open the Clones dialog (Edit | Clone | Create Tiled Clones...)
    25) ...

    ReplyDelete
    Replies
    1. Thank you for your feedback. I feel that level of explanation is a bit verbose, but there might be some out there who benefit from it. I will leave it up to the good souls such as yourself to elaborate where others request such refinement.

      Instead of making the circle "just a sliver of what it once was", I used 360/255 because I was reduplicating the sliver 255 times (because of a 255 colour palette) around to make a circle. Given that I then also had to use 100/255 to work in Hue points, I should probably have just divided the circle into 100 segments in the first place. Indeed, a quick test now of doing exactly that produces an equally acceptable colour gradient wheel with much simpler numbers - 3.6 degree arc, 100 column clones with a 3.6 degree column rotation (1 row clone, no rotation), 100 hue steps at 1%, excluding tile shift, of course. A blur of 2.0 to finish. That's simpler.

      Delete