Back to Recipes Homepage
recipe picture
Recipe: Sawtooth function
3.833335
Your rating: None Average: 3.8 (6 votes)
Used 48 times with an average impact of 843 points.

Profile

Name: Sawtooth function
ID: 2593
Created on: Fri, 05/28/2010 - 11:19
Updated on: Fri, 05/28/2010 - 11:19
Description:

When dealing with random values, this function trims positive and negative values to your desired range. This example trims all incoming values to a scale from 1 to 10.



Best For


Comments

Joined: 09/18/2009
Groups: SETI.Germany
Score Impact

I still don't get why this recipe creates a score impact, although it only outputs some text to show how the function works and doesn't do any changes on the puzzle itself.
If you know why, tell me, please.

Joined: 09/18/2009
Groups: SETI.Germany
More...

Note that this function intendedly doesn't work symmetric (similar to the sinus-function, which also isn't symmetric at the y-axis) to keep the "waveform" homogenous on the x-axis.
If you want a symmetric output, use absolute values as function-input.

Joined: 09/18/2009
Groups: SETI.Germany
That's how the code does look like

function Sawtooth(x,range) -- returns values between only 1 and range
x2=x
if x2>0 then
x2=((x2-1)%range)+1
else
x2=range-(-x2%range)
end
return x2
end

for k=15,-15,-1 do
l=Sawtooth(k,10)
print (k," ",l)
end

Want to try?
Add to Cookbook!
To download recipes to your cookbook, you need to have the game client running.
Parent

none

Children

none

Authors
Sitemap

Developed by: UW Center for Game Science, UW Institute for Protein Design, Northeastern University, Vanderbilt University Meiler Lab, UC Davis
Supported by: DARPA, NSF, NIH, HHMI, Amazon, Microsoft, Adobe, RosettaCommons