雨上がりの空気って好きです。
;mm,kg,sec
#include "d3m.hsp"
#define global RIPPLE_DIV 15 // 波紋を何分割して描画するか(大きければ大きいほどなめらかな円に近づく)
;#################################################################
;「はずむ虹の輪」を参考
#module
;輪を描画 xy平面に描画します。
#deffunc m_d3circle int _x, int _y, int _z, int _r
d3setlocal _x, _y, _z ;中心座標
d3initlineto
repeat RIPPLE_DIV + 1
t = 2.0 * M_PI / RIPPLE_DIV * cnt
d3lineto cos( t ) * _r, sin( t ) * _r
loop
return
#global
;#################################################################
;カメラ基準座標
camx = 5000 : camy = 5000 : camz = 1500
;波紋の管理用配列変数
dim r, 4, 500 ;xyrf
*main
redraw 1 : await 16 : redraw 0 : color : boxf : color 255, 255, 255 : pos 0,0
ct++ ;経過フレーム(経過時間)
stick key : if key&128 : end ;ESC = END
; カメラ座標
d3setcam cos(0.01 * ct) * camx, sin(0.01 * ct) * camy, camz, 0, 0, 1000
; 雨を描画
randomize 0
repeat 500
x = rnd(8000) - 4000
y = rnd(8000) - 4000
z = -rnd(8000)
;雨の直径と終端速度の関係
;φ1.0(680cm/sec)、φ2.0(962cm/sec)
;(680cm/s*10) * (30ms/1000) = 204mm/フレーム
;(962cm/s*10) * (30ms/1000) = 288.6mm/フレーム
;288.6 - 204 = 84.6
v = -204 -rnd(85)
z = (ct * v + z) \ 8000 + 8000
z0 = z - v ;残像を表示
;雨ライン
d3line x, y, z, x, y, z0
a = rnd(5) ;波紋の数に制限をかける。
; if z0>8000 { ;これにするとすべての波紋を描画する。重い。
if (z0>8000)&(a<1) {
r(0, rc) = x, y, 0, 30
rc++
if rc>=500 : rc = 0 ;一定個数以上の波紋を作らないようにしている。
}
;波の伝播速度=sqrt(g*h)
;g重力加速度、h深さ
;50cm/s = 15mm/フレーム
if r(3, cnt) > 0 {
r(2,cnt)+=15
color 255.0*r(3,cnt)/30, 255.0*r(3,cnt)/30, 255.0*r(3,cnt)/30
m_d3circle r(0, cnt), r(1, cnt), 0, r(2, cnt)
d3setlocal 0,0,0, 1,0,0, 0,1,0, 0,0,1 ;元のグローバル座標系に戻す。m_d3circleの後には必ず必要。
r(3, cnt)--
color 255,255,255
}
loop
goto *main