Replace chatgpt function in clouds.js with human written one

This commit is contained in:
redbirdly 2025-03-30 10:19:31 +08:00 committed by GitHub
parent 9f81b09871
commit 8855d02a91
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 11 deletions

View File

@ -10,17 +10,14 @@ clouds_settingsTab.registerSettings("Real time", cloud_count_setting);
settingsManager.registerTab(clouds_settingsTab); settingsManager.registerTab(clouds_settingsTab);
// Biased random function biasedRandom(A, B, samples) {
function randomGaussian(A, B, biasFactor=2) { var sum = 0;
let u = Math.random(); for (var i = 0;i < samples;i++) {
let v = Math.random(); sum += Math.random();
let num = Math.sqrt(-2.0 * Math.log(u)) * Math.cos(2.0 * Math.PI * v); }
var average = sum / samples;
let mean = (A + B) / 2; return A + average * (B - A);
let stdDev = (B - A) / biasFactor;
let result = mean + num * stdDev;
return Math.min(Math.max(result, A), B);
} }
function randomBetween(A, B) { function randomBetween(A, B) {
@ -32,7 +29,7 @@ function initClouds(amount) {
var w = randomBetween(6, 17); var w = randomBetween(6, 17);
var h = randomBetween(4, 10); var h = randomBetween(4, 10);
var x = randomBetween(0, width - w); var x = randomBetween(0, width - w);
var y = randomGaussian(0, height * 0.75, 4); var y = biasedRandom(0, height * 0.75, 4);
// Higher clouds move faster // Higher clouds move faster
var speedBoost = 1 - (y / (height * 0.75)); var speedBoost = 1 - (y / (height * 0.75));