Subject:
|
Building a sphere
|
Newsgroups:
|
lugnet.cad
|
Date:
|
Thu, 25 Mar 1999 09:59:54 GMT
|
Viewed:
|
916 times
|
| |
![Post a public reply to this message](/news/icon-reply.gif) | |
Rich Thompson (richone@midsouth.rr.com) wrote:
> Has anyone modeled a sphere in Ldraw? I am having trouble getting an
> interesting sphere effect in a tight (16-20 stud) space and could use some
> ideas...
I've polished up the code for generating building
instructions for a LEGO sphere I posted yesterday. It still
needs some tweaking (part number for 1x1 plate and a
corrected orientation matrix), but at least it compiles.
If you need a sphere with a different radius, just change
the value of the constant "Radius" (on line 30).
Play well,
Jacob
------------------------------------------------------------------------------
--
-- procedure Sphere_Instructions (body)
--
-- Writes a LDraw file with building instructions for a LEGO sphere.
--
-- Requested by Rich Thompson (richone@midsouth.rr.com).
--
-- You can get a free Ada compiler at <URL:http://www.gnat.com/mirrors.html>.
--
------------------------------------------------------------------------------
--
-- 1999.03.24-25 (Jacob Sparre Andersen)
-- Written.
--
------------------------------------------------------------------------------
-- Standard packages:
with Ada.Integer_Text_IO;
with Ada.Text_IO;
------------------------------------------------------------------------------
procedure Sphere_Instructions is
---------------------------------------------------------------------------
-- The orientation matrix or the order the coordinates are _printed_ in
-- needs to be fixed.
Radius : constant Positive := 45; -- LU ( = 1/2 plates )
Squared_Radius : constant Positive := (Radius * 4)**2; -- LDraw units
Half_Width : constant Positive := Radius / 5 + 1; -- Studs
Half_Height : constant Positive := Radius / 2 + 1; -- Plates
---------------------------------------------------------------------------
use Ada.Integer_Text_IO;
use Ada.Text_IO;
X, Y, Z : Integer;
begin -- Sphere_Instructions
Put_Line ("0 FILE build_sphere.dat");
Put_Line ("0 TITLE Building instructions for a sphere");
for Z_Index in - Half_Height .. + Half_Height loop
Z := 8 * Z_Index; -- LDraw units
for X_Index in - Half_Width .. + Half_Width loop
X := 20 * X_Index; -- LDraw units
for Y_Index in - Half_Width .. + Half_Width loop
Y := 20 * Y_Index; -- LDraw units
if X**2 + Y**2 + Z**2 <= Squared_Radius then
Put ("1 16 ");
else
Put ("1 24 ");
end if;
Put (X);
Put (" ");
Put (Y);
Put (" ");
Put (Z);
Put_Line (" 1 0 0 0 1 0 0 0 1 1x1plate.dat");
end loop;
end loop;
Put_Line ("0 STEP");
end loop;
end Sphere_Instructions;
|
|
Message is in Reply To:
![](/news/x.gif) | | A Sphere
|
| Has anyone modeled a sphere in Ldraw? I am having trouble getting an interesting sphere effect in a tight (16-20 stud) space and could use some ideas... Rich (URL) (26 years ago, 20-Mar-99, to lugnet.cad)
|
6 Messages in This Thread: ![A Sphere -Rich Thompson (20-Mar-99 to lugnet.cad)](/news/x.gif) ![](/news/246.gif) ![Re: A Sphere -Jacob Sparre Andersen (23-Mar-99 to lugnet.cad)](/news/x.gif) ![](/news/46.gif) ![RE: A Sphere -Rich Thompson (23-Mar-99 to lugnet.cad)](/news/x.gif)
![](/news/x.gif) ![](/news/268.gif) ![Re: A Sphere -Jacob Sparre Andersen (23-Mar-99 to lugnet.cad)](/news/x.gif)
![](/news/x.gif) ![](/news/268.gif) ![You are here](/news/here.gif)
![](/news/x.gif) ![](/news/68.gif) ![Re: A Sphere -John Gerlach (25-Mar-99 to lugnet.cad)](/news/x.gif)
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|