xxxxxxxxxx
83
const w = 320;
const h = 240;
let centreUv;
let heat
let climate = 0;
let heatFalloffSlider
let heatFalloff = 0.25
function setup() {
createCanvas(w, h);
snow = createVector(255, 255, 255);
grass = createVector(0, 255, 0);
dessert = createVector(255, 255, 0);
hot = createVector(255,0,0)
cold = createVector(255,255,255)
heatFalloffSlider = createSlider( 0, 1, heatFalloff, 0.01)
heatFalloffSlider.position(10, 250);
heatFalloffSlider.input(heatFalloffSliderChanged);
}
function heatFalloffSliderChanged(){
heatFalloff = heatFalloffSlider.value()
console.log(heatFalloff)
draw()
}
function draw() {
background(0, 0, 0);
noFill();
noStroke();
randomSeed(1)
const centreUv = createVector(0.5, 0.5);
for (let y = 0; y < h; y++) {
let climate = y / h - centreUv.y;
for(let x = 0; x < w; x++)
{
let season = x / w - centreUv.x;
let temp = getTemperature(season,climate, heatFalloff+ (sin(x * .05) * .025) )
var heatX = lerp(cold.x, hot.x, temp)
var heatY = lerp(cold.y, hot.y, temp)
var heatZ = lerp(cold.z, hot.z, temp)
set(x,y, color(heatX, heatY, heatZ))
}
}
updatePixels()
stroke(0);
rect(0, 0, w, h);
noLoop();
}
function getTemperature(uvX, uvY, heatFalloff) {
const climate = abs(uvY) * 2;
const heat = abs(uvX) * heatFalloff;
const heatCurve = pow(sin((PI * heat) / 2), 1.5);
let temp = 1 - max(climate - heatCurve, 0)
return temp < heatFalloff ? 0 : temp;
}