Fred's ImageMagick Scripts



    Licensing:

    Copyright © Fred Weinhaus

    My scripts are available free of charge for non-commercial (non-profit) use, ONLY.

    For use of my scripts in commercial (for-profit) environments or non-free applications, please contact me (Fred Weinhaus) for licensing arrangements. My email address is fmw at alink dot net.

    If you: 1) redistribute, 2) incorporate any of these scripts into other free applications or 3) reprogram them in another scripting language, then you must contact me for permission, especially if the result might be used in a commercial or for-profit environment.

    Usage, whether stated or not in the script, is restricted to the above licensing arrangements. It is also subject, in a subordinate manner, to the ImageMagick license, which can be found at: http://www.imagemagick.org/script/license.php

    Please read the Pointers For Use on my home page to properly install and customize my scripts.

SPHERE


Creates a colored sphere with a combination of diffuse and specular illumination.

Download Script

last modified: December 15, 2018



USAGE: sphere [-d diameter] [-c color] [-b bgcolor] [-t theta] [-p phi] [-l lambertian] [-s specular] [-e exponent] [infile] soutfile
USAGE: sphere [-h or -help]

-d .... diameter ......... desired diameter of sphere; integer>0; default=128;
.......................... determines the width and height of the output image
-c .... color ............ desired sphere color;
.......................... Any valid IM color is allowed; default=red
-b .... bgcolor .......... background color outside sphere;
.......................... Any valid IM color is allowed; default=black
-t .... theta ............ white light azimuth angle measure counter clockwise
.......................... around the sphere from the positive x axis;
.......................... 0<=float<=360; default=135 (lighting from the northwest)
-p .... phi .............. white light altitude angle measured downward from
.......................... zenith (i.e. from out of center of sphere toward viewer);
.......................... 0<=float<=180; 0 is light source right over the center
.......................... of the sphere; default=50
-l .... lambertian ....... lambertian (diffuse) illumination amplitude; 0<=float<=1;
.......................... default=0.9
-s .... specular ......... specular illumination amplitude; 0<=float<=1;
.......................... default=0.6
-e .... exponent ......... specular lighting exponent; float>0

If infile is provided, then it will be used in place of the color. The
infile must be square and the diameter will obtained from the dimensions
of the image.

PURPOSE: To create a colored sphere with a combination of diffuse and specular illumination.

DESCRIPTION: SPHERE creates a colored sphere with a combination of diffuse and specular illumination. Lighting is from a white light source. The diffuse term is computed from the Lambertian shading model. The specular term is computed from the Blinn-Phong approximation.

ARGUMENTS:

-d diameter ... DIAMETER of the sphere. Also controls the width and height of the output image. Values are integers>0. The default=128

-c color ... COLOR is the desired color for the sphere. The default=red. Any valid IM color is allowed.
See http://imagemagick.org/script/color.php

-b bgcolor ... BGCOLOR is the background color around the outside of the sphere. The default=black. Any valid IM color is allowed.
See http://imagemagick.org/script/color.php See http://imagemagick.org/script/color.php

-t theta ... THETA is the white light azimuth angle measured counter clockwise from the positive x axis. Values are floats between 0 and 360 degrees. The default=135, which means the light is coming from the northwest.

-p phi ... PHI is the white light altitude angle measure downward from zenith (vertical) towards horizontal. Values are floats between 0 and 180 degrees. A value of zero means the light is from above the sphere. The default=50.

-l lambertian ... LAMBERTIAN is the amplitude of the diffuse lighting. Values are in the range 0<=float<=1. The default=0.9

-s specular ... SPECULAR is the amplitude of the specular lighting. Values are in the range 0<=float<=1. The default=0.6. A value of zero means not to compute the specular component.

-e exponent ... EXPONENT is the specular exponent, which controls the area of the reflective effect. Larger values means smaller areas. Values are floats>0. The default=70.

NOTE: If infile is provided, then it will be used in place of the color. The infile must be square and the diameter will obtained from the dimensions of the image.

REQUIRMENTS: IM 6.5.4-3 or higher due to the use of -compose mathematics.

THEORY: See the following: http://en.wikipedia.org/wiki/Lambertian_reflectance
http://en.wikipedia.org/wiki/Blinn–Phong_shading_model

NOTE: This script may be a little slow due to the use in part of -fx.

CAVEAT: No guarantee that this script will work on all platforms, nor that trapping of inconsistent parameters is complete and foolproof. Use At Your Own Risk.


EXAMPLES


Lambertian vs Lambertian Plus Specular

Lambertian
(diffuse)
Arguments:
-s 0

Lambertian & Specular
(diffuse & specular)
Arguments:
(defaults)



Variation On Specular Size

Arguments:
-s 0.6 -e 70

Arguments:
-s 0.4 -e 60

Arguments:
-s 0.2 -e 50



Variation On Specular Intensity

Arguments:
-s 0.6 -e 70

Arguments:
-s 0.4 -e 60

Arguments:
-s 0.2 -e 50



Variation On Background Color

Arguments:
-b black

Arguments:
-b blue

Arguments:
-b none