# Desk Toy linkage { # Distance between center points of the sliders. CentDist = 2.25; # Angle of the line between the center points (initial value). Time = 0; # Height/2 and width/2 of vertical slider. Height in the maximum that # can be used without collisions. Hg = CentDist * sqrt( 2 )/2; Wd = .25; # Angle at which the tip of the vertical slider is coincident with the # top edge of the horizontal slider. ContactAng = asind( (Hg + Wd)/CentDist ); # Arrow head offset such that the sliders avoid collisions. Awd = Hg - CentDist * Cosd( ContactAng ); # Octagon "radius" and depth. OSize = 3; ODepth = .75; # Slider depth from z = 0 (top of octagon). SDepth = .25; # Slider extension above z = 0. SliderExt = .125; # Handle width and depth. HandleW = .5; HandleDepth = .25; # Handle length is CentDist * HandleLenScale + 2 * HandleW HandleLenScale = 2; # Slight offset from top of slider HandleOffset = 0.050; # Center points of the sliders as a function of the angle of the # the line between them. The variable "Time" is used as the angle # since this drives the animation. VertCt = pt( 0, CentDist * sind( Time ) ); HorzCt = pt( -CentDist * cosd( Time ), 0 ); HandleDir = vecFrom2pts( VertCt, HorzCt ); Endpt = ptScaledOffset( VertCt, HandleDir, HandleLenScale ); } # Handle { # For stick-figure animation # HandleStick = profile( EndPt, VertCt ); # setColor( HandleStick, "Green" ); HandL1 = lineOffsetFromLine( -HandleW/2, linePtVec( VertCt, HandleDir )); HandL2 = lineOffsetFromLine( HandleW/2, linePtVec( VertCt, HandleDir )); HandL3 = linePtVec( ptScaledOffset( EndPt, unitVec( HandleDir ), HandleW ), dirPerpLine( HandL1 )); HandL4 = linePtVec( ptScaledOffset( VertCt, unitVec( HandleDir ), -HandleW ), dirPerpLine( HandL1 )); HandleOutline = outlineCrv( { HandL1, HandL3, HandL2, HandL4 }, false ); Handle = extrude( HandleOutline, pt( 0, 0, SliderExt + HandleOffset ), pt( 0, 0, SliderExt + HandleOffset + HandleDepth ), true ); } # Screw heads { Plane = objTransform( flatSrf( linear, linear, 4, 4 ), sg( 1.1 ) ); HemiSph = combineShells( CubeSphere, Plane, "-", true, 0.005 ); Slot = slot( offsetAnchor( NegZOriginAnchor, -1.25, 0, 1 ), 2.5, .5, .75, 0, 10, 0, false ); # "Unit" screw head ScrewHead = combineShells( HemiSph, Slot, "-", true, 0.005 ); ScrewHeadV = objTransform( ScrewHead, sg( .125 ), txyz( ptX( VertCt ), ptY( VertCt ), SliderExt + HandleOffset + HandleDepth )); ScrewHeadH = objTransform( ScrewHead, sg( .125 ), txyz( ptX( HorzCt ), ptY( HorzCt ), SliderExt + HandleOffset + HandleDepth )); } # Knob { KnobProf = uniOpCrv( cubic, { pt( 0, 1 ), pt( .75, 1 ), pt( .75, .5), pt( .5, .5 ), pt( .5, 0 ) } ); Knob = objTransform( srfOfRevolution( Yaxis, KnobProf, "bottom" ), rx( 90 ), sg( .4 ), txyz( ptX( EndPt ), ptY( EndPt ), SliderExt + HandleOffset + HandleDepth )); } # Slider and octagon outlines. { # For stick-figure animation make the curves move, otherwise # use instance/objtransform to make the extruded surface move #VertBox = profile( pt( -Wd, ptY( VertCt ) + Hg - AWd), # pt( 0, ptY( VertCt ) + Hg ), # pt( Wd, ptY( VertCt ) + Hg - AWd ), # pt( Wd, ptY( VertCt ) - Hg + AWd ), # pt( 0, ptY( VertCt ) - Hg ), # pt( -Wd, ptY( VertCt ) - Hg + AWd ), # pt( -Wd, ptY( VertCt ) + Hg - AWd )); #HorzBox = profile( pt( ptX( HorzCt ) - Hg, 0 ), # pt( ptX( HorzCt ) - Hg + AWd, Wd ), # pt( ptX( HorzCt ) + Hg - AWd, Wd ), # pt( ptX( HorzCt ) + Hg, 0 ), # pt( ptX( HorzCt ) + Hg - AWd, -Wd ), # pt( ptX( HorzCt ) - Hg + AWd, -Wd ), # pt( ptX( HorzCt ) - Hg, 0 )); VertBox0 = profile( pt( -Wd, 0 + Hg - AWd), pt( 0, 0 + Hg ), pt( Wd, 0 + Hg - AWd ), pt( Wd, 0 - Hg + AWd ), pt( 0, 0 - Hg ), pt( -Wd, 0 - Hg + AWd ), pt( -Wd, 0 + Hg - AWd )); HorzBox0 = profile( pt( -CentDist - Hg, 0 ), pt( -CentDist - Hg + AWd, Wd ), pt( -CentDist + Hg - AWd, Wd ), pt( -CentDist + Hg, 0 ), pt( -CentDist + Hg - AWd, -Wd ), pt( -CentDist - Hg + AWd, -Wd ), pt( -CentDist - Hg, 0 )); Oct = outlineCrv( array( lineVertical( -OSize ), linePtVec( pt( -4./3. * OSize, 0 ), vec(1,1)), lineHorizontal( Osize ), linePtVec( pt( 4./3. * OSize, 0 ), vec(1,-1)), lineVertical( OSize ), linePtVec( pt( 4./3. * OSize, 0 ), vec(1,1)), lineHorizontal( -Osize ), linePtVec( pt( -4./3. * OSize, 0 ), vec(1,-1))), false ); } # Slider and block solids { VSlider = extrude( reverseObj( VertBox0 ), pt( 0, 0, SliderExt ), pt( 0, 0, -SDepth ), true ); HSlider = extrude( reverseObj( HorzBox0 ), pt( 0, 0, SliderExt ), pt( 0, 0, -SDepth ), true ); # Use objtransform if you want to render... VSliderI = instance( VSlider, ty( ptY( VertCt ) ) ); VSliderO = objTransform( VSlider, ty( ptY( VertCt ) ) ); HSliderI = instance( HSlider, tx( ptX( HorzCt ) + CentDist ) ); HSliderO = objTransform( HSlider, tx( ptX( HorzCt ) + CentDist ) ); Block = extrudeDir( reverseObj( Oct ), vec( 0, 0, -ODepth ), true ); HSlot = slot( objtransform( NegZOriginAnchor, tx( -1.25 * OSize )), 2.5 * OSize, Wd*2, SDepth, 0, 0, 0, false ); VSlot = slot( objtransform( NegZOriginAnchor, rz(90), ty( -1.25 * OSize )), 2.5 * OSize, Wd*2, SDepth + .005, 0, 0, 0, false ); sh1 = combineSHells( Block, HSlot, "-" ); BlockShell = combineSHells( Sh1, VSlot, "-" ); } # Attributes { setColor( VSLiderI, "Bronze" ); setColor( HSLiderI, "Bronze" ); setColor( VSLiderO, "Bronze" ); setColor( HSLiderO, "Bronze" ); setColor( BlockShell, color( 120, 50, 15 )); setColor( ScrewHeadV, "Silver" ); setColor( ScrewHeadH, "Silver" ); setColor( Knob, "Wheat" ); setColor( Handle, "LightGrey" ); setSq( VSLiderO, "Mirror" ); setSq( HSLiderO, "Mirror" ); setSq( ScrewHeadV, "Mirror" ); setSq( ScrewHeadH, "Mirror" ); setSq( BlockShell, "Wood1" ); setSq( Knob, "Porcelain" ); setTexture( BlockShell, "wood_grain1.rle" ); } # Don't use textures for animation. Takes too long, etc. #remAttr( BlockShell, "texture" ); #setColor( BlockShell, "Tan" ); ToyGroup = group( BlockShell, Handle, VSliderO, HSliderO, Knob, ScrewHeadV, ScrewHeadH ); # Transform group to position on "display table" model Toy = objTransform( ToyGroup, tz( Odepth), sg( 1/3.0 ));