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,143 @@
with Ada.Numerics.Elementary_Functions;
with Ada.Numerics.Generic_Real_Arrays;
with SDL.Video.Windows.Makers;
with SDL.Video.Renderers.Makers;
with SDL.Video.Palettes;
with SDL.Events.Events;
procedure Death_Star is
Width : constant := 400;
Height : constant := 400;
package Float_Arrays is
new Ada.Numerics.Generic_Real_Arrays (Float);
use Ada.Numerics.Elementary_Functions;
use Float_Arrays;
Window : SDL.Video.Windows.Window;
Renderer : SDL.Video.Renderers.Renderer;
subtype Vector_3 is Real_Vector (1 .. 3);
type Sphere_Type is record
Cx, Cy, Cz : Integer;
R : Integer;
end record;
function Normalize (V : Vector_3) return Vector_3 is
(V / Sqrt (V * V));
procedure Hit (S : Sphere_Type;
X, Y : Integer;
Z1, Z2 : out Float;
Is_Hit : out Boolean)
is
NX : constant Integer := X - S.Cx;
NY : constant Integer := Y - S.Cy;
Zsq : constant Integer := S.R * S.R - (NX * NX + NY * NY);
Zsqrt : Float;
begin
if Zsq >= 0 then
Zsqrt := Sqrt (Float (Zsq));
Z1 := Float (S.Cz) - Zsqrt;
Z2 := Float (S.Cz) + Zsqrt;
Is_Hit := True;
return;
end if;
Z1 := 0.0;
Z2 := 0.0;
Is_Hit := False;
end Hit;
procedure Draw_Death_Star (Pos, Neg : Sphere_Type;
K, Amb : Float;
Dir : Vector_3)
is
Vec : Vector_3;
ZB1, ZB2 : Float;
ZS1, ZS2 : Float;
Is_Hit : Boolean;
S : Float;
Lum : Integer;
begin
for Y in Pos.Cy - Pos.R .. Pos.Cy + Pos.R loop
for X in Pos.Cx - Pos.R .. Pos.Cx + Pos.R loop
Hit (Pos, X, Y, ZB1, ZB2, Is_Hit);
if not Is_Hit then
goto Continue;
end if;
Hit (Neg, X, Y, ZS1, ZS2, Is_Hit);
if Is_Hit then
if ZS1 > ZB1 then
Is_Hit := False;
elsif ZS2 > ZB2 then
goto Continue;
end if;
end if;
if Is_Hit then
Vec := (Float (Neg.Cx - X),
Float (Neg.Cy - Y),
Float (Neg.Cz) - ZS2);
else
Vec := (Float (X - Pos.Cx),
Float (Y - Pos.Cy),
ZB1 - Float (Pos.Cz));
end if;
S := Float'Max (0.0, Dir * Normalize (Vec));
Lum := Integer (255.0 * (S ** K + Amb) / (1.0 + Amb));
Lum := Integer'Max (0, Lum);
Lum := Integer'Min (Lum, 255);
Renderer.Set_Draw_Colour ((SDL.Video.Palettes.Colour_Component (Lum),
SDL.Video.Palettes.Colour_Component (Lum),
SDL.Video.Palettes.Colour_Component (Lum),
255));
Renderer.Draw (Point => (SDL.C.int (X + Width / 2),
SDL.C.int (Y + Height / 2)));
<<Continue>>
end loop;
end loop;
end Draw_Death_Star;
procedure Wait is
use type SDL.Events.Event_Types;
Event : SDL.Events.Events.Events;
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;
Direction : constant Vector_3 := Normalize ((20.0, -40.0, -10.0));
Positive : constant Sphere_Type := (0, 0, 0, 120);
Negative : constant Sphere_Type := (-90, -90, -30, 100);
begin
if not SDL.Initialise (Flags => SDL.Enable_Screen) then
return;
end if;
SDL.Video.Windows.Makers.Create (Win => Window,
Title => "Death star",
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_Death_Star (Positive, Negative, 1.5, 0.2, Direction);
Window.Update_Surface;
Wait;
Window.Finalize;
SDL.Finalise;
end Death_Star;

View file

@ -0,0 +1,106 @@
import math
enum Axis {
x_
y_
z_
r_
}
fn clamp(x f64, b f64, t f64) f64 {
if x < b { return b }
else if x > t { return t }
else { return x }
}
fn dot(v []f64, w []f64) f64 {
return v[int(Axis.x_)] * w[int(Axis.x_)] +
v[int(Axis.y_)] * w[int(Axis.y_)] +
v[int(Axis.z_)] * w[int(Axis.z_)]
}
fn normal(v []f64, mut result []f64) {
ilen := 1.0 / f64(math.sqrt(dot(v, v)))
result[int(Axis.x_)] = v[int(Axis.x_)] * ilen
result[int(Axis.y_)] = v[int(Axis.y_)] * ilen
result[int(Axis.z_)] = v[int(Axis.z_)] * ilen
}
fn hit_test(s []f64, x f64, y f64, mut result []f64) bool {
mut z := s[int(Axis.r_)] * s[int(Axis.r_)] - (x - s[int(Axis.x_)]) * (x - s[int(Axis.x_)]) -
(y - s[int(Axis.y_)]) * (y - s[int(Axis.y_)])
if z >= 0 {
z = math.sqrt(z)
result[0] = s[int(Axis.z_)] - z
result[1] = s[int(Axis.z_)] + z
return true
}
else { return false }
}
fn death_star(posic []f64, neg []f64, sun []f64, k f64, amb f64) {
mut xx, mut temp1, mut temp2 := []f64{len: 3}, []f64{len: 3}, []f64{len: 3}
mut hp, mut hn := []f64{len: 2}, []f64{len: 2}
mut result_val, mut shade := 0, -1
shades := [' ', '.', ':', '!', '*', 'o', 'e', '&', '#', '%', '@']
y_start := int(posic[int(Axis.y_)] - posic[int(Axis.r_)] - 0.5)
y_end := int(posic[int(Axis.y_)] + posic[int(Axis.r_)] + 0.5)
x_start := int(posic[int(Axis.x_)] - posic[int(Axis.r_)] - 0.5)
x_end := int(posic[int(Axis.x_)] + posic[int(Axis.r_)] + 0.5)
for y in y_start .. y_end + 1 {
mut line := ''
for x in x_start .. x_end + 1 {
result_val = 0
if !hit_test(posic, f64(x), f64(y), mut hp) { result_val = 0 }
else if !hit_test(neg, f64(x), f64(y), mut hn) { result_val = 1 }
else if hn[0] > hp[0] { result_val = 1 }
else if hn[1] > hp[1] { result_val = 0 }
else if hn[1] > hp[0] { result_val = 2 }
else { result_val = 1 }
shade = -1
match result_val {
0 {
shade = 0
}
1 {
temp1[int(Axis.x_)] = f64(x) - posic[int(Axis.x_)]
temp1[int(Axis.y_)] = f64(y) - posic[int(Axis.y_)]
temp1[int(Axis.z_)] = hp[0] - posic[int(Axis.z_)]
normal(temp1, mut xx)
}
2 {
temp2[int(Axis.x_)] = neg[int(Axis.x_)] - f64(x)
temp2[int(Axis.y_)] = neg[int(Axis.y_)] - f64(y)
temp2[int(Axis.z_)] = neg[int(Axis.z_)] - hn[1]
normal(temp2, mut xx)
}
else {}
}
if shade != 0 {
b := math.pow(dot(sun, xx), k) + amb
shade = int(clamp((1.0 - b) * f64(shades.len - 1), 1, f64(shades.len - 1)))
}
line += shades[shade].str()
}
println(line)
}
}
fn main() {
mut posic, mut neg := []f64{len: 4}, []f64{len: 4}
mut temp3, mut sun := []f64{len: 3}, []f64{len: 3}
posic[int(Axis.x_)] = 20
posic[int(Axis.y_)] = 20
posic[int(Axis.z_)] = 0
posic[int(Axis.r_)] = 20
neg[int(Axis.x_)] = 10
neg[int(Axis.y_)] = 10
neg[int(Axis.z_)] = -15
neg[int(Axis.r_)] = 10
temp3[0] = -2
temp3[1] = 1
temp3[2] = 3
normal(temp3, mut sun)
death_star(posic, neg, sun, 2, 0.1)
}

View file

@ -0,0 +1,81 @@
'deathstar ascii graphics
option explicit
const x_=0
const y_=1
const z_=2
const r_=3
function clamp(x,b,t)
if x<b then
clamp=b
elseif x>t then
clamp =t
else
clamp=x
end if
end function
function dot(v,w) dot=v(x_)*w(x_)+v(y_)*w(y_)+v(z_)*w(z_): end function
function normal (byval v)
dim ilen:ilen=1/sqr(dot(v,v)):
v(x_)=v(x_)*ilen: v(y_)=v(y_)*ilen: v(z_)=v(z_)*ilen:
normal=v:
end function
function hittest(s,x,y)
dim z
z = s(r_)^2 - (x-s(x_))^2 - (y-s(y_))^2
if z>=0 then
z=sqr(z)
hittest=array(s(z_)-z,s(z_)+z)
else
hittest=0
end if
end function
sub deathstar(pos, neg, sun, k, amb)
dim x,y,shades,result,shade,hp,hn,xx,b
shades=array(" ",".",":","!","*","o","e","&","#","%","@")
for y = pos(y_)-pos(r_)-0.5 to pos(y_)+pos(r_)+0.5
for x = pos(x_)-pos(r_)-0.5 to pos(x_)+pos(r_)+.5
hp=hittest (pos, x, y)
hn=hittest(neg,x,y)
if not isarray(hp) then
result=0
elseif not isarray(hn) then
result=1
elseif hn(0)>hp(0) then
result=1
elseif hn(1)>hp(1) then
result=0
elseif hn(1)>hp(0) then
result=2
else
result=1
end if
shade=-1
select case result
case 0
shade=0
case 1
xx=normal(array(x-pos(x_),y-pos(y_),hp(0)-pos(z_)))
'shade=clamp(1-dot(sun,xx)^k+amb,1,ubound(shades))
case 2
xx=normal(array(neg(x_)-x,neg(y_)-y,neg(z_)-hn(1)))
'shade=clamp(1-dot(sun,xx)^k+amb,1,ubound(shades))
end select
if shade <>0 then
b=dot(sun,xx)^k+amb
shade=clamp((1-b) *ubound(shades),1,ubound(shades))
end if
wscript.stdout.write string(2,shades(shade))
next
wscript.stdout.write vbcrlf
next
end sub
deathstar array(20, 20, 0, 20),array(10,10,-15,10), normal(array(-2,1,3)), 2, 0.1