examples/LCD now draws Mandelbrot set, but it is very slow

This commit is contained in:
Vovanium 2021-08-26 19:38:57 +03:00
parent 9450af9543
commit 5be434edf6
1 changed files with 52 additions and 28 deletions

View File

@ -128,12 +128,39 @@ procedure LCD is
end loop;
end;
Period : constant Time_Span := Milliseconds(5);
procedure Plot (X, Y, R, G, B: Integer) is
begin
-- Draw a pixel;
CSX.Set (False);
LCD_Command (ILI9341.CASET,
Interfaces.Unsigned_8 (X / 256),
Interfaces.Unsigned_8 (X mod 256),
Interfaces.Unsigned_8 ((X + 1) / 256),
Interfaces.Unsigned_8 ((X + 1) mod 256));
LCD_Command (ILI9341.PASET,
Interfaces.Unsigned_8 (Y / 256),
Interfaces.Unsigned_8 (Y mod 256),
Interfaces.Unsigned_8 ((Y + 1) / 256),
Interfaces.Unsigned_8 ((Y + 1) mod 256));
LCD_Command (ILI9341.RAMWR,
Interfaces.Unsigned_8 (G),
Interfaces.Unsigned_8 (B),
Interfaces.Unsigned_8 (R));
CSX.Set (True);
end;
Period : constant Time_Span := Milliseconds(2000);
Now : Time := Clock;
X, Y : Integer := 0;
Colour : Integer := 0;
--X, Y : Integer := 0;
--Colour : Integer := 0;
Scale : Float := 1.0/60.0;
CRe, CIm : Float;
ZRe, ZIm, T : Float;
N : Integer;
begin
UART.Initialize;
@ -286,33 +313,30 @@ begin
loop
for Y in Integer range 0 .. 319 loop
for X in Integer range 0 .. 239 loop
CRe := Float(- Y + 160) * Scale - 1.403;
CIm := Float(X - 120) * Scale;
N := 0;
ZRe := CRe;
ZIm := CIm;
while ZRe * ZRe + ZIm * ZIm < 4.0 and N < 256 loop
T := ZRe * ZRe - ZIm * ZIm + CRe;
ZIm := 2.0 * ZRe * ZIm + CIm;
ZRe := T;
N := N + 1;
end loop;
if N = 256 then
Plot (X, Y, 0, 0, 0);
else
Plot (X, Y, 255 - N, N, 255 - N);
end if;
end loop;
end loop;
-- Draw a pixel;
CSX.Set (False);
LCD_Command (ILI9341.CASET,
Interfaces.Unsigned_8 (X / 256),
Interfaces.Unsigned_8 (X mod 256),
Interfaces.Unsigned_8 ((X + 1) / 256),
Interfaces.Unsigned_8 ((X + 1) mod 256));
LCD_Command (ILI9341.PASET,
Interfaces.Unsigned_8 (Y / 256),
Interfaces.Unsigned_8 (Y mod 256),
Interfaces.Unsigned_8 ((Y + 1) / 256),
Interfaces.Unsigned_8 ((Y + 1) mod 256));
LCD_Command (ILI9341.RAMWR,
Interfaces.Unsigned_8 (Colour / 65536),
Interfaces.Unsigned_8 (Colour / 256 mod 256),
Interfaces.Unsigned_8 (Colour mod 256));
Scale := Scale * 0.63;
CSX.Set (True);
X := (X + 1) mod 240;
Y := (Y + 1) mod 319;
Colour := (Colour + 16#010101#) mod 2**24;
Now := Now + Period;
Now := Clock + Period;
delay until Now;
--LED.Set (not LED_On);