We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am trying to create a boomerang (instagram) type effect for 3D text, where the text rotates from one orientation then rotates the opposite direction but is smooth and does not jump. This rotation should continue in an infinite loop (example for video shown here ). The closest I can get is
p.draw = function() {
if (mouseIsPressed) {
p.background('#c3f2cf');
p.push();
p.translate(-60, 50, 35);
if (second() % 2 == 0) {
setInterval(function() {i = i + 1}, 500);
} else {
setInterval(function() {i = i - 1}, 500);
}
p.rotateX(i);
p.texture(img2);
p.scale(0.7);
p.model(dearlove);
p.pop();
}
else {
p.background(255);
}
}
I am using instance mode here. Essentially I am trying to make an ascending and descending list of numbers that is passed to the p.rotateX for the p.model(dearlove). But the numbers should ascend to one value, then descend FROM that value. I can almost get the effect I want by
p.draw = function() {
if (second()%2 == 0) {
i = 0.03;
} else {
i = -0.03
}
p.push();
p.translate(-60, 50, 35);
p.rotateX(p.frameCount * i);
p.texture(img2);
p.scale(0.7);
p.model(dearlove);
p.pop();
}
but the 3D text jumps orientations when switching the direction of rotation. I'm sure I'm over thinking this. Cannot figure out how to get around the lack of a sleep() function in javascript. Let me know if further clarification is needed. Thanks.
Answers
One way of approaching this kind of problem is:
sin()
to generate input, andmap()
(-1,1) to (0,1) to bounce back and forth.For previous example, see:
Thanks for the quick response, I have attempted a solution using what you recommended which looked something like
but the output from the sine function is still very jumpy. I have attempted another solution that looks like the following(I have removed extraneous lines of code)
and this almost works, as the numbers do oscillate up and down, but the sequence of numbers approaches infinity rather than forever oscillating. Any thoughts? Thanks.
Just got this to work! Needed to define the variable for the setInterval outside of the if statement. Thanks for your help!
Just now noticing that this works around 80% of the time. Occasionally negativie numbers win out, and the model rotates only one direction, rather than bouncing. Currently am playing with the timing of the setIntervals, to see if this has an effect.
Demo at http://p5js.sketchpad.cc/sp/pad/view/En0henvcHV/latest
Notice that it seems
image()
is not yet (properly) implemented in p5.js when using the WebGJ renderer. See https: //github.com/processing/p5.js/issues/1507Kf