#include "colors.inc" // math adapted from http://mathworld.wolfram.com/Spirograph.html // original code Stefan Viljoen // adapted by DLM camera { location <00,00,80> look_at <0,0,0> } light_source { <0,0,10> color White } light_source { <0,-10,-10> color White } // these vars describe the wheels #declare radius_fixed = 13; //fixed wheel #declare radius_rotating = 4; //rotating wheel #declare spiro_offset = 8; //pen offset on rotating wheel #declare theta_max = 4*(2*pi); //upper limit for theta #declare rot = (2*pi)/360; // fraction of a revolution for each step (step size in rad) #declare theta = -rot; //radians #declare cyl_rad = 1; // radius of cyliner or sphere #declare x_scale = 1; #declare y_scale = 1; #declare z_scale = 0; //#declare z_fac = 0.0025; // coordinates #declare x_loc = 0; #declare y_loc = 0; #declare z_loc = 0; #declare x_loc_o = 0; #declare y_loc_o = 0; #declare z_loc_o = 0; #macro get_coord (theta, x_loc, y_loc) // modify params x_loc, y_loc given theta - other vars are global and don't change #declare x_loc = x_scale * ( (radius_fixed + radius_rotating) * cos(theta) -(radius_rotating + spiro_offset) *cos((radius_fixed+radius_rotating)/radius_rotating*theta)); #declare y_loc = y_scale *( (radius_fixed + radius_rotating) * sin(theta) -(radius_rotating + spiro_offset) *sin((radius_fixed+radius_rotating)/radius_rotating*theta)); #end // initial pos get_coord (theta, x_loc, y_loc) #while (theta < theta_max) #declare x_loc_o = x_loc; #declare y_loc_o = y_loc ; #declare z_loc_o = z_loc ; #declare theta = theta + rot; get_coord (theta, x_loc, y_loc) #declare z_loc = theta/theta_max*z_scale ; // cylinder line segs cylinder { ,,cyl_rad pigment { color rgb } finish { ambient rgb <0.8,0.8,0.8> } } //* // sphere sweep sphere { ,cyl_rad pigment { color rgb } finish { ambient rgb <0.8,0.8,0.8> } } //*// #end