POV-Ray : Newsgroups : povray.text.scene-files : LEGO macro Server Time
31 Oct 2024 19:27:07 EDT (-0400)
  LEGO macro (Message 1 to 1 of 1)  
From: Larry Fontaine
Subject: LEGO macro
Date: 3 Sep 1999 18:07:19
Message: <37D044FF.81A4DA0C@isd.net>
Sorry, I realize that was an HTML post before.

At leats one person wanted to see LEGO source...
While this macro models only basic blocks and no special/decorative
pieces, it's a start, and I know some people here like to look at macros

and loops, so anyway it's a 'fun' post even if you don't use it.

First of all, my rounded box macro. 12 cylinders, 8 spheres and 3 boxes
merged into a round box of any size.
usage: object { roundbox(X1,Y1,Z1,X2,Y2,Z2,R) //modifiers }
Box goes from <X1,Y1,Z1> to <X2,Y2,Z2> and has a rounding radius of R.

    #macro roundbox (X1,Y1,Z1,X2,Y2,Z2,R)
    #local T=0;
    #if (X1>X2) #declare T=X2; #declare X2=X1; #declare X1=T; #end
    #if (Y1>Y2) #declare T=Y2; #declare Y2=Y1; #declare Y1=T; #end
    #if (Z1>Z2) #declare T=Z2; #declare Z2=Z1; #declare Z1=T; #end
    merge {
       cylinder { <X1+R,Y1+R,Z1+R>,<X1+R,Y1+R,Z2-R>,R }
       cylinder { <X1+R,Y1+R,Z1+R>,<X1+R,Y2-R,Z1+R>,R }
       cylinder { <X1+R,Y1+R,Z1+R>,<X2-R,Y1+R,Z1+R>,R }
       cylinder { <X2-R,Y1+R,Z1+R>,<X2-R,Y1+R,Z2-R>,R }
       cylinder { <X1+R,Y1+R,Z2-R>,<X2-R,Y1+R,Z2-R>,R }
       cylinder { <X2-R,Y1+R,Z1+R>,<X2-R,Y2-R,Z1+R>,R }
       cylinder { <X1+R,Y1+R,Z2-R>,<X1+R,Y2-R,Z2-R>,R }
       cylinder { <X2-R,Y1+R,Z2-R>,<X2-R,Y2-R,Z2-R>,R }
       cylinder { <X1+R,Y2-R,Z1+R>,<X1+R,Y2-R,Z2-R>,R }
       cylinder { <X1+R,Y2-R,Z1+R>,<X2-R,Y2-R,Z1+R>,R }
       cylinder { <X2-R,Y2-R,Z1+R>,<X2-R,Y2-R,Z2-R>,R }
       cylinder { <X1+R,Y2-R,Z2-R>,<X2-R,Y2-R,Z2-R>,R }
       sphere { <X1+R,Y1+R,Z1+R>,R }
       sphere { <X1+R,Y1+R,Z2-R>,R }
       sphere { <X1+R,Y2-R,Z1+R>,R }
       sphere { <X1+R,Y2-R,Z2-R>,R }
       sphere { <X2-R,Y1+R,Z1+R>,R }
       sphere { <X2-R,Y1+R,Z2-R>,R }
       sphere { <X2-R,Y2-R,Z1+R>,R }
       sphere { <X2-R,Y2-R,Z2-R>,R }
       box { <X1,Y1+R,Z1+R>,<X2,Y2-R,Z2-R> }
       box { <X1+R,Y1,Z1+R>,<X2-R,Y2,Z2-R> }
       box { <X1+R,Y1+R,Z1>,<X2-R,Y2-R,Z2> }
       bounded_by { box { <X1,Y1,Z1>,<X2,Y2,Z2> } }
    } #end

And the predefined "bump", rounded off with a torus:

    #declare bump=merge {
            cylinder { <0,0,0>,<0,.2,0>,.27 }
            cylinder { <0,-.06,0>,<0,.17,0>,.3 }
            torus { .27,.03 translate <0,.17,0> }
            bounded_by { cylinder { <0,-.06,0>,<0,.25,0>,.3 } }
    }

Now the makelego macro. Calls roundbox, differences out the bottom area,

and adds cylinder "pegs" underneath and "bumps" on top where necessary.
usage: object { makelego(X1,Y1,Z1,X2,Y2,Z2) //modifiers }
NOTE: The macro does NOT check for proper measurements. Width and length

should be integers and height should be a multiple of 0.4 (plate
height).

    #macro makelego (X1,Y1,Z1,X2,Y2,Z2)
    #if (X1>X2) #declare T=X2; #declare X2=X1; #declare X1=T; #end
    #if (Y1>Y2) #declare T=Y2; #declare Y2=Y1; #declare Y1=T; #end
    #if (Z1>Z2) #declare T=Z2; #declare Z2=Z1; #declare Z1=T; #end
    #local XC = 1; #local ZC = 1;
    merge {
       difference {
          object { roundbox (X1,Y1,Z1,X2,Y2,Z2,.05) }
          box { <X1+.2,Y1-1,Z1+.2>,<X2-.2,Y2-.2,Z2-.2> }
          #declare XC = 0;
          #while (XC < (X2-X1))
          #declare ZC = 0;
          #while (ZC < (Z2-Z1))
          cylinder { <X1+XC+.5,Y1,Z1+ZC+.5>,<X1+XC+.5,Y2+.1,Z1+ZC+.5>,.2

}
          #declare ZC=ZC+1;
          #end
          #declare XC=XC+1;
          #end
          bounded_by { box { <X1,Y1,Z1>,<X2,Y2,Z2> } }
          }
       #declare XC=1; #declare ZC=1;
       #if ((X2-X1)>1)
       #if ((Z2-Z1)>1)
       #while (XC < (X2-X1))
       #declare ZC = 1;
       #while (ZC < (Z2-Z1))
       difference {
          cylinder { <X1+XC,Y1,Z1+ZC>,<X1+XC,Y2-.19,Z1+ZC>,.407 }
          cylinder { <X1+XC,Y1-.19,Z1+ZC>,<X1+XC,Y2,Z1+ZC>,.3 }
          bounded_by { cylinder {
<X1+XC,Y1,Z1+ZC>,<X1+XC,Y2-.19,Z1+ZC>,.407 } }
       }
       #declare ZC=ZC+1;
       #end
       #declare XC=XC+1;
       #end
       #else
       #while (XC < (X2-X1))
       cylinder { <X1+XC,Y1,Z1+.5>,<X1+XC,Y2-.19,Z1+.5>,.2 }
       #declare XC=XC+1;
       #end #end #end
       #if ((Z2-Z1)>1)
       #while (ZC < (Z2-Z1))
       cylinder { <X1+.5,Y1,Z1+ZC>,<X1+.5,Y2-.19,Z1+ZC>,.2 }
       #declare ZC=ZC+1;
       #end #end
       #declare XC = 0;
       #while (XC < (X2-X1))
       #declare ZC = 0;
       #while (ZC < (Z2-Z1))
       object { bump translate <X1+XC+.5,Y2,Z1+ZC+.5> }
       #declare ZC=ZC+1;
       #end
       #declare XC=XC+1;
       #end
       bounded_by { box { <X1,Y1,Z1>,<X2,Y2+.2,Z2> } }
    } #end


Post a reply to this message


Attachments:
Download 'examples.jpg' (7 KB)

Preview of image 'examples.jpg'
examples.jpg


 

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.