text
stringlengths
0
234
Put_Time_Diff (T);
Put_Line (" R2 works for 2s");
delay 2.0;
Put_Time_Diff (T);
Put_Line (" R2 reading...");
I := One_A_Time.Read;
Put_Time_Diff (T);
Put_Line (" ...R2 read" & Integer'Image (I));
Put_Line ("*** R2 exit ***");
end Reader2;
T : Time := Clock;
begin
-- The main writes
Put_Time_Diff (T);
Put_Line (" ET writes 1...");
One_A_Time.Write (1);
Put_Time_Diff (T);
Put_Line (" ET has written 1");
Function Definition: procedure Mandel_UTF is
Function Body: package Complex_Types is new Ada.Numerics.Generic_Complex_Types (Float);
use Complex_Types;
-- Configuration constants.
Bitmap_Size : constant := 128; -- pixels
Max_Iterations : constant := 32;
Num_Of_Threads : constant := 4;
------------------------------------------------------
-- This part replaces Given's glyphs table
subtype Brush_Levels is Integer range 0 .. 255;
type Brushes is array (Brush_Levels) of Wide_Character;
function Generate_Glyphs return Brushes is
First_Code_Point : constant := 10240;
begin
return E : Brushes do
for I in Brush_Levels'Range loop
E (I) := Wide_Character'Val (First_Code_Point + I);
end loop;
end return;
end Generate_Glyphs;
Glyphs : constant Brushes := Generate_Glyphs;
------------------------------------------------------
-- Returns the intensity of a single point in the Mandelbrot set.
function Render_Pixel (C : Complex) return Float is
Z : Complex := Complex'(0.0, 0.0);
begin
for N in Integer range 0 .. Max_Iterations loop
Z := Z*Z + C;
if (abs Z > 2.0) then
return Float (N) / Float (Max_Iterations);
end if;
end loop;
return 0.0;
Function Definition: procedure Free_Bitmap is new Ada.Unchecked_Deallocation
Function Body: (Object => Bitmap, Name => Bitmap_Ref);
-- Encapsulates the multithreaded render: creates a bunch of workers
-- and a scheduler, which hands out work units to the renderers.
procedure Mandelbrot
(Data : Bitmap_Ref;
R1, I1, R2, I2 : Float)
is
Width : Integer := Data'Length (1);
Height : Integer := Data'Length (2);
Xdelta : Float := (R2-R1) / Float (Width);
Ydelta : Float := (I2-I1) / Float (Height);
task Scheduler is
-- Each worker calls this to find out what it needs to do.
entry Request_Work_Unit (Y : out Integer; I : out Float);
Function Definition: procedure MandelPNG is
Function Body: package C renames Interfaces.C;
package Complex_Types is new Ada.Numerics.Generic_Complex_Types (Float);
use Complex_Types;
-- Configuration constants.
Width : constant := 800;
Height : constant := 600;
Max_Iterations : constant := 32;
-- Returns the intensity of a single point in the Mandelbrot set.
function Render_Pixel (C : Complex) return Float is
Z : Complex := Complex'(0.0, 0.0);
begin
for N in Integer range 0 .. Max_Iterations loop
Z := Z*Z + C;
if (abs Z > 2.0) then
return Float (N) / Float (Max_Iterations);
end if;
end loop;