Fractal tree: Difference between revisions
Content deleted Content added
Ada version |
Ada: Using renderer for line drawing |
||
Line 17:
with SDL.Video.Windows.Makers;
with SDL.Video.Surfaces;
with SDL.Video.Renderers.Makers;
with SDL.Video.Rectangles;
with SDL.Video.Pixel_Formats;
Line 27 ⟶ 28:
Level : constant := 13;
Length : constant := 130.0;
X_Start : constant :=
Y_Start : constant :=
A_Start : constant := -1.54;
Angle_1 : constant := 0.10;
Angle_2 : constant := 0.35;
Line 35 ⟶ 36:
C_2 : constant := 0.87;
Surface : SDL.Video.Surfaces.Surface;
Event : SDL.Events.Events.Events;
use SDL.C;▼
Point : constant SDL.Video.Rectangles.Rectangle▼
procedure Draw_Tree (Level : in Natural;
Line 75 ⟶ 46:
X, Y : in Float)
is
use Ada.Numerics.Elementary_Functions;
Pi : constant := Ada.Numerics.Pi;
X_2 : constant Float := X + Length * Cos (Angle, 2.0 * Pi);
Y_2 : constant Float := Y + Length * Sin (Angle, 2.0 * Pi);
:= ((C.int (X), C.int (Y)), (C.int (X_2), C.int (Y_2)));
begin
if Level > 0 then
Renderer.Draw (Line => Line);
Draw_Tree (Level - 1, C_1 * Length, Angle + Angle_1, X_2, Y_2);
Draw_Tree (Level - 1, C_2 * Length, Angle - Angle_2, X_2, Y_2);
Line 105 ⟶ 81:
end if;
SDL.Video.Windows.Makers.Create (Win =>
Title => "Fractal tree",
Position => SDL.Natural_Coordinates'(X => 10, Y => 10),
Size => SDL.Positive_Sizes'(Width, Height),
Flags => 0);
Surface :=
SDL.Video.Renderers.Makers.Create (Renderer, Surface);
Surface.Fill (SDL.Video.Rectangles.Rectangle'(0, 0, Width, Height),
Line 118 ⟶ 95:
Draw_Tree (Level, Length, A_Start, X_Start, Y_Start);
Wait;
SDL.Finalise;
end Fractal_Tree;</lang>
|