VisualFreeBasic 中的简单重力模拟
代码模拟了高达100000粒子和一个中心物体之间的基本引力。
可以调整模拟速度。
可以调整粒子的初始速度 (方向角是随机的)
可以调整粒子质量
重置微粒与爆裂 (所有100000个微粒立刻发布)
可以将绘制的粒子切换为点或圆。
切换粒子回收。
重置模拟
FB 源码,VFB源码请进勇芳编程群里下载。
#Include "fbgfx.bi"
Using FB
Randomize Timer
Type particle
x As Double
y As Double
z As Double
x_vel As Double
y_vel As Double
x_acc As Double
y_acc As Double
x_force As Double
y_force As Double
mass As ULongInt
r As UByte
g As UByte
b As UByte
alive As Byte
End Type
Type pythag
opp As Double
adj As Double
hyp As Double
angle As Double
End Type
Type gravity_point
x As Double
y As Double
z As Double
mass As ULongint
radius As Double
End Type
Declare Sub init_particle(max As Integer)
Declare Function draw_particle(max As Integer, dot As UByte) As Integer
Declare Sub move_particle(gpoint As gravity_point,max As Integer, dt As Double)
Declare Function calc_Gforce(m1 As Double, m2 As Double, dist As Double) As Double
Declare Function calc_pythag(x1 As Double, x2 As Double, y1 As Double, y2 As Double) As pythag
Const max_particle = 100000
Const Screen_width = 800
Const screen_height = 600
Const TRUE = 1
Const FALSE = 0
Const FIXED_TIME_STEP = 1/60
Const Gravity_const = .0000000000667834
Const max_force = 10
Const max_acc = 50
Dim Shared As Single init_vel, particle_mass
Const pi = 3.14159
Dim Shared particle(max_particle) As particle
Dim gravity_point As gravity_point
Dim As UByte fin, no_key, mse, dot
Dim Shared recycle As UByte
Dim As Double CurrentTime, LastTime, dt, angle
Dim As Integer speed , mx, my, mb, frame,i,r,g,b
Dim As Integer pCount
ScreenRes screen_width,screen_height,32,2
ScreenSet 1,0
fin = FALSE
no_key = TRUE
mse = FALSE
recycle = TRUE
dot = TRUE
dt = 0.5
speed = 10
init_vel = 5
particle_mass = 100
frame = 0
gravity_point.x = 300
gravity_point.y = 300
gravity_point.z = 0
gravity_point.mass = 100000000000
gravity_point.radius = 20
init_particle(max_particle)
While