comp.lang.ada
 help / color / mirror / Atom feed
From: Gautier <gautier@fakeaddress.nil>
Subject: Re: Ada as a first language
Date: Tue, 24 Mar 2009 02:41:39 +0100
Date: 2009-03-24T02:41:39+01:00	[thread overview]
Message-ID: <49c83a1c$1_3@news.bluewin.ch> (raw)
In-Reply-To: <7NadnVUQy9Nzm1XUnZ2dnUVZ_geWnZ2d@earthlink.com>

Brian wrote:

> Since hobbyist, beginner code tends to be small (Less than 1K SLOC/project, and usually much 
> smaller), then other languages might tend to give him more success with less 
> pain.

I would put the line rather around 100 lines. And even so... I often do 
less than 100 lines hobby programs without too much pain in Ada. I just 
made this one with a buddy who was sure it would be more complicated in 
some script language (and would be a lot slower of course):

with Graph; use Graph;

procedure Fractal is

   subtype Real is Float;

   type Pt is record
     x,y:  Real;
   end record;

   subtype Vector is Pt;

   type Figure is array(Positive range <>) of Pt;

   type Matrix22 is array(1..2,1..2) of Real;

   function "+"(p: Pt; v: Vector) return Pt is
   begin
     return (p.x+v.x, p.y+v.y);
   end;

   function "*"(M: Matrix22; p: Pt) return Pt is
   begin
     return
       (M(1,1) * p.x + M(1,2) * p.y,
        M(2,1) * p.x + M(2,2) * p.y);
   end;

   type Affine is record
     M: Matrix22;
     v: Vector;
   end record;

   type Affine_array is array(Positive range <>) of Affine;

   function Morph(f: Figure; a: Affine) return Figure is
     mod_f: Figure(f'Range);
   begin
     for i in f'Range loop
       mod_f(i):= a.M*f(i) + a.v;
     end loop;
     return mod_f;
   end Morph;

   procedure Draw(f: Figure; a: Affine_array; level: Natural) is
   begin
     if level = 0 then
       Point( f(f'Last).x, f(f'Last).y );
       for i in f'Range loop
         LineTo( f(i).x, f(i).y );
       end loop;
     else
       for i in a'Range loop
         Draw( Morph(f,a(i)), a, level-1 );
       end loop;
     end if;
   end Draw;

   procedure Plot(f: Figure; a: Affine_array; d:device_type; n:string) is
   begin
     InitGraph(d, file_name=>n);
     Set_math_plane(0.0,0.0, 1.0,1.0, d);
     for level in 1..10 loop
       Draw( f, a, level);
       ClearDevice;
     end loop;
     CloseGraph(d);
   end Plot;

   procedure Plot_Sierp(d:device_type; n:string) is
     triangle: Figure:= ((0.0,0.0), (0.5, 0.886), (1.0,0.0));
     M: Matrix22:= ((0.5,0.0),(0.0,0.5));
     v1: Vector:= (0.0,0.0);
     v2: Vector:= (0.5,0.0);
     v3: Vector:= (0.25,0.886/2.0);
     transformations: Affine_array:=
       ( (M,v1), (M,v2), (M,v3) );
   begin
     Plot( triangle, transformations, d, n);
   end Plot_sierp;

begin
   Plot_sierp(PostScript, "sierpinski.ps");
end;
_________________________________________________________
Gautier's Ada programming -- http://sf.net/users/gdemont/
NB: For a direct answer, e-mail address on the Web site!



  reply	other threads:[~2009-03-24  1:41 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-22  2:26 Ada as a first language Chris
2009-03-22 10:36 ` mockturtle
2009-03-22 14:44 ` Brian Drummond
2009-03-23 11:03   ` Peter C. Chapin
2009-03-23 13:29     ` Brian Drummond
2009-03-25 10:51       ` Peter C. Chapin
2009-03-23 16:59   ` rolf.ebert_nospam_
2009-03-24 19:22   ` Tim Rowe
2009-04-04  1:42     ` Brian Gaffney
2009-04-07  9:50       ` Alex R. Mosteo
2009-03-22 15:21 ` Gary Scott
2009-03-23  8:28 ` Brian
2009-03-23  9:05   ` Jacob Sparre Andersen
2009-03-23 22:02     ` Brian
2009-03-24  1:41       ` Gautier [this message]
2009-03-24  5:56       ` Jacob Sparre Andersen
2009-03-24 22:30         ` Brian
2009-03-25  9:41           ` rmoldskr+usenet
2009-03-25 22:27             ` Brian
2009-03-25 17:58       ` John McCormick
2009-03-25 23:20         ` Brian
2009-03-23 12:08 ` Chris
2009-03-25 21:10   ` John McCormick
2009-04-11 16:40   ` Mike Silva
2009-03-23 23:05 ` jpwoodruff
2009-03-25  0:16 ` Martin
2009-03-25 15:54 ` John McCormick
  -- strict thread matches above, loose matches on Subject: below --
1997-07-03  0:00 Ada as a First Language RC
1997-07-03  0:00 ` Michael Feldman
1997-07-06  0:00 ` Alan Brain
1997-07-06  0:00   ` Robert Dewar
1997-07-16  0:00   ` Eric James DeArment
1997-07-07  0:00 ` Shmuel (Seymour J.) Metz
1992-12-29 15:40 agate!dog.ee.lbl.gov!hellgate.utah.edu!fcom.cc.utah.edu!vx9000.weber.edu!
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox