• woodgrain effects easily simulated using embedded cylinder equations
  • eqn of cylinder: r1 = (u^2 + v^2)^0.5
  • perturb (deviate) wood growth
  • twist axis of cylinders:
  • then use mod function to simulate embedded cylinders, and map r2 size to a colour (eg. dark, light)

    eg. Code from Watt, Program 7.1, p. 248 :

    wood_grain(u,v,w:real; var r,g,b:real);
       var radius, angle: real;
       grain:integer;
    
       radius := sqrt(u*u+v*v);
       if w=0 then angle := pi / 2
              else angle := arctan(u,w);
       /* arctan evaluates arctan(u,w), but uses ingo to return
          a value betwen 0 and 2*pi */
       radius := radius + 2*sin(20*angle+v/150);
       grain := round(radius) mod 60;
       if grain < 40 then
          r := R_LIGHT; g := G_LIGHT; b := B_LIGHT;
       else
          r := R_DARK; g := G_DARK; b := B_DARK;
    end;