| 1 | 
greg | 
1.1 | 
/* Copyright (c) 1986 Regents of the University of California */ | 
| 2 | 
  | 
  | 
 | 
| 3 | 
  | 
  | 
#ifndef lint | 
| 4 | 
  | 
  | 
static char SCCSid[] = "$SunId$ LBL"; | 
| 5 | 
  | 
  | 
#endif | 
| 6 | 
  | 
  | 
 | 
| 7 | 
  | 
  | 
/* | 
| 8 | 
  | 
  | 
 *  p_func.c - routine for procedural patterns. | 
| 9 | 
  | 
  | 
 * | 
| 10 | 
  | 
  | 
 *     4/8/86 | 
| 11 | 
  | 
  | 
 */ | 
| 12 | 
  | 
  | 
 | 
| 13 | 
  | 
  | 
#include  "ray.h" | 
| 14 | 
  | 
  | 
 | 
| 15 | 
  | 
  | 
/* | 
| 16 | 
  | 
  | 
 *      A procedural pattern can either be a brightness or a | 
| 17 | 
  | 
  | 
 *  color function.  A brightness function is given as: | 
| 18 | 
  | 
  | 
 * | 
| 19 | 
  | 
  | 
 *      modifier brightfunc name | 
| 20 | 
  | 
  | 
 *      2+ bvarname filename xf | 
| 21 | 
  | 
  | 
 *      0 | 
| 22 | 
  | 
  | 
 *      n A1 A2 .. | 
| 23 | 
  | 
  | 
 * | 
| 24 | 
  | 
  | 
 *  A color function is given as: | 
| 25 | 
  | 
  | 
 * | 
| 26 | 
  | 
  | 
 *      modifier colorfunc name | 
| 27 | 
  | 
  | 
 *      4+ rvarname gvarname bvarname filename xf | 
| 28 | 
  | 
  | 
 *      0 | 
| 29 | 
  | 
  | 
 *      n A1 A2 .. | 
| 30 | 
  | 
  | 
 * | 
| 31 | 
  | 
  | 
 *  Filename is the name of the file where the variable definitions | 
| 32 | 
  | 
  | 
 *  can be found.  The list of real arguments can be accessed by | 
| 33 | 
  | 
  | 
 *  definitions in the file.  The xf is a transformation | 
| 34 | 
  | 
  | 
 *  to get from the original coordinates to the current coordinates. | 
| 35 | 
  | 
  | 
 */ | 
| 36 | 
  | 
  | 
 | 
| 37 | 
  | 
  | 
 | 
| 38 | 
  | 
  | 
p_bfunc(m, r)                   /* compute brightness pattern */ | 
| 39 | 
  | 
  | 
register OBJREC  *m; | 
| 40 | 
  | 
  | 
RAY  *r; | 
| 41 | 
  | 
  | 
{ | 
| 42 | 
  | 
  | 
        extern double  varvalue(); | 
| 43 | 
  | 
  | 
        extern int  errno; | 
| 44 | 
  | 
  | 
        double  bval; | 
| 45 | 
  | 
  | 
        register char  **sa; | 
| 46 | 
  | 
  | 
 | 
| 47 | 
  | 
  | 
        setfunc(m, r); | 
| 48 | 
  | 
  | 
 | 
| 49 | 
  | 
  | 
        sa = m->oargs.sarg; | 
| 50 | 
  | 
  | 
 | 
| 51 | 
  | 
  | 
        if (m->oargs.nsargs < 2) | 
| 52 | 
  | 
  | 
                objerror(m, USER, "bad # arguments"); | 
| 53 | 
  | 
  | 
        if (!vardefined(sa[0])) | 
| 54 | 
  | 
  | 
                loadfunc(sa[1]); | 
| 55 | 
  | 
  | 
        errno = 0; | 
| 56 | 
  | 
  | 
        bval = varvalue(sa[0]); | 
| 57 | 
  | 
  | 
        if (errno) { | 
| 58 | 
  | 
  | 
                objerror(m, WARNING, "compute error"); | 
| 59 | 
  | 
  | 
                return; | 
| 60 | 
  | 
  | 
        } | 
| 61 | 
  | 
  | 
        scalecolor(r->pcol, bval); | 
| 62 | 
  | 
  | 
} | 
| 63 | 
  | 
  | 
 | 
| 64 | 
  | 
  | 
 | 
| 65 | 
  | 
  | 
p_cfunc(m, r)                   /* compute color pattern */ | 
| 66 | 
  | 
  | 
register OBJREC  *m; | 
| 67 | 
  | 
  | 
RAY  *r; | 
| 68 | 
  | 
  | 
{ | 
| 69 | 
  | 
  | 
        extern double  varvalue(); | 
| 70 | 
  | 
  | 
        extern int  errno; | 
| 71 | 
  | 
  | 
        COLOR  cval; | 
| 72 | 
  | 
  | 
        register char  **sa; | 
| 73 | 
  | 
  | 
 | 
| 74 | 
  | 
  | 
        setfunc(m, r); | 
| 75 | 
  | 
  | 
 | 
| 76 | 
  | 
  | 
        sa = m->oargs.sarg; | 
| 77 | 
  | 
  | 
 | 
| 78 | 
  | 
  | 
        if (m->oargs.nsargs < 4) | 
| 79 | 
  | 
  | 
                objerror(m, USER, "bad # arguments"); | 
| 80 | 
  | 
  | 
        if (!vardefined(sa[0])) | 
| 81 | 
  | 
  | 
                loadfunc(sa[3]); | 
| 82 | 
  | 
  | 
        errno = 0; | 
| 83 | 
  | 
  | 
        setcolor(cval, varvalue(sa[0]), | 
| 84 | 
  | 
  | 
                        varvalue(sa[1]), | 
| 85 | 
  | 
  | 
                        varvalue(sa[2])); | 
| 86 | 
  | 
  | 
        if (errno) { | 
| 87 | 
  | 
  | 
                objerror(m, WARNING, "compute error"); | 
| 88 | 
  | 
  | 
                return; | 
| 89 | 
  | 
  | 
        } | 
| 90 | 
  | 
  | 
        multcolor(r->pcol, cval); | 
| 91 | 
  | 
  | 
} |