OpenSCAD Color Library

Rainbow Color Library

Library to produce 2D array of RGB values scaled across an arbitrary size

This thing does not make a printable object. The output from this thing is primarily to demonstrate the utility of the colorArray() function. The colorArray() function produces a 2D array of RGB values that can be used in other projects.

Use

  • download the .scad file
  • move the file somewhere in your home directory: /home/MyUser/OpenSCAD/myLibraries/
  • Add the following line to one of your project files: use </home/MyUser/OpenSCAD/myLibraries/colors.scad>

Getting Help

  • use </path/to/colors.scad>
  • from within OpenScad help_colors() for a list of all modules
  • for help with a specific module help_colors("coloraArray");
  • rinse, repeat.

You are more than welcome to try and print this, but I made no attempt to make the objects properly manifold.

Aaron Ciuffo (Txoof)
Reach me at google mail: aaron dot ciuffo
https://www.thingiverse.com/txoof/about
released under GPL V3.0

Latest versions can be found at github:
https://github.com/txoof/OpenSCADColors

User Facing Functions

function colorArray

create an X by Y array of RGB values

accepts:

  • columns (integer): divisions of color wheel
  • rows (integer): number of itterations from origin
  • scaled (boolean): when true, return a value scaled by
    distance from origin
    returns:
  • X by Y array of RGB values

example:

  • myArray = colorArray(3, 3, scaled = false);
    for (row=[0:len(myArray)-1]) { //three iterations
    echo(colorArray[row]);
    }

  • ECHO: [[1, 0, 0], [1, 0, 0], [1, 0, 0]]
  • ECHO: [[0, 1, 0], [0, 1, 0], [0, 1, 0]]
  • ECHO: [[0, 0, 1], [0, 0, 1], [0, 0, 1]]

function chord

calculates chord length given a radius and angle

accepts:

  • r (real): radius of circle
  • angle (real): angle of segement
    returns:
  • length of chord (real)

example:

  • echo(chord(r = 10, angle = 60));
  • ECHO: 5.17638

function RGB

returns RGB value as 1D array of reals value between 0 an 1

accepts:

  • angle (real)
    returns:
  • RGB (array of real)

example:

  • echo(RGB(30))
  • ECHO: [1, 0.546691, 0]

funciton RGBScale

returns RGB value as 1D array of reals scaled by distance from origin (0-1)

accepts:

  • angle (real)
  • r (real): radius between 0-1
    returns:
  • RGB (array of real)

example:

  • echo(RGBScale(55, 1));
  • ECHO: [1, 0.941923, 0]
  • echo(RGBScale(55, 0.5));
  • ECHO: [1, 0.970961, 0.5]
  • echo(RGBScale(55, 0));
  • ECHO: [1, 1, 1]

Test Modules

module wheel

draws a color wheel

accepts:

  • segments (integer): number of segments to divide the wheel into
  • rings (integer): number of itterations
  • scaled (boolean): true - use color scaling
  • pixel (1D array): [x dimension, y dimension, z dimension] of elements

module objDemo

draws an array of objects using the colorArray() function to provide colors

accepts:

  • rows (integer): number of rows of objects
  • columns (integer): number of columns of objects
  • size (real): radius of objects
  • minQual (integer): minimum quality value to use
  • step (integer): steps to increase quality by
  • scaled (boolean): when true, use color scaling

module demoCyl

draw a hollow cylinder using the colorArray() function

accepts:

  • segments (integer): number of segments to divde cylinder into
  • layers (integer): number of layers
  • r (real): radius of cylinder
  • scaled (boolean): when true use color scaling