javascript - js implements the algorithm of upper parabola
欧阳克
欧阳克 2017-06-14 10:52:30
0
4
999

  • It’s not about drawing this line, it’s a function, the parameter is an x, and the return value increases with the value of x, showing the trend in the picture above. Please provide such a function, thank you!

欧阳克
欧阳克

温故而知新,可以为师矣。 博客:www.ouyangke.com

reply all(4)
習慣沉默

Upper Parabola? It looks like a quarter circle from the picture. .

Exponential function

For example, quadratic function

y = ax^2 + bx + c

// 柯里化 
var y = a => b => c => x =>  a * x ** 2 + b * x + c; 

// y = x^2 
var ept = y(1)(0)(0); 

About this

Trigonometric functions

Have a look and this one is more consistent. . .

y = -cos wx + o

// 柯里化 
var y = A => W => O => OFFSET =>  x => A * Math.cos(W * x + O) + OFFSET; 

// cosineLine(x) = -1000cos(w)
var cosineLine = y(-1000)(1)(0)(500); 

Probably like this. . . .

Parabola

The mathematical form is

x^2 = 2p * y

that is

y = x ^ 2 / 2p

Same as the exponential function form

// 柯里化 
var y = p => x => x * x / 2p; 

Power function

// y = a^x - 1 
// 柯里化 
var y = a => x => a ** x - 1;

Probably looks like this

Quarter of a circle

Use...canvas' arc to draw an arc

Probably looks like this

g.arc(0,0,800, 0, 2*Math.PI);
g.stroke(); 

However, when x reaches outside the radius, there is no real solution. .


canvas part

Probably like this. . But it is easy to stack overflow. .

function render(g, line, x = 0){
    var y = line(x / 50); 

    if (y <= 800) {
        g.lineTo(x, 800 - y); 
        render(g, line, x + 0.5); 
    } else {
        g.stroke();
    }
}
曾经蜡笔没有小新

Isn’t this a math problem, f(x)=ax*x + bx + c

曾经蜡笔没有小新

function(x) { return x**2; }

伊谢尔伦

function fn(x) {

  return x*x;

}
console.log(fn(9));

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template