We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, I'm new to processing and I have a small question about Example 5-8 : Easing Does It in the second eddition of the getting started with processing book.
Here is the code:
float x;
float easing = 1;
void setup(){
size(544,416);
}
void draw(){
float targetX = mouseX;
x += (targetX - x)*easing;
ellipse(x, 40, 12, 12);
println(targetX + " : " + x);
}
My question is about the value of x. From my understanding, the value of (targetX - x)*easing is added onto the variable x, but in that formula, x is being taken away. What exactly is the initial value of x, how is this being calculated?
Answers
you can find out by inserting
println(x);
into setup()apart from that, easing should be <1 and background should be used:
https://forum.Processing.org/two/discussion/18404/processing-code-doesn-t-work-in-p5#Item_5
http://studio.SketchPad.cc/sp/pad/view/ro.9XkJm3bjTAxB2/latest
Thank you very much, sorry I feel quite stupid (that should be really obvious, I guess)!
2nd time this has been asked this week, so no, not obvious.
I'd always recommend defining variables with an explicit value for clarity.
Processing uses Java's default initializations if they are not specified (e.g. int 0; String null, boolean false) for global variables -- although clarity in your code is better. The compiler sets float x to 0.0f
https://forum.processing.org/two/discussion/comment/76061/#Comment_76061
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html
but that relies on you knowing the processing is java and then knowing the java defaults 8)
actually, that link above is to a third person asking the same question. which makes me think this is all an assignment.