Superellipse: Difference between revisions

Ada version
(Ada version)
Line 13:
Draw a superellipse with n = 2.5, and a = b = 200
<br><br>
 
=={{header|Ada}}==
{{libheader|SDLAda}} Brute force calculation.
<lang Ada>with Ada.Numerics.Elementary_Functions;
 
with SDL.Video.Windows.Makers;
with SDL.Video.Surfaces;
with SDL.Video.Rectangles;
with SDL.Video.Pixel_Formats;
with SDL.Events.Events;
 
procedure Superelipse is
 
Width : constant := 600;
Height : constant := 600;
A : constant := 200.0;
B : constant := 200.0;
N : constant := 2.5;
 
Win : SDL.Video.Windows.Window;
Surface : SDL.Video.Surfaces.Surface;
Event : SDL.Events.Events.Events;
 
procedure Plot (X, Y : Float) is
use SDL.C;
Point : constant SDL.Video.Rectangles.Rectangle
:= (X => Width / 2 + SDL.C.int (X),
Y => Height / 2 + SDL.C.int (Y),
Width => 1, Height => 1);
begin
Surface.Fill (Point, SDL.Video.Pixel_Formats.To_Pixel
(Format => Surface.Pixel_Format,
Red => 0, Green => 250, Blue => 0));
end Plot;
 
procedure Draw_Superelipse
is
use Ada.Numerics.Elementary_Functions;
Xx, Yy : Float;
subtype Legal_Range is Float range 0.980 .. 1.020;
begin
for Y in 0 .. Height loop
for X in 0 .. Width loop
Xx := Float (X - Width / 2);
Yy := Float (Y - Height / 2);
if (abs (Xx / A)) ** N + (abs (Yy / B)) ** N in Legal_Range then
Plot (Xx, Yy);
end if;
 
end loop;
end loop;
end Draw_Superelipse;
 
procedure Wait is
use type SDL.Events.Event_Types;
begin
loop
while SDL.Events.Events.Poll (Event) loop
if Event.Common.Event_Type = SDL.Events.Quit then
return;
end if;
end loop;
delay 0.100;
end loop;
end Wait;
 
begin
if not SDL.Initialise (Flags => SDL.Enable_Screen) then
return;
end if;
 
SDL.Video.Windows.Makers.Create (Win => Win,
Title => "Superelipse",
Position => SDL.Natural_Coordinates'(X => 10, Y => 10),
Size => SDL.Positive_Sizes'(Width, Height),
Flags => 0);
Surface := Win.Get_Surface;
 
Surface.Fill (SDL.Video.Rectangles.Rectangle'(0, 0, Width, Height),
SDL.Video.Pixel_Formats.To_Pixel
(Format => Surface.Pixel_Format,
Red => 0, Green => 0, Blue => 0));
 
Draw_Superelipse;
Win.Update_Surface;
 
Wait;
Win.Finalize;
SDL.Finalise;
end Superelipse;</lang>
 
=={{header|C}}==
Interactive program to draw a SuperEllipse. Requires the [http://www.cs.colorado.edu/~main/bgi/cs1300/ WinBGIm] library.
210

edits