| 1 |
############################################################################### |
| 2 |
## |
| 3 |
## Windsock turbulence animation |
| 4 |
## |
| 5 |
############################################################################### |
| 6 |
|
| 7 |
# SPDX-License-Identifier: GPL-2.0-or-later |
| 8 |
# |
| 9 |
# NOTE! This copyright does *not* cover user models that use these Nasal |
| 10 |
# services by normal function calls - this is merely considered normal use |
| 11 |
# of the code, and does *not* fall under the heading of "derived work." |
| 12 |
# |
| 13 |
# Copyright (C) 2017-2020 by Erik Hofman |
| 14 |
|
| 15 |
var dt = 0.0; |
| 16 |
var windsock = func { |
| 17 |
var wind = getprop("/environment/wind-speed-kt") or 0; |
| 18 |
var mag1 = getprop("/environment/turbulence/magnitude-norm") or 0; |
| 19 |
var mag2 = getprop("/environment/turbulence/raw-magnitude-norm") or 0; |
| 20 |
var sens = getprop("/environment/turbulence/sensitivity") or 1.0; |
| 21 |
var rateHz = getprop("/environment/turbulence/rate-hz") or 0; |
| 22 |
var rate = 3.1514 * rateHz; |
| 23 |
var tot1 = math.sin(dt*rate)*mag1*mag1; |
| 24 |
var tot2 = math.sin(3.33*dt*rate/sens)*sens*mag2*mag2; |
| 25 |
tot2 = mag2*tot2 + (1-mag2)*math.tan(dt/10)/5; |
| 26 |
var total = wind + tot2 + tot1*tot2; |
| 27 |
|
| 28 |
interpolate("/environment/windsock/wind-speed-kt", total, 0.3); |
| 29 |
|
| 30 |
total += 5*mag2; |
| 31 |
interpolate("/environment/windsock/wind-speed-12.5kt", total, 0.1); |
| 32 |
|
| 33 |
dt += 0.08 + 0.02*(math.sin(dt)+math.cos(dt/(mag2+0.01))*0.33); |
| 34 |
} |
| 35 |
windsockTimer = maketimer(0.25, windsock); |
| 36 |
windsockTimer.simulatedTime = 1; |
| 37 |
windsockTimer.start(); |