Codetoy doesn't add its own math library. Each language's standard one is available:
AssemblyScript C# Python Where math lives
Math. sin ( x) Math. cos ( x) Math. atan2 ( y, x)
Math. sqrt ( x) Math. pow ( b, e) Math. abs ( x)
Math. floor ( x) Math. ceil ( x) Math. round ( x)
Math. min ( a, b) Math. max ( a, b)
Math. random ( )
Math. PI Math. E
Math. Sin ( x) Math. Cos ( x) Math. Atan2( y, x)
Math. Sqrt ( x) Math. Pow( b, e) Math. Abs ( x)
Math. Floor ( x) Math. Ceiling ( x) Math. Round ( x)
Math. Min( a, b) Math. Max( a, b) Math. Clamp( v, lo, hi)
Random. Shared. NextDouble ( )
Math. PI Math. E Math. Tauimport math, random
math. sin( x) math. cos( x) math. atan2( y, x)
math. sqrt( x) math. pow ( b, e) abs ( x)
math. floor( x) math. ceil( x) round ( x)
min ( a, b) max ( a, b)
random. random( )
random. uniform( a, b) random. randint( a, b)
math. pi math. e math. tau
# Angles are radians
Every angle in Codetoy (rotate() Canvas.Rotate() rotate() , arc() not in C# arc() , Math.sin() Math.Sin() math.sin() , Math.cos() Math.Cos() math.cos() ) is in radians . A full turn is 2π, about 6.283. To convert degrees: radians = degrees * π / 180.
# Recipes
# Distance between two points
AssemblyScript C# Python
const dx = x2 - x1, dy = y2 - y1
const dist = Math. sqrt ( dx * dx + dy * dy)
const hit = dist < r1 + r2 double dx = x2 - x1, dy = y2 - y1;
double dist = Math. Sqrt ( dx * dx + dy * dy) ;
bool hit = dist < r1 + r2; dist = math. hypot( x2 - x1, y2 - y1)
hit = dist < r1 + r2
# Angle toward a point
AssemblyScript C# Python
const angle = Math. atan2 ( input. mouseY ( ) - y, input. mouseX ( ) - x)
x += Math. cos ( angle) * speed * deltaTime ( )
y += Math. sin ( angle) * speed * deltaTime ( ) double angle = Math. Atan2 ( Input. MouseY - y, Input. MouseX - x) ;
x += Math. Cos ( angle) * speed * Screen. DeltaTime;
y += Math. Sin ( angle) * speed * Screen. DeltaTime; angle = math. atan2( mouseY( ) - y, mouseX( ) - x)
x += math. cos( angle) * speed * deltaTime( )
y += math. sin( angle) * speed * deltaTime( )
# Random number in a range
AssemblyScript C# Python
function randomRange ( min: f64, max: f64) : f64 {
return min + Math. random ( ) * ( max - min)
} double RandomRange ( double min, double max) => min + Random. Shared. NextDouble ( ) * ( max - min) ; random. uniform( min_value, max_value)
# Clamp and lerp
AssemblyScript C# Python
function clamp ( v: f64, lo: f64, hi: f64) : f64 { return Math. max ( lo, Math. min ( hi, v) ) }
function lerp ( a: f64, b: f64, t: f64) : f64 { return a + ( b - a) * t } double clamped = Math. Clamp ( v, lo, hi) ;
double Lerp ( double a, double b, double t) => a + ( b - a) * t; def clamp ( v, lo, hi) : return max ( lo, min ( hi, v) )
def lerp ( a, b, t) : return a + ( b - a) * t
# Rectangle overlap (AABB)
AssemblyScript C# Python
function overlaps ( ax: f64, ay: f64, aw: f64, ah: f64, bx: f64, by: f64, bw: f64, bh: f64) : bool {
return ax < bx + bw && ax + aw > bx && ay < by + bh && ay + ah > by
} bool Overlaps ( double ax, double ay, double aw, double ah, double bx, double by , double bw, double bh) =>
ax < bx + bw && ax + aw > bx && ay < by + bh && ay + ah > by ; def overlaps ( ax, ay, aw, ah, bx, by, bw, bh) :
return ax < bx + bw and ax + aw > bx and ay < by + bh and ay + ah > by