Scaling text

Hi everyone,

I'm just wondering how do you successfully and smoothly increase/decrease the scale of text/type by the positioning of mouse Y?

Basically, when the mouse is at the top of the window I want the text to be small, and when it's at the bottom I want it to be big, and while transitioning from big to small, it is smooth as if it is growing. I hope this makes sense.

At the moment the text jumps from small to big instantly.

As you can tell I'm a beginner, and this may be a very simple command, but regards to coding so far I have:

void setup() { size(1000, 1000);


void draw() { float x = mouseX; float y = mouseY;




textSize (20);

text("john", x, height/2, y, height/2);


Thanks in advance!



  • Answer ✓

    This will give you smooth text scaling between sizes 10 and 410

    void setup() { 
      size(1000, 1000);
    void draw() { 
      textSize( 0.4 * mouseY + 10);
      textAlign(CENTER, CENTER);
      text("John", 0, 0, width, height);
  • Ah thank you so much!

  • @TypeCoding -- if you want to add a time lag or slow growth rate to quark's demo sketch, save the previous size t the end of each draw() and use lerp() at the beginning of each draw to calculate the new size from the previous. The amount (amt) from 0-1 that you set in lerp will be how smoothly or sharply your value changes.

Sign In or Register to comment.