Data update

This commit is contained in:
Ingy döt Net 2026-02-01 16:33:20 -08:00
parent 5150844a7d
commit 4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions

View file

@ -1,125 +0,0 @@
with Ada.Numerics.Discrete_Random;
with SDL.Video.Windows.Makers;
with SDL.Video.Renderers.Makers;
with SDL.Events.Events;
procedure Brownian_Tree is
Width : constant := 800;
Height : constant := 600;
Points : constant := 50_000;
subtype Width_Range is Integer range 1 .. Width;
subtype Height_Range is Integer range 1 .. Height;
type Direction is (N, NE, E, SE, S, SW, W, NW);
package Random_Width is new Ada.Numerics.Discrete_Random (Width_Range);
package Random_Height is new Ada.Numerics.Discrete_Random (Height_Range);
package Random_Direc is new Ada.Numerics.Discrete_Random (Direction);
Window : SDL.Video.Windows.Window;
Renderer : SDL.Video.Renderers.Renderer;
Event : SDL.Events.Events.Events;
Width_Gen : Random_Width.Generator;
Height_Gen : Random_Height.Generator;
Direc_Gen : Random_Direc.Generator;
function Poll_Quit return Boolean is
use type SDL.Events.Event_Types;
begin
while SDL.Events.Events.Poll (Event) loop
if Event.Common.Event_Type = SDL.Events.Quit then
return True;
end if;
end loop;
return False;
end Poll_Quit;
procedure Draw_Brownian_Tree is
Field : array (Width_Range, Height_Range) of Boolean := (others => (others => False));
X : Width_Range;
Y : Height_Range;
Direc : Direction;
procedure Random_Free (X : out Width_Range; Y : out Height_Range) is
begin
-- Find free random spot
loop
X := Random_Width.Random (Width_Gen);
Y := Random_Height.Random (Height_Gen);
exit when Field (X, Y) = False;
end loop;
end Random_Free;
begin
-- Seed
Field (Random_Width.Random (Width_Gen),
Random_Height.Random (Height_Gen)) := True;
for I in 0 .. Points loop
Random_Free (X, Y);
loop
-- If collide with wall then new random start
while
X = Width_Range'First or X = Width_Range'Last or
Y = Height_Range'First or Y = Height_Range'Last
loop
Random_Free (X, Y);
end loop;
exit when Field (X - 1, Y - 1) or Field (X, Y - 1) or Field (X + 1, Y - 1);
exit when Field (X - 1, Y) or Field (X + 1, Y);
exit when Field (X - 1, Y + 1) or Field (X, Y + 1) or Field (X + 1, Y + 1);
Direc := Random_Direc.Random (Direc_Gen);
case Direc is
when NW | N | NE => Y := Y - 1;
when SW | S | SE => Y := Y + 1;
when others => null;
end case;
case Direc is
when NW | W | SW => X := X - 1;
when SE | E | NE => X := X + 1;
when others => null;
end case;
end loop;
Field (X, Y) := True;
Renderer.Draw (Point => (SDL.C.int (X), SDL.C.int (Y)));
if I mod 100 = 0 then
if Poll_Quit then
return;
end if;
Window.Update_Surface;
end if;
end loop;
end Draw_Brownian_Tree;
begin
Random_Width.Reset (Width_Gen);
Random_Height.Reset (Height_Gen);
Random_Direc.Reset (Direc_Gen);
if not SDL.Initialise (Flags => SDL.Enable_Screen) then
return;
end if;
SDL.Video.Windows.Makers.Create (Win => Window,
Title => "Brownian tree",
Position => SDL.Natural_Coordinates'(X => 10, Y => 10),
Size => SDL.Positive_Sizes'(Width, Height),
Flags => 0);
SDL.Video.Renderers.Makers.Create (Renderer, Window.Get_Surface);
Renderer.Set_Draw_Colour ((0, 0, 0, 255));
Renderer.Fill (Rectangle => (0, 0, Width, Height));
Renderer.Set_Draw_Colour ((200, 200, 200, 255));
Draw_Brownian_Tree;
Window.Update_Surface;
loop
exit when Poll_Quit;
delay 0.050;
end loop;
Window.Finalize;
SDL.Finalise;
end Brownian_Tree;

View file

@ -1,108 +0,0 @@
; Save bitmap to external file
(define (save-pbm bitmap filename)
(define f (open-output-file filename))
(simple-format f "P1\n~A ~A\n"
(list-ref (array-dimensions bitmap) 0)
(list-ref (array-dimensions bitmap) 1))
(do ((c 0 (+ c 1))) ((eqv? c (list-ref (array-dimensions bitmap) 1)))
(do ((r 0 (+ r 1))) ((eqv? r (list-ref (array-dimensions bitmap) 0)))
(display (array-ref bitmap r c) f))
(newline f))
(close-output-port f)
)
; Return a random coordinate in the bitmap that isn't filled yet along with a direction
(define (new-particle bitmap)
(define x (random (list-ref (array-dimensions bitmap) 0)))
(define y (random (list-ref (array-dimensions bitmap) 1)))
(define dx (- (random 3) 1))
(define dy (- (random 3) 1))
;Repeat until we find an unused location
(if (> (array-ref bitmap x y) 0)
(new-particle bitmap)
(list (list x y) (list dx dy))))
; Check neighboring coordinates to see if a collision occured
(define (collision-check bitmap p)
(define c #f)
(define oob #f)
(define x (list-ref (car p) 0))
(define y (list-ref (car p) 1))
(define dx (list-ref (cadr p) 0))
(define dy (list-ref (cadr p) 1))
(define w (list-ref (array-dimensions bitmap) 0))
(define h (list-ref (array-dimensions bitmap) 1))
; If the particle hasn't gone out of bounds keep checking for a collision
(if (or (> 0 x) (> 0 y) (<= w x) (<= h y))
(set! oob #t)
(do ((x (- (list-ref (car p) 0) 1) (+ x 1))) ((eqv? x (+ (list-ref (car p) 0) 2)))
(do ((y (- (list-ref (car p) 1) 1) (+ y 1))) ((eqv? y (+ (list-ref (car p) 1) 2)))
; Check existing neighbors for collisions
(if (and (<= 0 x) (<= 0 y) (> w x) (> h y))
(if (not (zero? (array-ref bitmap x y)))
(set! c #t))))))
(if oob
#f ; Return false if out of bounds
(if c
p ; Return the point of collision if a collision occured
(if (and (zero? dx) (zero? dy))
#f ; Return false if particle is motionless with no collision
(collision-check bitmap (particle-move p))))))
; Plot a particle on the bitmap
(define (particle-plot! bitmap p)
(array-set! bitmap 1 (list-ref (car p) 0) (list-ref (car p) 1)))
; Move a particle along its slope
(define (particle-move p)
(list (list
(+ (list-ref (car p) 0) (list-ref (cadr p) 0))
(+ (list-ref (car p) 1) (list-ref (cadr p) 1)))
(cadr p)))
; Grow a brownian tree
(define (grow-brownian-tree! bitmap collisions)
(define w (list-ref (array-dimensions bitmap) 0))
(define h (list-ref (array-dimensions bitmap) 1))
; Generate a new particle at a random location
(define p (new-particle bitmap))
; Find a collision or lack of one and plot it on the bitmap
(set! p (collision-check bitmap p))
(if p (begin
; Display collision number and the place it happened
(display collisions)(display ": ")(display (car p))(newline)
(set! collisions (- collisions 1))
; Plot the point
(particle-plot! bitmap p)))
; If we're done say so
(if (zero? collisions)
(display "Done\n"))
; Keep going until we have enough collisions
; or have filled the bitmap
(if (and (< 0 collisions) (memq 0 (array->list (array-contents bitmap))))
(grow-brownian-tree! bitmap collisions)))
; Plot a random point to seed the brownian tree
(define (seed-brownian-tree! bitmap)
(define p (new-particle bitmap))
(particle-plot! bitmap p))
;;; Example usage ;;;
; Seed the random number generator
(let ((time (gettimeofday)))
(set! *random-state*
(seed->random-state (+ (car time) (cdr time)))))
; Generate a tree with 320*240 collisions on a bitmap of the size 640x480
; The bitmap is zeroed to start and written with a one where a collision occurs
(define bitmap (make-array 0 640 480))
(seed-brownian-tree! bitmap)
(grow-brownian-tree! bitmap (* 320 240))
; Save to a portable bitmap file
(save-pbm bitmap "brownian-tree.pbm")