Answer the question
In order to leave comments, you need to log in
How to get a function from a set of values?
The moment is as follows - I'm trying to figure out an algorithm for the following task:
There is a list of players, the players have points. There is a picture, it shows the levels (of which there are currently 6) and the number of points that these levels have.
For example,
level 1 - 601-700
level 2 - 701-800
level 3 - 801-1000
level 4 - 1001-1200
level 5 - 1201-1400
level 6 - 1401-1600
The height picture is determined, but not for long. Now the height of the image is 800 pixels. (Width doesn't matter)
For now, I've written a simple function that takes points and returns pixels. This is a system of equations consisting of 2 equations to be exact. They are obviously linear. On a plot of 600-800 pixels, we get a density of 100 points per level. At 800-1600 we have 200 points per level.
The levels are the same.
And so, I suffered with wolframalpha for half an hour, trying to get her to find me a system of equations. It didn't work out. The problem is that in the future, if someone wants to update the picture, he will have to find a system of equations that describes this function and rewrite them in JavaScript. No matter how difficult it is, but I do not hope for followers.
Here is my solution for this particular picture.
function point2pix(pt)
{
if (pt <=800)
return 800 - ((pt -600)/200)*266
else
return 533 - ((pt - 800)/800)*533
}
Answer the question
In order to leave comments, you need to log in
General idea:
If the height in pixels for each level is fixed, then we count how many pixels one level
occupies PixPerLevel = Height / Levels.Count,
we count whole levels the ScoredLevels player has cycled through the Levels array.
then pix = PixPerLevel * ScoredLevels + tail for the last level (Tail).
The tail for the last level is also easy to calculate
Tail = PixPerLevel * (Score - Levels[ScoredLevels]) / (Levels[ScoredLevels + 1] - Levels[ScoredLevels])
en.wikipedia.org/wiki/%D0%98%D0%BD%D1%82%D0%B5%D1%80%D0%BF%D0%BE%D0%BB%D1%8F%D1%86%D0 %B8%D1%8F
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question