/******************************************************************* * RESISTORS include file for the Persistance of Vision Ray Tracer * * part of the ELECTRONICS set * ******************************************************************* * * Created by Mark Hanford, December 2001 * * * This is a simple resistor * * Resistor(Band1, Band2, Band3, Tolerance, A, B, C) * macro to draw a basic resistor. The values [0..9] provided for * Band1, Band2 and Band3 determine the colour of the stripes. * Tolerance [5 | 10] determines the colour of the tolerance band. * Negative values will hide the stripes altogether. * * * Dependencies * electronics.inc - mainly for some constants * connections.inc - -to put the wires into the resistors * * Optimisation options: * There's not much to optimise on this object yet, this may change... * * Base units: millimetres * Resistor Length - 7.0mm *************************************************************************/ /******************************************** * Check for and set some default variables * ********************************************/ #ifdef(View_POV_Include_Stack) #debug "including resistors.inc\n" #end #ifdef (MH_Resistors_Inc_Temp) //do nothing #else #declare MH_Resistors_Inc_Temp=version; #include "electronics.inc" /************ * Textures * ************/ #declare F_ResistorStripe= finish{phong 1} #declare T_Resistor = texture{pigment{color rgb<0.200000, 0.200000, 0.710000>} normal{bumps 0.1 scale 0.1}} #declare T_Resistor0 = texture{pigment{color rgb<0.300000, 0.300000, 0.300000>} finish{F_ResistorStripe}} #declare T_Resistor1 = texture{pigment{color rgb<0.647059, 0.164706, 0.164706>} finish{F_ResistorStripe}} #declare T_Resistor2 = texture{pigment{color rgb<1.000000, 0.000000, 0.000000>} finish{F_ResistorStripe}} #declare T_Resistor3 = texture{pigment{color rgb<1.000000, 0.500000, 0.000000>} finish{F_ResistorStripe}} #declare T_Resistor4 = texture{pigment{color rgb<1.000000, 1.000000, 0.000000>} finish{F_ResistorStripe}} #declare T_Resistor5 = texture{pigment{color rgb<0.000000, 1.000000, 0.000000>} finish{F_ResistorStripe}} #declare T_Resistor6 = texture{pigment{color rgb<0.000000, 0.000000, 1.000000>} finish{F_ResistorStripe}} #declare T_Resistor7 = texture{pigment{color rgb<0.309804, 0.184314, 0.309804>} finish{F_ResistorStripe}} #declare T_Resistor8 = texture{pigment{color rgb<0.700000, 0.700000, 0.700000>} finish{F_ResistorStripe}} #declare T_Resistor9 = texture{pigment{color rgb<1.000000, 1.000000, 1.000000>} finish{F_ResistorStripe}} #declare T_Resistor05per = texture{pigment{color rgb<0.800000, 0.498039, 0.196078>} finish{F_ResistorStripe}} #declare T_Resistor10per = texture{pigment{color rgb<0.900000, 0.910000, 0.980000>} finish{F_ResistorStripe}} /************* * Constants * *************/ #declare ResistorLength = 7.5; #declare Re = 6.5; /**************** * The Resistor * ****************/ #macro Resistor(Value, Tolerance, Type, PinPitch, Depth) #local Band1 = Value.x; #local Band2 = Value.y; #local Band3 = Value.z; #local ResHalfLength = ((Re+4)/2); #local ResMaxRadius = 2.3/2; #local ResMinRadius = 1.8/2; //where the stripes start and end #local Stripe1s = 0.15; #local Stripe1e = 0.20; #local Stripe2s = 0.25; #local Stripe2e = 0.32; #local Stripe3s = 0.37; #local Stripe3e = 0.42; #local Stripe4s = 0.75; #local Stripe4e = 0.79; #local Jitter = 0.01; #switch (Band1) #case (0) #local Stripe1col = T_Resistor0; #break #case (1) #local Stripe1col = T_Resistor1; #break #case (2) #local Stripe1col = T_Resistor2; #break #case (3) #local Stripe1col = T_Resistor3; #break #case (4) #local Stripe1col = T_Resistor4; #break #case (5) #local Stripe1col = T_Resistor5; #break #case (6) #local Stripe1col = T_Resistor6; #break #case (7) #local Stripe1col = T_Resistor7; #break #case (8) #local Stripe1col = T_Resistor8; #break #case (9) #local Stripe1col = T_Resistor9; #break #else #local Stripe1col = T_Resistor; #break #end #switch (Band2) #case (0) #local Stripe2col = T_Resistor0; #break #case (1) #local Stripe2col = T_Resistor1; #break #case (2) #local Stripe2col = T_Resistor2; #break #case (3) #local Stripe2col = T_Resistor3; #break #case (4) #local Stripe2col = T_Resistor4; #break #case (5) #local Stripe2col = T_Resistor5; #break #case (6) #local Stripe2col = T_Resistor6; #break #case (7) #local Stripe2col = T_Resistor7; #break #case (8) #local Stripe2col = T_Resistor8; #break #case (9) #local Stripe2col = T_Resistor9; #break #else #local Stripe2col = T_Resistor; #break #end #switch (Band3) #case (0) #local Stripe3col = T_Resistor0; #break #case (1) #local Stripe3col = T_Resistor1; #break #case (2) #local Stripe3col = T_Resistor2; #break #case (3) #local Stripe3col = T_Resistor3; #break #case (4) #local Stripe3col = T_Resistor4; #break #case (5) #local Stripe3col = T_Resistor5; #break #case (6) #local Stripe3col = T_Resistor6; #break #case (7) #local Stripe3col = T_Resistor7; #break #case (8) #local Stripe3col = T_Resistor8; #break #case (9) #local Stripe3col = T_Resistor9; #break #else #local Stripe3col = T_Resistor; #break #end #switch (Tolerance) #case (5) #local Stripe4col = T_Resistor05per; #break #case (10) #local Stripe4col = T_Resistor10per; #break #else #local Stripe4col = T_Resistor; #break #end #local T_ResistorStripes= texture{ gradient y texture_map{ [0.000000 T_Resistor] [Stripe1s-Jitter T_Resistor] [Stripe1s Stripe1col] [Stripe1e Stripe1col] [Stripe1e+Jitter T_Resistor] [Stripe2s-Jitter T_Resistor] [Stripe2s Stripe2col] [Stripe2e Stripe2col] [Stripe2e+Jitter T_Resistor] [Stripe3s-Jitter T_Resistor] [Stripe3s Stripe3col] [Stripe3e Stripe3col] [Stripe3e+Jitter T_Resistor] [Stripe4s-Jitter T_Resistor] [Stripe4s Stripe4col] [Stripe4e Stripe4col] [Stripe4e+Jitter T_Resistor] [1.000000 T_Resistor] } scale <1, 6.5, 1> translate 3.25*y } // the body of the resistor #local ResistorBody= intersection{ lathe{ cubic_spline 8, < 0.0, 20.00>, < 0.0, ResHalfLength>, //furthest point , //peak , , , //peak < 0.0, -ResHalfLength>, //nearest point < 0.0, -20.00> } box{<-2*ResMaxRadius, -(Re/2)-0.3, -2*ResMaxRadius>, <2*ResMaxRadius, (Re/2)+0.3, 2*ResMaxRadius>} texture{T_ResistorStripes} rotate 90*x } // Work out which way up the resistor is, and which wire mount to use // ------------------------------------------------------------------ // there are four types of resistor: // 0 - resistor is horizontal with no wire // 1 - resistor is horizontal with a straight wire // 2 - resistor is horizontal with a bent wire // 3 - resistor is horizontal with a recurved wire #switch (Type) #case (0) object{ ResistorBody translate ResistorLength/2*z } #break #case (1) union{ object{ResistorBody} object{WireStraight(PinPitch)} translate ResistorLength/2*z } #break #case (2) union{ object{ResistorBody} object{WireBent(PinPitch, Depth)} translate ((PinPitch/2))*z } #break #case (3) union{ object{ResistorBody} object{WireRecurve(PinPitch, Depth)} rotate 90*x translate ResistorLength/2*y } #break #end #end /************* * Finish up * *************/ version=MH_Resistors_Inc_Temp; #end