'Simple Model of Ionic Crystal v4 by QWERKEY 2018-11-14
CONST A0!
= 100, A1!
= 2, R0!
= 250, R1!
= 2.3, A2!
= 200, R2!
= 115, FMin!
= -5 '-55 CONST NoBalls%%
= 100, Atom!
= 120, Kelvin!
= 0.35, F1!
= 1000, F2!
= 3000, Xstal!
= 0.99 CONST BallSize1%%
= 25, BallSize0%%
= 30, Offset%
= 730, ScreenX%
= 1260, ScreenY%
= 800
DIM SHARED SodiumPos!
(NoBalls%%
- 1, 2), ChlorinePos!
(NoBalls%%
- 1, 2) 'Sodium 1, Chlorine 0 DIM SHARED SodiumVel!
(NoBalls%%
- 1, 2), ChlorineVel!
(NoBalls%%
- 1, 2), Theta!
'= 0.0084 DIM SodiumAcc!
(NoBalls%%
- 1, 2), ChlorineAcc!
(NoBalls%%
- 1, 2), BallStats%
(1, 2)
_TITLE "Very Accurate Quantum Physics Model"
FOR N%%
= 0 TO NoBalls%%
- 1 ChlorinePos!
(N%%
, M%%
) = 1.5 * ScreenX%
* (RND - 0.5) SodiumPos!
(N%%
, M%%
) = 1.5 * ScreenX%
* (RND - 0.5) ChlorineVel!
(N%%
, M%%
) = (RND - 0.5) * Kelvin!
SodiumVel!
(N%%
, M%%
) = (RND - 0.5) * Kelvin!
' Ball Colours (Cyperium Method)
READ BallStats%
(N%%
, P%%
) COLOR _RGBA(BallStats%
(N%%
, 0), BallStats%
(N%%
, 1), BallStats%
(N%%
, 2), 65), _RGBA(0, 0, 0, 0) 'Image data goes from 1 to 255 (not 0 to 255)
DeltaX% = X% - 127
DeltaY% = Y% - 127
DeltaZ% = Z% - 127
Dist!
= SQR((DeltaX%
* DeltaX%
) + (DeltaY%
* DeltaY%
) + (DeltaZ%
* DeltaZ%
)) IF Dist!
> 125 AND Dist!
< 127 THEN PSET (X%
, Y%
), _RGBA(CINT(Z%
* BallStats%
(N%%
, 0) * (1 - (XBright!
* X%
/ 255)) / 255), CINT(Z%
* BallStats%
(N%%
, 1) * (1 - (XBright!
* X%
/ 255)) / 255), CINT(Z%
* BallStats%
(N%%
, 2) * (1 - (XBright!
* X%
/ 255)) / 255), 65)
'Create screen
MaxDist! = 0
FOR N%%
= 0 TO NoBalls%%
- 1 XTemp! = ChlorinePos!(N%%, 0): ZTemp! = ChlorinePos!(N%%, 2)
_MAPTRIANGLE (0, 0)-(255, 0)-(0, 255), Chlorine&
TO(-(BallSize1%%
- 1) \
2 + XDash!
(XTemp!
, ZTemp!
), (BallSize1%%
- 1) \
2 + ChlorinePos!
(N%%
, 1), ZDash!
(XTemp!
, ZTemp!
) - Offset%
)-((BallSize1%%
- 1) \
2 + XDash!
(XTemp!
, ZTemp!
), (BallSize1%%
- 1) \
2 + ChlorinePos!
(N%%
, 1), ZDash!
(XTemp!
, ZTemp!
) - Offset%
)-(-(BallSize1%%
- 1) \
2 + XDash!
(XTemp!
, ZTemp!
), -(BallSize1%%
- 1) \
2 + ChlorinePos!
(N%%
, 1), ZDash!
(XTemp!
, ZTemp!
) - Offset%
) _MAPTRIANGLE (255, 255)-(0, 255)-(255, 0), Chlorine&
TO((BallSize1%%
- 1) \
2 + XDash!
(XTemp!
, ZTemp!
), -(BallSize1%%
- 1) \
2 + ChlorinePos!
(N%%
, 1), ZDash!
(XTemp!
, ZTemp!
) - Offset%
)-(-(BallSize1%%
- 1) \
2 + XDash!
(XTemp!
, ZTemp!
), -(BallSize1%%
- 1) \
2 + ChlorinePos!
(N%%
, 1), ZDash!
(XTemp!
, ZTemp!
) - Offset%
)-((BallSize1%%
- 1) \
2 + XDash!
(XTemp!
, ZTemp!
), (BallSize1%%
- 1) \
2 + ChlorinePos!
(N%%
, 1), ZDash!
(XTemp!
, ZTemp!
) - Offset%
) XTemp! = SodiumPos!(N%%, 0): ZTemp! = SodiumPos!(N%%, 2)
_MAPTRIANGLE (0, 0)-(255, 0)-(0, 255), Sodium&
TO(-(BallSize0%%
- 1) \
2 + XDash!
(XTemp!
, ZTemp!
), (BallSize0%%
- 1) \
2 + SodiumPos!
(N%%
, 1), ZDash!
(XTemp!
, ZTemp!
) - Offset%
)-((BallSize0%%
- 1) \
2 + XDash!
(XTemp!
, ZTemp!
), (BallSize0%%
- 1) \
2 + SodiumPos!
(N%%
, 1), ZDash!
(XTemp!
, ZTemp!
) - Offset%
)-(-(BallSize0%%
- 1) \
2 + XDash!
(XTemp!
, ZTemp!
), -(BallSize0%%
- 1) \
2 + SodiumPos!
(N%%
, 1), ZDash!
(XTemp!
, ZTemp!
) - Offset%
) _MAPTRIANGLE (255, 255)-(0, 255)-(255, 0), Sodium&
TO((BallSize0%%
- 1) \
2 + XDash!
(XTemp!
, ZTemp!
), -(BallSize0%%
- 1) \
2 + SodiumPos!
(N%%
, 1), ZDash!
(XTemp!
, ZTemp!
) - Offset%
)-(-(BallSize0%%
- 1) \
2 + XDash!
(XTemp!
, ZTemp!
), -(BallSize0%%
- 1) \
2 + SodiumPos!
(N%%
, 1), ZDash!
(XTemp!
, ZTemp!
) - Offset%
)-((BallSize0%%
- 1) \
2 + XDash!
(XTemp!
, ZTemp!
), (BallSize0%%
- 1) \
2 + SodiumPos!
(N%%
, 1), ZDash!
(XTemp!
, ZTemp!
) - Offset%
) SodiumAcc!(N%%, M%%) = 0
ChlorineAcc!(N%%, M%%) = 0
FOR L%%
= 0 TO NoBalls%%
- 1 'opposites
D!
= SQR((SodiumPos!
(N%%
, 0) - ChlorinePos!
(L%%
, 0)) * (SodiumPos!
(N%%
, 0) - ChlorinePos!
(L%%
, 0)) + (SodiumPos!
(N%%
, 1) - ChlorinePos!
(L%%
, 1)) * (SodiumPos!
(N%%
, 1) - ChlorinePos!
(L%%
, 1)) + (SodiumPos!
(N%%
, 2) - ChlorinePos!
(L%%
, 2)) * (SodiumPos!
(N%%
, 2) - ChlorinePos!
(L%%
, 2))) F! = (Attraction!(D!) + Repulsion!(D!)) / F1!
'IF F! < FMin! / F1! THEN F! = FMin! / F1!
SodiumAcc!(N%%, M%%) = -F! * (SodiumPos!(N%%, M%%) - ChlorinePos!(L%%, M%%)) / D! + SodiumAcc!(N%%, M%%)
'_MAPTRIANGLE (0, 0)-(101, 0)-(101, 1), LineImage& TO(XDash!(SodiumPos!(N%%, 0), SodiumPos!(N%%, 2)), SodiumPos!(N%%, 1), ZDash!(SodiumPos!(N%%, 0), SodiumPos!(N%%, 2)) - Offset%)-(XDash!(ChlorinePos!(L%%, 0), ChlorinePos!(L%%, 2)), ChlorinePos!(L%%, 1), ZDash!(ChlorinePos!(L%%, 0), ChlorinePos!(L%%, 2)) - Offset%)-(XDash!(ChlorinePos!(L%%, 0), ChlorinePos!(L%%, 2)), ChlorinePos!(L%%, 1), ZDash!(ChlorinePos!(L%%, 0), ChlorinePos!(L%%, 2)) - Offset% - 1), , _SMOOTH
IF ABS(SodiumPos!
(N%%
, 0) - ChlorinePos!
(L%%
, 0)) > ABS(SodiumPos!
(N%%
, 1) - ChlorinePos!
(L%%
, 1)) AND ABS(SodiumPos!
(N%%
, 0) - ChlorinePos!
(L%%
, 0)) > ABS(SodiumPos!
(N%%
, 2) - ChlorinePos!
(L%%
, 2)) THEN delta! = SodiumPos!(N%%, 1) - ChlorinePos!(L%%, 1)
SodiumPos!(N%%, 1) = SodiumPos!(N%%, 1) + delta! * (1 - Xstal!)
ChlorinePos!(L%%, 1) = ChlorinePos!(L%%, 1) - delta! * (1 - Xstal!)
delta! = SodiumPos!(N%%, 2) - ChlorinePos!(L%%, 2)
SodiumPos!(N%%, 2) = SodiumPos!(N%%, 2) + delta! * (1 - Xstal!)
ChlorinePos!(L%%, 2) = ChlorinePos!(L%%, 2) - delta! * (1 - Xstal!)
ELSEIF ABS(SodiumPos!
(N%%
, 1) - ChlorinePos!
(L%%
, 1)) > ABS(SodiumPos!
(N%%
, 0) - ChlorinePos!
(L%%
, 0)) AND ABS(SodiumPos!
(N%%
, 1) - ChlorinePos!
(L%%
, 1)) > ABS(SodiumPos!
(N%%
, 2) - ChlorinePos!
(L%%
, 2)) THEN delta! = SodiumPos!(N%%, 0) - ChlorinePos!(L%%, 0)
SodiumPos!(N%%, 0) = SodiumPos!(N%%, 0) + delta! * (1 - Xstal!)
ChlorinePos!(L%%, 0) = ChlorinePos!(L%%, 0) - delta! * (1 - Xstal!)
delta! = SodiumPos!(N%%, 2) - ChlorinePos!(L%%, 2)
SodiumPos!(N%%, 2) = SodiumPos!(N%%, 2) + delta! * (1 - Xstal!)
ChlorinePos!(L%%, 2) = ChlorinePos!(L%%, 2) - delta! * (1 - Xstal!)
delta! = SodiumPos!(N%%, 1) - ChlorinePos!(L%%, 1)
SodiumPos!(N%%, 1) = SodiumPos!(N%%, 1) + delta! * (1 - Xstal!)
ChlorinePos!(L%%, 1) = ChlorinePos!(L%%, 1) - delta! * (1 - Xstal!)
delta! = SodiumPos!(N%%, 0) - ChlorinePos!(L%%, 0)
SodiumPos!(N%%, 0) = SodiumPos!(N%%, 0) + delta! * (1 - Xstal!)
ChlorinePos!(L%%, 0) = ChlorinePos!(L%%, 0) - delta! * (1 - Xstal!)
D!
= SQR((SodiumPos!
(L%%
, 0) - ChlorinePos!
(N%%
, 0)) * (SodiumPos!
(L%%
, 0) - ChlorinePos!
(N%%
, 0)) + (SodiumPos!
(L%%
, 1) - ChlorinePos!
(N%%
, 1)) * (SodiumPos!
(L%%
, 1) - ChlorinePos!
(N%%
, 1)) + (SodiumPos!
(L%%
, 2) - ChlorinePos!
(N%%
, 2)) * (SodiumPos!
(L%%
, 2) - ChlorinePos!
(N%%
, 2))) F! = (Attraction!(D!) + Repulsion!(D!)) / F1!
'IF F! < FMin! / F1! THEN F! = FMin! / F1!
ChlorineAcc!(N%%, M%%) = F! * (SodiumPos!(L%%, M%%) - ChlorinePos!(N%%, M%%)) / D! + ChlorineAcc!(N%%, M%%)
'same type
D!
= SQR((SodiumPos!
(N%%
, 0) - SodiumPos!
(L%%
, 0)) * (SodiumPos!
(N%%
, 0) - SodiumPos!
(L%%
, 0)) + (SodiumPos!
(N%%
, 1) - SodiumPos!
(L%%
, 1)) * (SodiumPos!
(N%%
, 1) - SodiumPos!
(L%%
, 1)) + (SodiumPos!
(N%%
, 2) - SodiumPos!
(L%%
, 2)) * (SodiumPos!
(N%%
, 2) - SodiumPos!
(L%%
, 2))) F! = -(Attraction!(D!)) / F2!
SodiumAcc!(N%%, M%%) = -F! * (SodiumPos!(N%%, M%%) - SodiumPos!(L%%, M%%)) / D! + SodiumAcc!(N%%, M%%)
D!
= SQR((ChlorinePos!
(N%%
, 0) - ChlorinePos!
(L%%
, 0)) * (ChlorinePos!
(N%%
, 0) - ChlorinePos!
(L%%
, 0)) + (ChlorinePos!
(N%%
, 1) - ChlorinePos!
(L%%
, 1)) * (ChlorinePos!
(N%%
, 1) - ChlorinePos!
(L%%
, 1)) + (ChlorinePos!
(N%%
, 2) - ChlorinePos!
(L%%
, 2)) * (ChlorinePos!
(N%%
, 2) - ChlorinePos!
(L%%
, 2))) F! = -(Attraction!(D!)) / F2!
ChlorineAcc!(N%%, M%%) = -F! * (ChlorinePos!(N%%, M%%) - ChlorinePos!(L%%, M%%)) / D! + ChlorineAcc!(N%%, M%%)
SodiumPos!(N%%, M%%) = SodiumPos!(N%%, M%%) + SodiumVel!(N%%, M%%)
ChlorinePos!(N%%, M%%) = ChlorinePos!(N%%, M%%) + ChlorineVel!(N%%, M%%)
SodiumVel!(N%%, M%%) = SodiumVel!(N%%, M%%) + SodiumAcc!(N%%, M%%)
IF ABS(SodiumVel!
(N%%
, M%%
)) > Kelvin!
THEN SodiumVel!
(N%%
, M%%
) = Kelvin!
* (ABS(SodiumVel!
(N%%
, M%%
)) / SodiumVel!
(N%%
, M%%
)) ChlorineVel!(N%%, M%%) = ChlorineVel!(N%%, M%%) + ChlorineAcc!(N%%, M%%)
IF ABS(ChlorineVel!
(N%%
, M%%
)) > Kelvin!
THEN ChlorineVel!
(N%%
, M%%
) = Kelvin!
* (ABS(ChlorineVel!
(N%%
, M%%
)) / ChlorineVel!
(N%%
, M%%
)) Theta! = Theta! + 0.0084
'FUNCTION MakeHardware& (Imagename&)
' MakeHardware& = _COPYIMAGE(Imagename&, 33)
' _FREEIMAGE Imagename&
'END FUNCTION
Attraction! = A0! * (1 / (Dist! / A2!) ^ A1!)
Repulsion! = -R0! * (1 / (Dist! / R2!) ^ R1!)
XDash!
= X!
* COS(Theta!
) + Z!
* SIN(Theta!
)
ZDash!
= -X!
* SIN(Theta!
) + Z!
* COS(Theta!
)
SUB CentreOfMass
'fio centre of mass adjustment & zero net momentums TotMass# = 0
MRx# = 0: MRy# = 0: MRz# = 0
Px# = 0: Py# = 0: Pz# = 0
FOR N%
= 0 TO NoBalls%%
- 1 TotMass# = TotMass# + 1
MRx# = MRx# + SodiumPos!(N%, 0)
MRy# = MRy# + SodiumPos!(N%, 1)
MRz# = MRz# + SodiumPos!(N%, 2)
Px# = SodiumVel!(N%, 0) + Px#
Py# = SodiumVel!(N%, 1) + Py#
Pz# = SodiumVel!(N%, 2) + Pz#
TotMass# = TotMass# + 1
MRx# = MRx# + ChlorinePos!(N%, 0)
MRy# = MRy# + ChlorinePos!(N%, 1)
MRz# = MRz# + ChlorinePos!(N%, 2)
Px# = ChlorineVel!(N%, 0) + Px#
Py# = ChlorineVel!(N%, 1) + Py#
Pz# = ChlorineVel!(N%, 2) + Pz#
FOR N%
= 0 TO NoBalls%%
- 1 SodiumPos!(N%, 0) = SodiumPos!(N%, 0) - (MRx# / TotMass#)
SodiumPos!(N%, 1) = SodiumPos!(N%, 1) - (MRy# / TotMass#)
SodiumPos!(N%, 2) = SodiumPos!(N%, 2) - (MRz# / TotMass#)
SodiumVel!(N%, 0) = SodiumVel!(N%, 0) - (Px# / TotMass#)
SodiumVel!(N%, 1) = SodiumVel!(N%, 1) - (Py# / TotMass#)
SodiumVel!(N%, 2) = SodiumVel!(N%, 2) - (Pz# / TotMass#)
ChlorinePos!(N%, 0) = ChlorinePos!(N%, 0) - (MRx# / TotMass#)
ChlorinePos!(N%, 1) = ChlorinePos!(N%, 1) - (MRy# / TotMass#)
ChlorinePos!(N%, 2) = ChlorinePos!(N%, 2) - (MRz# / TotMass#)
ChlorineVel!(N%, 0) = ChlorineVel!(N%, 0) - (Px# / TotMass#)
ChlorineVel!(N%, 1) = ChlorineVel!(N%, 1) - (Py# / TotMass#)
ChlorineVel!(N%, 2) = ChlorineVel!(N%, 2) - (Pz# / TotMass#)