Jump to content

Superellipse: Difference between revisions

m
Ada: No use of SDL.Video.Surfaces
(Ada version)
m (Ada: No use of SDL.Video.Surfaces)
Line 19:
 
with SDL.Video.Windows.Makers;
with SDL.Video.SurfacesRenderers.Makers;
with SDL.Video.Rectangles;
with SDL.Video.Pixel_Formats;
with SDL.Events.Events;
 
Line 28 ⟶ 26:
Width : constant := 600;
Height : constant := 600;
A : constant := 200.0;
B : constant := 200.0;
N : constant := 2.5;
 
Win Window : SDL.Video.Windows.Window;
SurfaceRenderer : SDL.Video.SurfacesRenderers.SurfaceRenderer;
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 type SDL.C.int;
use Ada.Numerics.Elementary_Functions;
Xx, Yy : Float;
Line 59 ⟶ 46:
Yy := Float (Y - Height / 2);
if (abs (Xx / A)) ** N + (abs (Yy / B)) ** N in Legal_Range then
PlotRenderer.Draw (Xx,Point Yy=> (X => Width / 2 + SDL.C.int (Xx);,
:= (X Y => Width Height / 2 +- SDL.C.int (XYy))),;
end if;
 
Line 84 ⟶ 72:
end if;
 
SDL.Video.Windows.Makers.Create (Win => WinWindow,
Title => "Superelipse",
Position => SDL.Natural_Coordinates'(X => 10, Y => 10),
Size => SDL.Positive_Sizes'(Width, Height),
Flags => 0);
SurfaceSDL.Video.Renderers.Makers.Create :=(Renderer, WinWindow.Get_Surface);
Renderer.Set_Draw_Colour ((0, 0, 0, 255));
 
SurfaceRenderer.Fill (SDL.Video.Rectangles.Rectangle' => (0, 0, Width, Height),);
Renderer.Set_Draw_Colour ((0, 220, 0, 255));
SDL.Video.Pixel_Formats.To_Pixel
(Format => Surface.Pixel_Format,
Red => 0, Green => 0, Blue => 0));
 
Draw_Superelipse;
WinWindow.Update_Surface;
 
Wait;
WinWindow.Finalize;
SDL.Finalise;
end Superelipse;</lang>
211

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.