EvolvingNatFloat: Difference between revisions

From Vintage Story Wiki
m
Updated navbox to new code navbox.
(Created page with "= EvolvingNatFloat = A number generator whose return value changes over time according a transform and factor.<br> Each sequential value is retrieved according to the first va...")
 
m (Updated navbox to new code navbox.)
 
(9 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{GameVersion|1.19.3}}
= EvolvingNatFloat =
= EvolvingNatFloat =
A number generator whose return value changes over time according a transform and factor.<br>
A number generator whose return value changes over time according to a transform and factor.<br>
Each sequential value is retrieved according to the first value and the sequence number.  
Each sequential value is retrieved according to the first value and the sequence number.  


To use EvolvingNatFloat, add the using statement for '''Vintagestory.API.MathTools'''.
To use EvolvingNatFloat, add the using statement for '''Vintagestory.API.MathTools'''.<br>'''''Important note''': The value of sequence should always satisfy '''sequence >= 0'''''
 
== Example in code ==
== Example in code ==
<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
using Vintagestory.API.MathTools;
using Vintagestory.API.MathTools;


class Example
public class EvolvingNatFloatMod : ModSystem
{
    Example()
     {
     {
        float factor = 1;


         EvolvingNatFloat evolve;
         public override void StartServerSide(ICoreServerAPI api)
        evolve = new EvolvingNatFloat(
        {
            EnumTransformFunction.CLAMPEDPOSITIVESINUS,
            float factor = 1;
            factor
 
            EvolvingNatFloat evolve;
            evolve = new EvolvingNatFloat(
                EnumTransformFunction.CLAMPEDPOSITIVESINUS,
                factor


        );
            );


        float firstValue = 5;
            float firstValue = 5;
        for (float sequence = firstValue; sequence < 100; sequence++)
            for (float sequence = firstValue; sequence < 100; sequence++)
        {
            {
            // Retrieve each sequential value
                // Retrieve each sequential value
            float y = evolve.nextFloat(firstValue, sequence);
                float y = evolve.nextFloat(firstValue, sequence);
            }
         }
         }
     }
     }
}
</syntaxhighlight>
</syntaxhighlight>


Line 84: Line 86:


== Visual representation ==
== Visual representation ==
For every representation, the value of '''factor = 1'''<br>
For every representation except smoothstep, the '''factor = 1'''<br>
For '''linearincrease, linearreduce''', the '''initialValue = 1, -1'''<br>
For every representation except smoothstep, linearnullify, the '''initalValue = 1'''<br>
For every other function, the '''initialValue = 0'''<br>
 
[[File:Txtpositiveclampedsinus.png|180px]]
[[File:Txtcosinus.png|180px]]
[[File:Txtidentical.png|180px]]
[[File:Txtinverselinear.png|180px]]<br><br>
[[File:Txtlinear.png|180px]]
[[File:Txtlinearincrease.png|180px]]
[[File:TxtlinearnullifyFirstValMinusFive.png|180px]]
[[File:Txtlinearreduce.png|180px]]<br><br>
[[File:Txtquadratic.png|180px]]
[[File:Txtroot.png|180px]]
[[File:Txtsinus.png|180px]]
[[File:Txtsmoothstep.png|180px]]


[[File:Annotatedclampedpositivesinus.png|150px]]
{{Navbox/codemodding}}
[[File:Annotatedcosinus.png|150px]]
[[File:Annotatedidentical.png|150px]]
[[File:Annotatedinverselinear.png|150px]]<br><br>
[[File:Annotatedlinear.png|150px]]
[[File:Annotatedlinearincreaseplusminus.png|150px]]
[[File:Annotatedlinearnullify.png|150px]]
[[File:Annotatedlinearreduceplusminus.png|150px]]<br><br>
[[File:Annotatedquadratic.png|150px]]
[[File:Annotatedroot.png|150px]]
[[File:Annotatedsinus.png|150px]]
[[File:Annotatedsmoothstep.png|150px]]
Confirmedusers
536

edits