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,19 @@
generic
type Float_Type is digits <>;
Gravitation : Float_Type;
package Pendulums is
type Pendulum is private;
function New_Pendulum (Length : Float_Type;
Theta0 : Float_Type) return Pendulum;
function Get_X (From : Pendulum) return Float_Type;
function Get_Y (From : Pendulum) return Float_Type;
procedure Update_Pendulum (Item : in out Pendulum; Time : in Duration);
private
type Pendulum is record
Length : Float_Type;
Theta : Float_Type;
X : Float_Type;
Y : Float_Type;
Velocity : Float_Type;
end record;
end Pendulums;

View file

@ -0,0 +1,38 @@
with Ada.Numerics.Generic_Elementary_Functions;
package body Pendulums is
package Math is new Ada.Numerics.Generic_Elementary_Functions (Float_Type);
function New_Pendulum (Length : Float_Type;
Theta0 : Float_Type) return Pendulum is
Result : Pendulum;
begin
Result.Length := Length;
Result.Theta := Theta0 / 180.0 * Ada.Numerics.Pi;
Result.X := Math.Sin (Theta0) * Length;
Result.Y := Math.Cos (Theta0) * Length;
Result.Velocity := 0.0;
return Result;
end New_Pendulum;
function Get_X (From : Pendulum) return Float_Type is
begin
return From.X;
end Get_X;
function Get_Y (From : Pendulum) return Float_Type is
begin
return From.Y;
end Get_Y;
procedure Update_Pendulum (Item : in out Pendulum; Time : in Duration) is
Acceleration : constant Float_Type := Gravitation / Item.Length *
Math.Sin (Item.Theta);
begin
Item.X := Math.Sin (Item.Theta) * Item.Length;
Item.Y := Math.Cos (Item.Theta) * Item.Length;
Item.Velocity := Item.Velocity +
Acceleration * Float_Type (Time);
Item.Theta := Item.Theta +
Item.Velocity * Float_Type (Time);
end Update_Pendulum;
end Pendulums;

View file

@ -0,0 +1,24 @@
with Ada.Text_IO;
with Ada.Calendar;
with Pendulums;
procedure Main is
package Float_Pendulum is new Pendulums (Float, -9.81);
use Float_Pendulum;
use type Ada.Calendar.Time;
My_Pendulum : Pendulum := New_Pendulum (10.0, 30.0);
Now, Before : Ada.Calendar.Time;
begin
Before := Ada.Calendar.Clock;
loop
Delay 0.1;
Now := Ada.Calendar.Clock;
Update_Pendulum (My_Pendulum, Now - Before);
Before := Now;
-- output positions relative to origin
-- replace with graphical output if wanted
Ada.Text_IO.Put_Line (" X: " & Float'Image (Get_X (My_Pendulum)) &
" Y: " & Float'Image (Get_Y (My_Pendulum)));
end loop;
end Main;

View file

@ -0,0 +1,24 @@
10 gosub 1000
20 theta=π/2
30 g=9.81
40 l=0.5
50 speed=0
60 px=20
70 py=1
80 bx=px+l*20*sin(theta)
90 by=py-l*20*cos(theta)
100 print chr$(147);
110 for x=px to bx step (bx-px)/10
120 y=py+(x-px)*(by-py)/(bx-px)
130 print chr$(19);left$(x$,x);left$(y$,y);"."
140 next
150 print chr$(19);left$(x$,bx);left$(y$,by);chr$(113)
160 accel=g*sin(theta)/l/50
170 speed=speed+accel/10
180 theta=theta+speed
190 goto 80
980 rem ** setup strings to be used **
990 rem ** for cursor positioning **
1000 for i=0 to 39:x$=x$+chr$(29):next
1010 for i=0 to 24:y$=y$+chr$(17):next
1020 return

View file

@ -0,0 +1,32 @@
5 print chr$(147);tab(16);"{DOWN}{SHIFT-Q}"
10 gosub 1100
20 theta=π/2
30 g=9.81
40 l=1
50 speed=0
60 px=148
70 py=24
80 bx=px+l*90*sin(theta)
90 by=(py-l*90*cos(theta))+30
150 poke v+1,by:poke v,bx
160 accel=g*sin(theta)/l/50
170 speed=speed+accel/10
180 theta=theta+speed
190 get a$:if a$<>"q" then 80
200 poke v+21,0:end
1100 rem set up a sprite
1105 poke 2040,13
1110 for s=0 to 62:read d:poke 832+s,d:next
1115 v=53248:rem start of vic-ii
1120 poke v+21,1:rem enable sprite
1125 poke v+39,1:rem set color
1130 poke v+1,130:rem y pos
1135 poke v+16,0:pokev,128:rem x pos
1139 rem *** sprite bitmap data ***
1140 data 0,0,0,0,0,0,3,192,0,15,240,0
1145 data 31,248,0,63,252,0,127,254,0,255,255,0
1150 data 255,255,0,255,255,0,255,255,0,255,255,0
1155 data 255,255,0,127,254,0,63,252,0,31,248,0
1160 data 15,240,0,3,192,0,0,0,0,0,0,0
1165 data 0,0,0
1170 return

View file

@ -1,24 +0,0 @@
10 GOSUB 1000
20 THETA = π/2
30 G = 9.81
40 L = 0.5
50 SPEED = 0
60 PX = 20
70 PY = 1
80 BX = PX+L*20*SIN(THETA)
90 BY = PY-L*20*COS(THETA)
100 PRINT CHR$(147);
110 FOR X=PX TO BX STEP (BX-PX)/10
120 Y=PY+(X-PX)*(BY-PY)/(BX-PX)
130 PRINT CHR$(19);LEFT$(X$,X);LEFT$(Y$,Y);"."
140 NEXT
150 PRINT CHR$(19);LEFT$(X$,BX);LEFT$(Y$,BY);CHR$(113)
160 ACCEL=G*SIN(THETA)/L/50
170 SPEED=SPEED+ACCEL/10
180 THETA=THETA+SPEED
190 GOTO 80
980 REM ** SETUP STRINGS TO BE USED **
990 REM ** FOR CURSOR POSITIONING **
1000 FOR I=0 TO 39: X$ = X$+CHR$(29): NEXT
1010 FOR I=0 TO 24: Y$ = Y$+CHR$(17): NEXT
1020 RETURN

View file

@ -0,0 +1,57 @@
include graphics.e
include misc.e
constant dt = 1E-3
constant g = 50
sequence vc
sequence suspension
atom len
procedure draw_pendulum(atom color, atom len, atom alfa)
sequence point
point = (len*{sin(alfa),cos(alfa)} + suspension)
draw_line(color, {suspension, point})
ellipse(color,0,point-{10,10},point+{10,10})
end procedure
function wait()
atom t0
t0 = time()
while time() = t0 do
if get_key() != -1 then
return 1
end if
end while
return 0
end function
procedure animation()
atom alfa, omega, epsilon
if graphics_mode(18) then
end if
vc = video_config()
suspension = {vc[VC_XPIXELS]/2,vc[VC_YPIXELS]/2}
len = vc[VC_YPIXELS]/2-20
alfa = PI/2
omega = 0
while 1 do
draw_pendulum(BRIGHT_WHITE,len,alfa)
if wait() then
exit
end if
draw_pendulum(BLACK,len,alfa)
epsilon = -len*sin(alfa)*g
omega += dt*epsilon
alfa += dt*omega
end while
if graphics_mode(-1) then
end if
end procedure
animation()

View file

@ -32,11 +32,11 @@ Module Pendulum {
x+=pi/2
Release ' place stored background to screen
Width scale.x/2000 {
Draw Angle x, scale.y/2.5
Draw Angle x, scale.y/1.5 ' 1.5 for 16:9 screen
Width 1 {
Circle Fill 14, scale.x/25
}
Step Angle x, -scale.y/2.5
Step Angle x, -scale.y/1.5
}
Print @(1,1), lasttimecount
if sgn(accold)<>sgn(ACCEL) then lasttimecount=timecount: Profiler

View file

@ -0,0 +1,77 @@
import gg
import gx
import math
struct Element {
x int
y int
}
struct Pendulum {
mut:
dt f64 = 0.1
angle f64 = math.pi / 2
angle_velocity f64
length f64
anchor Element
fore gx.Color = gx.black
width int
height int
}
fn new_pendulum(length f64) Pendulum {
w := int(2 * length + 50)
h := int(length / 2 * 3)
anchor := Element{
x: w / 2
y: h / 4
}
return Pendulum{
length: length
width: w
height: h
anchor: anchor
}
}
fn (mut p Pendulum) draw(mut ctx gg.Context) {
ctx.begin()
// calculate ball position
ball_x := int(p.anchor.x + math.sin(p.angle) * p.length)
ball_y := int(p.anchor.y + math.cos(p.angle) * p.length)
// line from anchor to ball
ctx.draw_line(p.anchor.x, p.anchor.y, ball_x, ball_y, p.fore)
// anchor circles
ctx.draw_ellipse_filled(p.anchor.x - 3, p.anchor.y - 4, 7, 7, gx.light_gray)
ctx.draw_ellipse_empty(p.anchor.x - 3, p.anchor.y - 4, 7, 7, p.fore)
// ball circles
ctx.draw_ellipse_filled(ball_x - 7, ball_y - 7, 14, 14, gx.yellow)
ctx.draw_ellipse_empty(ball_x - 7, ball_y - 7, 14, 14, p.fore)
ctx.end()
}
// pendulum motion
fn (mut p Pendulum) update() {
gravity := 9.81
p.angle_velocity = p.angle_velocity - gravity / p.length * math.sin(p.angle) * p.dt
p.angle = p.angle + p.angle_velocity * p.dt
}
fn frame(mut pendulum Pendulum) {
mut ctx := gg.Context{}
pendulum.update()
pendulum.draw(mut ctx)
}
fn main() {
mut pendulum := new_pendulum(200)
mut context := gg.new_context(
width: pendulum.width
height: pendulum.height
window_title: "Pendulum"
frame_fn: frame
user_data: &pendulum
bg_color: gx.white
)
context.run()
}

View file

@ -0,0 +1,44 @@
option explicit
const dt = 0.15
const length=23
dim ans0:ans0=chr(27)&"["
dim Veloc,Accel,angle,olr,olc,r,c
const r0=1
const c0=40
cls
angle=0.7
while 1
wscript.sleep(50)
Accel = -.9 * sin(Angle)
Veloc = Veloc + Accel * dt
Angle = Angle + Veloc * dt
r = r0 + int(cos(Angle) * Length)
c = c0+ int(2*sin(Angle) * Length)
cls
draw_line r,c,r0,c0
toxy r,c,"O"
olr=r :olc=c
wend
sub cls() wscript.StdOut.Write ans0 &"2J"&ans0 &"?25l":end sub
sub toxy(r,c,s) wscript.StdOut.Write ans0 & r & ";" & c & "f" & s :end sub
Sub draw_line(r1,c1, r2,c2) 'Bresenham's line drawing
Dim x,y,xf,yf,dx,dy,sx,sy,err,err2
x =r1 : y =c1
xf=r2 : yf=c2
dx=Abs(xf-x) : dy=Abs(yf-y)
If x<xf Then sx=+1: Else sx=-1
If y<yf Then sy=+1: Else sy=-1
err=dx-dy
Do
toxy x,y,"."
If x=xf And y=yf Then Exit Do
err2=err+err
If err2>-dy Then err=err-dy: x=x+sx
If err2< dx Then err=err+dx: y=y+sy
Loop
End Sub 'draw_line