Godot Nature of Code  1.2.0
Nature of Code implemented in Godot Engine
Static Public Member Functions | List of all members
MathUtils Class Reference

Math utility functions More...

Static Public Member Functions

static float Map (float value, float istart, float istop, float ostart, float ostop)
 Map a value from one bound to another. More...
 
static float Randf ()
 Return a random floating number between 0 and 1. More...
 
static int RandRangei (int min, int max)
 Return an int RandRange. More...
 
static float SignedRandf ()
 Return a signed Randf, between -1 and 1. More...
 
static float RandRangef (float min, float max)
 Return a float RandRange. More...
 
static Vector2 RandRangeVector2X (float minX, float maxX, float y)
 Return a Vector with X in a random range. More...
 
static Vector2 RandRangeVector2Y (float x, float minY, float maxY)
 Return a Vector with Y in a random range. More...
 
static Vector2 RandVector2 (Vector2 rangeX, Vector2 rangeY)
 Return a Vector with coordinates in a random range (vector limits). More...
 
static Vector2 RandVector2 (float minX, float maxX, float minY, float maxY)
 Return a Vector with coordinates in a random range (float limits). More...
 
static Color RandColor ()
 Return a random color. More...
 

Detailed Description

Math utility functions

Definition at line 6 of file MathUtils.cs.

Member Function Documentation

◆ Map()

static float MathUtils.Map ( float  value,
float  istart,
float  istop,
float  ostart,
float  ostop 
)
inlinestatic

Map a value from one bound to another.

Parameters
valueValue to map
istartOriginal lower bound
istopOriginal upper bound
ostartTarget lower bound
ostopTarget upper bound
Returns
Mapped value

Definition at line 17 of file MathUtils.cs.

18  {
19  return ostart + ((ostop - ostart) * ((value - istart) / (istop - istart)));
20  }

◆ RandColor()

static Color MathUtils.RandColor ( )
inlinestatic

Return a random color.

Returns
Random color

Definition at line 118 of file MathUtils.cs.

119  {
120  return new Color((float)GD.RandRange(0, 1), (float)GD.RandRange(0, 1), (float)GD.RandRange(0, 1));
121  }

◆ Randf()

static float MathUtils.Randf ( )
inlinestatic

Return a random floating number between 0 and 1.

Returns
Random floating number

Definition at line 26 of file MathUtils.cs.

27  {
28  return (float)GD.RandRange(0, 1);
29  }

◆ RandRangef()

static float MathUtils.RandRangef ( float  min,
float  max 
)
inlinestatic

Return a float RandRange.

Parameters
minLower bound
maxUpper bound
Returns
Random float

Definition at line 57 of file MathUtils.cs.

58  {
59  return (float)GD.RandRange(min, max);
60  }

◆ RandRangei()

static int MathUtils.RandRangei ( int  min,
int  max 
)
inlinestatic

Return an int RandRange.

Parameters
minLower bound
maxUpper bound
Returns
Random int

Definition at line 37 of file MathUtils.cs.

38  {
39  return Mathf.RoundToInt(RandRangef(min, max));
40  }
static float RandRangef(float min, float max)
Return a float RandRange.
Definition: MathUtils.cs:57

◆ RandRangeVector2X()

static Vector2 MathUtils.RandRangeVector2X ( float  minX,
float  maxX,
float  y 
)
inlinestatic

Return a Vector with X in a random range.

Parameters
minXX lower bound
maxXX upper bound
yFixed Y value
Returns
Random vector

Definition at line 69 of file MathUtils.cs.

70  {
71  return new Vector2(RandRangef(minX, maxX), y);
72  }

◆ RandRangeVector2Y()

static Vector2 MathUtils.RandRangeVector2Y ( float  x,
float  minY,
float  maxY 
)
inlinestatic

Return a Vector with Y in a random range.

Parameters
xFixed X value
minYY lower bound
maxYY upper bound
Returns
Random vector

Definition at line 81 of file MathUtils.cs.

82  {
83  return new Vector2(x, RandRangef(minY, maxY));
84  }

◆ RandVector2() [1/2]

static Vector2 MathUtils.RandVector2 ( float  minX,
float  maxX,
float  minY,
float  maxY 
)
inlinestatic

Return a Vector with coordinates in a random range (float limits).

Parameters
minXX lower bound
maxXX upper bound
minYY lower bound
maxYY upper bound
Returns
Random vector

Definition at line 105 of file MathUtils.cs.

106  {
107  var vec = Vector2.Zero;
108  vec.x = (float)GD.RandRange(minX, maxX);
109  vec.y = (float)GD.RandRange(minY, maxY);
110 
111  return vec;
112  }

◆ RandVector2() [2/2]

static Vector2 MathUtils.RandVector2 ( Vector2  rangeX,
Vector2  rangeY 
)
inlinestatic

Return a Vector with coordinates in a random range (vector limits).

Parameters
rangeXX bounds
rangeYY bounds
Returns
Random vector

Definition at line 92 of file MathUtils.cs.

93  {
94  return RandVector2(rangeX.x, rangeX.y, rangeY.x, rangeY.y);
95  }
static Vector2 RandVector2(Vector2 rangeX, Vector2 rangeY)
Return a Vector with coordinates in a random range (vector limits).
Definition: MathUtils.cs:92

◆ SignedRandf()

static float MathUtils.SignedRandf ( )
inlinestatic

Return a signed Randf, between -1 and 1.

Returns
Signed random floating number

Definition at line 46 of file MathUtils.cs.

47  {
48  return Map((float)GD.RandRange(0, 1), 0, 1, -1, 1);
49  }
static float Map(float value, float istart, float istop, float ostart, float ostop)
Map a value from one bound to another.
Definition: MathUtils.cs:17

The documentation for this class was generated from the following file: