Extended Math [v1.0]

MrD69

  • Posts: 235
Stencyl Extended Math
An extension for the game engine Stencyl that adds extra math functions to make math calculations easier.

Stencyl lacks a number of mathematical blocks that would have to be built from scratch for each game that uses functions like averages in a list, factorials, and logarithms of base n. This extension allows you to do these plus much more without building the math functions from scratch.

Download Here: https://github.com/ess4654/Stencyl-Extended-Math



----- Constants -----
NaN


Returns a constant NaN which denotes not a number.

Infinity


Returns a constant which denotes the value of infinity.

Root 2


Returns the value of the square root of 2.

Phi


Returns Phi (the golden ratio) which is equal to (1 + √5)/2 ≈ 1.618

Maximum Bit Integers


Returns the maximum value of an 8, 16, 32, and 64 bit number.

----- Lists -----
Average, Max, Min values in List


Returns a specific number of the value of items in a given list which matches a desired characteristic.
Choices:
- Average
- Max
- Min

Intersection, Union and Subtraction of Lists


Returns a list with a desired modification given 2 lists.
Choices:
- Intersection: Returns a list of items found in both lists.
- Union: Returns a unique set of items found in all lists.
- Subtraction: Returns the first list with all values from the second list removed in the first.

Subset


Returns true if every item is list A is also found in list B.

Summation


Returns the sum of all values in a given list.

Identity Matrix


Returns a matrix square of a given size with 1's along the diagonal

----- Math -----
Is Number


Returns true if a given value is a number.

Is Even/Odd


Returns whether or not a number is even or odd.

+/-


Returns a list of size 2 where the value of A + B is at index 0 and A - B is at index 1.

Inverse


Returns the inverse 1/N of a number.

Divides


Returns true if the first number evenly divides the second.

Modular Arithmetic


Returns true if the remainder of each of the first two numbers divided by the last are the same.

Cube Root


Returns the cube root of a number.

N-th Root


Returns the N-th root of a number

Log with Base


Returns the logarithm of a number with any base.

Factorial


Returns the factorial of a number. ie. (N)(N-1)(N-2)...(1)

Pick


Returns the factorial of a number to a given step. ie. (N)(N-1)(N-2)...(N-(k-1))

Choose


Returns ((N)!/(N-k)!)/(k)!

sinh, cosh, tanh


Returns sinh, cosh, or tanh.
~ sinh = (1/2) (-(1/e^N) + e^N)
~ cosh = (1/2) ((1/e^N) + e^N)
~ tanh = sinh(N)/cosh(N)

Implies


Returns false if the premise is true, but the outcome is false otherwise returns true.

Heaven Side Step


Returns 0 if the number given is 0, 1 if the number given is larger than 0, and -1 if the number given is less than 0.

----- Positional Space -----
Distance Between Actors


Returns the distance between 2 actors in the scene.

----- Geometry -----
Circle


Returns the area or circumference of a circle with radius R.

Rectangle


Returns the area or perimeter of a rectangle with length L and width W.

Last Updated April 7, 2020 v1.0
-------------------------------------------------------------------------------------------------------------------------
Additional Notes: If you require additional math functions that are not included please let me know so I can add them

Contact Me: thejoblesscoder@gmail.com

Extension is Open Sourced and Licensed under MIT open source standards.
Games: Arrow Mania, Breakout/Outbreak, Water Drop


yoplalala

  • *
  • Posts: 1632
Nice extension  !  I like some of the functions.

So I have multiple comments to improve the code and a few ideas for some functions

Code: [Select]
public static function PlusMinus(_A:Float,_B:Float):Array<Dynamic>
{
var plusminus:Array<Dynamic> = new Array<Dynamic>();
plusminus.push(_A + _B);
plusminus.push(_A - _B);
return plusminus;
}
Use Array<Float> instead of Array<Dynamic> .  Try to use dynamic only if you need to.

Same here


   
Code: [Select]
public static function IdentityMatrix(n:Int):Array<Dynamic>
{
n = Math.floor(n);
var list = new Array<Dynamic>();
for(i in 0...n)
{
list.push(new Array<Dynamic>());
You can use Array<Array<Bool>>     and Array<Bool>

You have multiple  functions

Code: [Select]
public static function NaN():Float
{
return Math.NaN;
}

That you can put directly in the blocks.xml.  Also I think they are many functions you can inline to improve the performances :)

https://haxe.org/manual/class-field-inline.html


The ideas will be posted in an other post.


MrD69

  • Posts: 235
Hey thanks for the suggestions I will look into that. As for the Array<Dynamic> returns I believe that is because all arrays used in Stencyl are of the dynamic type and so trying to return an Array of type Float causes errors on compiling.
Games: Arrow Mania, Breakout/Outbreak, Water Drop

Chris24XD

  • Posts: 48
Wow l don't understand all of the things you have created but, great job!!!
Maybe this will help me in cases :)

chongyunxiang

  • Posts: 278
Hi,

I'm trying to use the distance block but there's something I don't understand. I want it to measure the distance between Self and an Actor (pet), but when I created an attribute for pet, it doesn't show in the drop down list when I choose Attribute in the block.

Why is that so?

HopFrog

  • Posts: 49
Hi!

Thanks for this awesome extension, very useful for my current project. Thought I would mention an error I got when running the project with the "Divides" block on Android (works fine on Flash, and works fine on Android without the Divides block):

[haxelib.exe] include/ExtendedMath.h:114:55: error: expected ',' or '...' before numeric constant

I'm not sure how to fix that.

Anyone has any ideas?

Thanks!

« Last Edit: September 20, 2020, 07:43:00 am by HopFrog »