What does t / = d mean? Python and errors

// t: current time, b: begInnIng value, c: change In value, d: duration

def: 'easeOutQuad',
swing: function (x, t, b, c, d) {
    //alert(jQuery.easing.default);
    return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
},
easeInQuad: function (x, t, b, c, d) {
    return c*(t/=d)*t + b;
},
easeOutQuad: function (x, t, b, c, d) {
    return -c *(t/=d)*(t-2) + b;
},

I'm trying to convert Robert Penner functions to Python functions and get stuck! Any help or anyone else done this before?

https://github.com/danro/jquery-easing/blob/master/jquery.easing.js

+5
source share
5 answers

In JavaScript and Python /=, this is an extended-purpose statement that has almost the same meaning.

In JS:

var i = 10;
i /= 2;

... is equivalent to:

var i = 10;
i = i / 2;

And, in Python:

i = 10
i /= 2

... is also equivalent (not exactly the same, but close enough for numbers):

i = 10
i = i / 2

However, there is one very big difference.

In JavaScript, assignment is an expression - it has a value, and this value is the value assigned to the variable. So:

var i = 10;
var j = i /= 2;

... roughly equivalent to:

var i = 10;
i /= 2;
var j = i;

Python - . . :

i = 10
j = i /= 2

... a SyntaxError.


, ( ) , / , - . ( , ...)

, JS ( , ?):

def easeInQuad(x, t, b, c, d):
    t /= d
    return c*t*t+b

:

old_t = t
t /= d

t t/=d old_t t/=d . , , old_t.

, , t , , :

return c * (t/d) * (t/d) + b
return c * (t/d)**2 + b
return c * t*t / d*d + b

-, C, , " ". , , - , . !

, :

t_over_d = t/d
return c * t_over_d * t_over_d + b

... , C, , . , , , , 1985, , t , t_over_d , , , ?

JS Python , -, , . ( JIT V8 PyPy) , .

, , "" , , , , , , , .


, JavaScript ...

-, JavaScript ", Firefox" ( " Spidermonkey", ), , JavaScript 2 , , ?). ECMAScript , , JS ( ) , , ECMAScript 5.1 , ( , "" "). .

, ES 5.1: 11.5 , (t/=d) t, 11.13.2 , t/=d t . ( , "", GetValue a SetValue, , .)

+6

/= - . t /= d t = t / d. +=, -= *= , ...

+1

, +=, .

t = t / d
+1
c*(t/=d)*t + b;

t /= d            # or t = t / d
c * t * t + b

Python

, t d int/long, Python2

easeOutQuad

def easeOutQuad (x, t, b, c, d):
    t /= d
    return -c * t * (t - 2) + b
+1

.

>>> p = 6
>>> p /= 2
>>> p
3
0
source

All Articles