Ellipse and text scaling issue
in
Programming Questions
•
3 years ago
I have a sketch that shows a moving circle (ellipse) with text over it.
When I increase the scale factor, the text jitters around as it moves. All of the positions are specified with floats, it looks as thought the text position is being cast to integers. Any thoughts on what's going on, and how to fix this?
If use the OpenGL renderer, the text movement is fine, but as I increase the scaling I can see straight edges on the circle. This doesn't happen at all with the default Java2D renderer. Any thoughts on this?
Finally, the text doesn't appear at all with the P2D renderer. Am I missing something, or is this a known bug?
Thanks,
Ollie
Edit: The default renderer is Java2D, not P2D. Updated text
import processing.core.PApplet;
public class RenderingDemo extends PApplet {
float x, y, dx = 0.1f;
float scale = 1;
public void setup() {
size(1200, 600); // , OPENGL); // try P2D and OPENGL to see the issues
smooth();
noStroke();
textFont(createFont("verdana", 12));
textMode(SHAPE);
ellipseMode(CENTER);
}
public void draw() {
background(200);
float tx = width / 2;
float ty = height / 2;
translate(tx, ty);
scale(scale);
fill(127);
ellipse(x, y, 50, 50);
fill(0);
text("text", x, y);
x += dx;
if (x > 100)
dx = -0.1f;
else if (x < -100)
dx = 0.1f;
println(x);
}
public void keyPressed() {
if (key == 'q')
scale += 0.1;
if (key == 'w')
scale -= 0.1;
}
}
1