My old nemesis, math

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: My old nemesis, math

Post by Taehl »

This only will be computed once every ten seconds or so (or six times in one frame, then nothing for 15 seconds), so it's okay for it to be expensive. Here's my final result:

Code: Select all

local n = math.random()
n = (n + .1*math.tanh(1/(3*(n-1/3))) )%1
So, what's n? A random number which can't be too close to 1/3. Or, with a little perspective, flowers in my plant game can't start out green (but can still be bred to there).

Anyway, thanks for the help, everyone. I don't know what I'd do without you.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: My old nemesis, math

Post by kikito »

Just a small thing: it's considered polite to accept one of the answers they give you on any stackexchange site, even if it just "points you" to the right solution without being the exact answer.

You can accept an answer by clicking on the little "flag" on the left of it. You can accept only one answer, but you can "up-vote" (with the little up-down arrows) as many as you want.

Up-voting, and accepting an answer increases the its author's reputation. People with high reputation get more privileges on the forum (for example, they can fix typos on other people's questions, or re-tag them). It'll also increase your acceptance rate (people with 0% acceptance rate get less answers).
When I write def I mean function.
User avatar
ghostwriter
Prole
Posts: 38
Joined: Sat Dec 11, 2010 11:08 pm

Re: My old nemesis, math

Post by ghostwriter »

Here's one that uses "normal" math functions. It hits a peak of 0.1 or -0.1 at x=1/3:

Code: Select all

y=0.1*(x-1/3)/abs(x-1/3)*(exp(-abs((x-1/3)*32)))
func.png
func.png (1.54 KiB) Viewed 770 times
You can "stretch" it by changing the 32 at the end. A lower value makes for a wider falloff, a larger number will make sharper falloff.
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests