# A semi-exponential decrease in growth.

4 posts

 I'm making a game which involves growing pumpkins, and I have two factors that affect growth: sunlight and water. I want the amount of growth to be something like this: https://fastly.kastatic.org/ka-perseus-images/7edbd1ab380efb207cf72aa25850838ef6c05824.png but not too steep. To be more clear, each pumpkin has a different optimum sunlight and water level. I only need a script for one factor because once I have that I'll be able to incorporate two. At optimum sunlight (let's just use this for our one factor) I want to have the most growth, then dropping off slowly when you're inside the a certain amount and then quickly. Then, I want it to, at a certain level, do not grow the pumpkins and then, at a certain level, lower the growth factor. The growth factor starts out at 1, but will decrease if you give your pumpkin too much or too little sunshine. I want this to follow the same rule as the growth distribution, going down a little if you're a little over, and a lot if you're a lot over. I want both distributions (growth and growth factor) to be symmetrical, meaning that if I had 2 more sunshine than the optimum amount, my pumpkin would grow the same amount as if I had 2 less sunshine. Might be hard to understand, but I worked out some math a couple years back for doing something like that for crops in Minecraft. https://github.com/Draco18s/HarderStuff/blob/master/src/main/java/com/draco18s/wildlife/WildlifeEventHandler.java#L1416-L1420 Temperature and Rainfall values got read from the current biome and piped through that mess of math (smaller results better). Then a random number would get rolled and if it wasn't 0, the crop wouldn't grow that update tick. This meant there was a narrow range of ideal temperature and rainfaill values, but being slightly outside meant small drop-offs, but the farther you moved away from optimal the faster and faster the drop-offs got due to the x^4 values. Note that rainfall and temperature curves operated differently, as there were different expected values (how wet/dry Minecraft biomes got, vs. how hot/cold) although both generally range 0-2 with 0.8 being "ideal" (e.g. about 80 degrees F and 1" of rain†) † The units in Minecraft are arbitrary but I wanted the "peak ideal value" to be equivalent to the temperature and just tacked on a unit of measure. It *roughly* corresponds to the monthly rainfall in real-world terms, minus 1 inch (that is, 1 MCU of rain would be 2"/mo and 2 MCU would be 3"/mo). > *Originally posted by **[Draco18s](/forums/4/topics/752055?page=1#11228853)**:* > Might be hard to understand, but I worked out some math a couple years back for doing something like that for crops in Minecraft. > > https://github.com/Draco18s/HarderStuff/blob/master/src/main/java/com/draco18s/wildlife/WildlifeEventHandler.java#L1416-L1420 > > Temperature and Rainfall values got read from the current biome and piped through that mess of math (smaller results better). Then a random number would get rolled and if it wasn't 0, the crop wouldn't grow that update tick. This meant there was a narrow range of ideal temperature and rainfaill values, but being slightly outside meant small drop-offs, but the farther you moved away from optimal the faster and faster the drop-offs got due to the x^4 values. > > Note that rainfall and temperature curves operated differently, as there were different expected values (how wet/dry Minecraft biomes got, vs. how hot/cold) although both generally range 0-2 with 0.8 being "ideal" (e.g. about 80 degrees F and 1" of rain†) > > † The units in Minecraft are arbitrary but I wanted the "peak ideal value" to be equivalent to the temperature and just tacked on a unit of measure. It *roughly* corresponds to the monthly rainfall in real-world terms, minus 1 inch (that is, 1 MCU of rain would be 2"/mo and 2 MCU would be 3"/mo). Yes, quite useful, but I forgot to mention: I'm building this game with javascript... The language doesn't matter. Algorithms can be implemented in any language assuming that language has a sin/cos/tan lookup table.