Skip to content

Instantly share code, notes, and snippets.

@GutterCat42
Last active September 15, 2023 07:10
Show Gist options
  • Save GutterCat42/5b4c82bbb1efc6199514cc84ce997e3c to your computer and use it in GitHub Desktop.
Save GutterCat42/5b4c82bbb1efc6199514cc84ce997e3c to your computer and use it in GitHub Desktop.
Graphwar Functions

Some functions for use in Graphwar

(Work in progress)

Credit to: My schooling, and https://youtu.be/E_MmkxTO5kg (kudos to whoever chose the music for this video)

NOTE: I am not a mathematician. I apologise for any errors.

Linear equation

y = mx Where m is the gradient.

Quadratic equation (parabola)

y = a(x-h)^2 where a is the dilation and (h, k) is the co-ordinate of the turning point.

Absolute

y = a*abs(x-b) where a is the slope and b is the x coordinate of the turning point. Absolutes can be chained by simply adding (or subtracting) them together.

Double absolute (diagonal line)

y=a*abs(x-b)-a*abs(x-c) or ((h/2)/(b-c))(abs(x+b)-abs(x+c)) where a is half of the gradient, h is the total height of the slope, b is the x coord of the slope's start, and c is the x coord of the slope's end.

Spike (Lorentziana function)

y = a/(1+(x-b)^2) where a is the amplitude of the spike (pos = up, neg = down) and b is the x coordinate of the spike's tip.

Sine spike (sinc)

y = a*sin(b*(x-c))/(b*(x-c)) where a is the amplitude of the spike, b is the frequency, and c is the x coordinate.

Step (heaviside step function)

y = k/(1+exp(a*(x-c))) where k is the height of the step, a is the steepness of the step, and c is the x coordinate of the step.

Sine

y = a*sin(bx) where a is the amplitude and b is the frequency.

Exponential/Delayed sine

sin(kx)/(1+exp(-a*(x+c))) where kis frequency, a is the rate at which to wave starts, and c is the x coord of the beginning of the wave.

Recursive Spike

y = (a*exp(b*sin(kx)))/(1+exp(-j*(x+c))) where a is top amplitude, b is top and bottom amplitude, k is spike freq, j is spike progressive height, c is the x displacement from center.

@a0fefd
Copy link

a0fefd commented Sep 14, 2023

Delayed sine is (h*sin(kx))/(1+exp(-a*(x-c))) the variables are self explanatory.

@a0fefd
Copy link

a0fefd commented Sep 14, 2023

Also you missed double absolute (aka diagonal step)

@GutterCat42
Copy link
Author

How is that the formula for delayed sine if there isn't even a sin() in it? I put it into desmos and it was more of a double absolute but curvy
image

I will add double absolute, is the equation just y=a*abs(x-b)+a*abs(x-c)?

@GutterCat42
Copy link
Author

Nevermind, its y=a*abs(x-b)-a*abs(x-c) where a is half of the gradient (?), b is the x coord of the first horizontal line, and c is the x coord of the second horizontal line.

@a0fefd
Copy link

a0fefd commented Sep 14, 2023

How is that the formula for delayed sine if there isn't even a sin() in it? I put it into desmos and it was more of a double absolute but curvy image

I will add double absolute, is the equation just y=a*abs(x-b)+a*abs(x-c)?

My bad I missed something in it it starts with hsin(kx)/(1+...

@a0fefd
Copy link

a0fefd commented Sep 14, 2023

Nevermind, its y=a*abs(x-b)-a*abs(x-c) where a is half of the gradient (?), b is the x coord of the first horizontal line, and c is the x coord of the second horizontal line.

image

Proof:
image

@a0fefd
Copy link

a0fefd commented Sep 14, 2023

Here is my own equation that I whipped up with a sprinkle of terrorism
(a*exp(b*sin(kx)))/(1+exp(-j*(x+c))) where a is top amplitude, b is top and bottom amplitude, k is spike freq, j is spike progressive height (similar to step a), c is start (same as step)

I call it the Recursive Spike

@GutterCat42
Copy link
Author

GutterCat42 commented Sep 14, 2023

Very nice
I shall add it

'Special spiky sine'

@GutterCat42
Copy link
Author

Alright I'll make it the 'Recursive Spike'.

Check if my equations are correct please ;)

@a0fefd
Copy link

a0fefd commented Sep 14, 2023

Alright I'll make it the 'Recursive Spike'.

Check if my equations are correct please ;)

Better wording for the c variable would be something like x displacement from center.

@GutterCat42
Copy link
Author

Changed it to exactly that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment