dimanche 21 février 2016

FreeBASIC

I think freebasic should be the standart basic language for the education , free and very easy to use for the beginners and the students , runs very fast and it doesnt need a long lines of code to create a window application, you have just one simple instruction like "screen 13" , supports pointer object-oriented API win32 opengl... ,freebasic is also powerful able to develop 2D,3D games even for research and simulation...
I have created the following simulation program of  the motion of moon and earth around the sun this famous problem in physics is called The Three-Body Problem , my demo will show you how freebasic is useful for these kinds of complex applications


const Xres = 800
const Yres = 600

ScreenRes Xres, Yres, 8 ,2

const G = 6.726 * 10 ^ (-11)
const Ms = 1.989 * 10 ^ 30
const Mm = 7.3476 * 10 ^ 22
const Me = 5.97 * 10 ^ 24

const Dem = 384400*10^3
const Des = 149600000*10^3

Dim dt as DOUBLE, t as DOUBLE
Dim x as DOUBLE,
y as DOUBLE

Dim xe as DOUBLE , ye as DOUBLE ,phie as DOUBLE
Dim vxe as DOUBLE,
vye as DOUBLE 

Dim xm as DOUBLE, ym as DOUBLE, Phim as DOUBLE
Dim vxm as DOUBLE
, vym as DOUBLE 

Dim omegam as DOUBLE,omegae as DOUBLE
Dim r as DOUBLE,
res as DOUBLE,rsm as DOUBLE,rme as DOUBLE


dt = 60/2
xe = Des
ye = 0
omegae = 6.28/(365*24*60*60)
vxe = 0
vye = Des * omegae

xm = Des + Dem
ym = 0
omegam =6.28/(27.3*24*60*60)
vxm = 0
vym = Dem * omegam+vye


DO
screenset 1,0
CLS
res = (xe * xe+ ye* ye) ^ 1.5
rsm = (xm*xm + ym*ym)^1.5
rme = ((xe-xm)^2+(ye-ym)^2)^1.5

vxe = vxe - (G * Ms * xe / res - G * Mm * (xm - xe) / rme) * dt
vye = vye - (G * Ms * ye / res - G * Mm * (ym - ye) / rme) * dt

vxm = vxm - (G * Ms * xm / rsm + G * Me * (xm - xe) / rme) * dt
vym = vym - (G * Ms * ym / rsm + G * Me * (ym - ye) / rme) * dt

xe = xe + vxe * dt
ye = ye + vye * dt

xm = xm + vxm * dt
ym = ym + vym * dt

line (Xres/2-400,Yres/2)-(Xres/2+400,Yres/2),4
line (Xres/2,Yres/2-400)-(Xres/2,Yres/2+400),4

LOCATE 1: PRINT USING "time= ###.### Days"; t/(60*60*24)
LOCATE 2: PRINT USING "Earth velocity = ##.#### KM/S";(vxe^2+vye^2)^0.5/10^3

x = xe * 280 / Des + Xres/2
y = -ye * 280 / Des + Yres/2

circle (10^(-7)*(xm-xe)+x,-10^(-7)*(ym-ye)+y),3,3,,,,F
CIRCLE (Xres/2,Yres/2 ), 5, 14,,,,F
x = xm * 280 / Des + Xres/2
y = -ym * 280 / Des + Yres/2

circle (x, y),3,15,,,,F
screencopy 1,0
t = t+dt
LOOP UNTIL INKEY$ = CHR$(27)

END

Aucun commentaire:

Enregistrer un commentaire

Remarque : Seul un membre de ce blog est autorisé à enregistrer un commentaire.