Data update

This commit is contained in:
Ingy döt Net 2026-04-30 12:34:36 -04:00
parent 4bb20c9b71
commit cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions

View file

@ -0,0 +1,81 @@
with Ada.Numerics.Elementary_Functions;
with SDL.Video.Windows.Makers;
with SDL.Video.Renderers.Makers;
with SDL.Video.Rectangles;
with SDL.Events.Events;
procedure Fractal_Tree is
Width : constant := 600;
Height : constant := 600;
Level : constant := 13;
Length : constant := 130.0;
X_Start : constant := 475.0;
Y_Start : constant := 580.0;
A_Start : constant := -1.54;
Angle_1 : constant := 0.10;
Angle_2 : constant := 0.35;
C_1 : constant := 0.71;
C_2 : constant := 0.87;
Window : SDL.Video.Windows.Window;
Renderer : SDL.Video.Renderers.Renderer;
Event : SDL.Events.Events.Events;
procedure Draw_Tree (Level : in Natural;
Length : in Float;
Angle : in Float;
X, Y : in Float)
is
use SDL;
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);
Line : constant SDL.Video.Rectangles.Line_Segment
:= ((C.int (X), C.int (Y)), (C.int (X_2), C.int (Y_2)));
begin
if Level > 0 then
Renderer.Set_Draw_Colour (Colour => (0, 220, 0, 255));
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);
end if;
end Draw_Tree;
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 => Window,
Title => "Fractal 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));
Draw_Tree (Level, Length, A_Start, X_Start, Y_Start);
Window.Update_Surface;
Wait;
Window.Finalize;
SDL.Finalise;
end Fractal_Tree;

View file

@ -0,0 +1,63 @@
Rebol [
title: "Rosetta code: Fractal tree"
file: %Fractal_tree.r3
url: https://rosettacode.org/wiki/Fractal_tree
needs: 3.16.0
]
b2d: import 'blend2d ;--use blend2d (draw module)
cv: attempt [import 'opencv] ;--for visualisation
fractal-tree: function/with [
spec [block! map! object!] "Configuration options"
][
scaleFactor: any [select spec 'scaleFactor 0.6 ] ;; Branch length scaling factor (default 0.6)
forkAngle: any [select spec 'forkAngle 0.1 * pi] ;; Branching angle in radians (default 0.1·π)
baseLen: any [select spec 'baseLen 10.0 ] ;; Base branch length (default 10.0)
size: any [select spec 'size 600x600 ] ;; Image dimensions (default 600×600)
depth: any [select spec 'depth 9 ] ;; Recursion depth (default 9)
start-angle: any [select spec 'angle 1.5 * pi] ;; Start angle pointing upward
;; Create a blank image of given size
img: make image! size
start-point: as-pair size/x / 2 size/y ;; center bottom of image
draw-tree :start-point :start-angle :depth
;; Return the generated image
img
][
;; fractal-tree function context -----------------
img: ;; Image to draw into (closed over)
scaleFactor: ;; Branch scaling factor (closed over)
forkAngle: ;; Branching angle (closed over)
baseLen: ;; Base branch length (closed over)
size: none ;; Image size (closed over)
draw-tree: function [
pos [pair!] ;; Current position as pair! (x y)
angle [decimal!] ;; Current branch angle (radians)
depth [integer!] ;; Remaining recursion depth
][
;; Calculate end point of current branch
len: depth * baseLen
pos2: as-pair
pos/x + (len * cos angle)
pos/y + (len * sin angle)
;; Draw branch line with width proportional to depth
draw img compose [
line-width (depth) pen red line (pos) (pos2)
]
;; Recurse for right and left sub-branches
-- depth
if depth > 0 [
draw-tree pos2 angle + forkAngle depth
draw-tree pos2 angle - forkAngle depth
]
]
]
;; Usage example:
img: fractal-tree [size: 800x600 depth: 10]
save %fractal-tree.png img
if cv [
cv/imshow/name :img "Fractal Tree"
cv/waitKey 0
]

View file

@ -0,0 +1,31 @@
Red [Needs: 'View]
color: brown
width: 9
view/tight/options/flags/no-wait [ ; click image to grow tree
img: image 1097x617 draw [
pen brown line-width 9 line 500x600 500x500] [grow]
] [offset: 0x0] [no-border]
ends: reduce [500x500 pi * 3 / 2] ; list of terminal nodes
da: pi * 30 / 180 ; angle of branches in radians
ea: pi * 5 / 180 ; offset added to angle to break symmetry
l: 200 ; branches initial lenght
scale: 0.7 ; branches scale factor
grow: does [ ; grows branches
l: l * scale
color: 2 * color + leaf / 3
width: width - 1
newends: copy []
foreach [p a] ends [
a1: a + da - ea
p1: p + as-pair l * cos a1 l * sin a1
a2: a - da - ea
p2: p + as-pair l * cos a2 l * sin a2
append img/draw compose/deep [
pen (color) line-width (width) line (p1) (p) (p2)]
append newends reduce [p1 a1 p2 a2]
]
ends: newends
]

View file

@ -0,0 +1,116 @@
Red [
Title: "Organic Fractal Tree"
Author: "hinjolicious"
Needs: 'View
Note: "Some code are adapted from Red example in Rosetta Code"
]
xsize: 1920 ; display width
ysize: 1080 ; height
xmid: to integer! xsize / 2 ; horiz middle
ymid: to integer! ysize / 2 ; vert middle
dist: to integer! ysize * 0.8
iter: 0
plant: yes
INIT: does [
if iter > 10 [ ; enough trees?
iter: 0
clear img/draw
dist: to integer! ysize * 0.8
]
trunk-height: ysize * random 0.2 ; trunk height
root-xpos: random xsize
root-ypos: dist + random trunk-height
dist: dist + (10 + random 20)
root-pos: as-point2d root-xpos root-ypos
branch-ypos: root-ypos - trunk-height
branch-pos: as-point2d root-xpos branch-ypos
if branch-ypos > ysize [ ; how many times branch pos is out of screen?
iter: iter + 1
]
color: as-color random 10 random 30 random 10 ; trunk/branch color
width: 5 + random 10 ; trunk width
ends: reduce [branch-pos pi * 1.5] ; list of terminal nodes
l: 50 + random 50 ; branches initial lenght
]
GROW: does [ ; grow branches
scale: 0.6 + random 0.4
l: l * scale
if l < 15 [init plant: yes]
color: color * 1.3
width: width * 0.8
newends: copy []
; flower color
flower: do random/only [red orange yellow cyan blue violet purple magenta pink white]
foreach [p a] ends [
da: pi * ( 2 + random 30) / 180 ; angle of branches in radians
ea: pi * (-10 + random 20) / 180 ; offset added to angle to break symmetry
a1: a + da - ea p1: p + as-point2d l * cos a1 l * sin a1
a2: a - da - ea p2: p + as-point2d l * cos a2 l * sin a2
either l < 21 [ ; draw leaves or flowers
either (random 100) > 97 [ ; flowers
lc: flower * (0.5 + random 1.5) rad: 3 + random 10
lc1: flower * (0.5 + random 1.5) rad1: 3 + random 10
lc2: flower * (0.5 + random 1.5) rad2: 3 + random 10
append img/draw compose/deep [
line-width 0
pen (lc) fill-pen (lc) circle (p) (rad)
pen (lc1) fill-pen (lc1) circle (p1) (rad1)
pen (lc2) fill-pen (lc2) circle (p2) (rad2)
fill-pen 00.00.00.255 ]
][ ; leaves
lc: color * (0.5 + random 1.5)
append img/draw compose/deep [
line-width 0
pen (lc)
fill-pen (lc)
line (p) (p1) (p2) (p)
fill-pen 00.00.00.255 ]
]
][ ; branches
append img/draw compose/deep [
line-width (width)
pen (color)
line (p1) (p) (p2) ]
]
append newends reduce [p1 a1 p2 a2]
]
ends: newends
]
TREES: does [ ; not used!
append img/draw compose/deep [ ; trunk
line-width (width)
pen (color)
line (root-pos) (branch-pos) ]
]
GARDEN: does [
either plant [plant: no trees][grow]
]
MAIN: does [
init
view/tight/options/flags [
img: base
with [size: as-pair xsize ysize]
black ; background
draw [] ; draw are in "on-time"
rate 10
on-time [garden]
[quit] ; click mouse to quit
]
[offset: 0x0] ; not-needed
[no-border] ; no border!
]
random/seed now/time
main