#include "colors.inc" #include "textures.inc" //default for plot_curve if nothing else is given in the code #macro curve(xp) 1 #end // good defaults #declare VectorScale0 = 1; #declare VectorThickness0 = 0.1; #declare VectorLabelScale0=2.5; #declare BarScale0 = 1.0; #declare BarZoom0 = 1.0; #declare BarLabelZoom0=1.0; #declare VectorScale = VectorScale0; #declare VectorThickness = VectorThickness0; #declare VectorLabelColor = White; #declare VectorLabelScale = VectorLabelScale0; #declare BarScale = BarScale0; #declare BarZoom = BarZoom0; #declare BarLabelZoom = BarLabelZoom0; #macro draw_bar(bottom,height,the_color,the_label) object { union { cylinder { <0,0,0>,<0,height*BarScale+0.001,0>,0.2 pigment {the_color}} text { ttf "crystal" the_label 0.1, 0 pigment { the_color } translate <0,-1,0> scale BarLabelZoom} } scale BarZoom translate bottom } #end #macro draw_hspring(x1,x2,y1,rad,thick) #local xs=0; #local rs=rad; #if (x1 > x2) #local temp=x1; #local x1=x2; #local x2=temp; #end #local dx=(x2-x1)/(rad*500); #local f=5/(x2-x1); #while (xs <= (x2-x1)) #local yp=rs*cos(2*pi*f*xs); #local zp=rs*sin(2*pi*f*xs); sphere {,thick pigment{ color Silver}} #local xs=xs+dx; #end #end #macro draw_vspring(y1,y2,x1,rad,thick) #local ys=0; #local rs=rad; #if (y1 > y2) #declare temp=y1; #declare y1=y2; #declare y2=temp; #end #local dy=(y2-y1)/(rad*500); #local f=5/(y2-y1); #while (ys <= (y2-y1)) #local xp=rs*cos(2*pi*f*ys); #local zp=rs*sin(2*pi*f*ys); sphere {,thick pigment{ color Silver}} #local ys=ys+dy; #end #end #macro draw_rope(x1,y1,x2,y2,thick) #if (abs(x2-x1) > 0.01 | abs(y2-y1) > 0.01) cylinder { ,,0.25*thick texture {DMFWood4} } #end #end #macro real_rope(end1,end2,thick,color1,color2,amb,detail) #local delta = end2-end1; #if(abs(delta.x)>0 | abs(delta.y)>0 | abs(delta.z)>0) #local step = 0; #local stepadd = thick/detail; #local dist = sqrt(pow(delta.x,2)+pow(delta.y,2)+pow(delta.z,2)); #if(dist>1) #local ofst = pow(10,-9); #else #local ofst = pow(10,-9); #end #local rotz = degrees(atan2(delta.y+ofst,sqrt(pow(delta.x+ofst,2)+pow(delta.z+ofst,2)))); #local roty = degrees(atan2(delta.z+ofst,delta.x+ofst)); union {#while(step<=dist) #local rtheta = 360*step/(thick*2); sphere{,thick/3 pigment{color1} finish{ambient amb} rotate} sphere{,thick/3 pigment{color2} finish{ambient amb} rotate} #local step = step+stepadd; #end rotate<0,0,rotz> rotate<0,roty,0> translate end1} #end #end #macro draw_real_rope(end1,end2,thick) real_rope(end1,end2,thick,Tan,Brown,0.3,5) #end #macro draw_text(the_location,the_text,text_color,text_scale) text { ttf "crystal" the_text 0.1, 0 pigment { text_color } scale text_scale translate the_location} #end #macro draw_variable(the_location,the_variable,the_units,text_color,text_scale) #local to_str=str(the_variable,0,2) draw_text(the_location,concat(to_str," ",the_units),text_color,text_scale) #end #macro dump_variable(the_name,the_variable) #local to_str=str(the_variable,0,2) #debug concat(the_name," is ", to_str,"\n") #end #macro dv(vec_tail,the_vector,vec_color,the_label) #local the_scaled_vector = VectorScale * vlength(the_vector) * vnormalize(the_vector); #local cone_start = 0.8 * the_scaled_vector; #local cone_end = 1.2 * the_scaled_vector; #local label_pos = 1.3 * the_scaled_vector; #if (vlength(the_scaled_vector) > 0.01) cylinder {vec_tail,vec_tail+the_scaled_vector,VectorThickness pigment {vec_color}} cone { vec_tail+cone_start,5*VectorThickness vec_tail+cone_end,0 pigment {vec_color}} #local text_end = vec_tail+label_pos; draw_text(text_end,the_label,VectorLabelColor,VectorLabelScale) #end #end #macro draw_vector(vec_tail,vec_offset,vec_color,the_label) dv(vec_tail,vec_offset,vec_color,the_label) #end #macro set_vector_scale(n) #declare VectorScale = n*VectorScale0; #end #macro set_vector_thickness(n) #declare VectorThickness = n*VectorThickness0; #end #macro set_vector_label_scale(n) #declare VectorLabelScale = n*VectorLabelScale0; #end #macro set_vector_label_color(vc) #declare VectorLabelColor = vc; #end #macro set_bar_scale(n) #declare BarScale = n; #end #macro set_bar_zoom(n) #declare BarZoom = n; #end #macro set_bar_label_zoom(n) #declare BarLabelZoom = n; #end #macro plot_curve(xmin,xmax,dx,the_color,the_scale) #local xp=0; #local yp=0; #local xold = xmin; #local yold = curve(xold); #declare xp=xmin+dx; #while(xp<=xmax) #declare yp=curve(xp); cylinder {,,.1*the_scale pigment {the_color}} #declare xold=xp; #declare yold=yp; #declare xp=xp+dx; #end #end