Pixelated numbers in a watch

My last questions are about sharpness. This sketch has an animation, specifically that of a clock. How could I make the numbers look perfectly sharp, without pixels around the edges?

void setup() {
  size(600, 600);
  textSize(200);
  textAlign(CENTER, CENTER);
}

void draw() {
  background(0); // Clear the background
  String dateTimeString = nf(hour(), 2) + ":" + nf(minute(), 2);
  text(dateTimeString, width/2, height/2); // Display the formatted string
}

Hello,

It looked good with P2D renderer!

Do you have scaling set in Windows?
I have scaling set to 125% and often see this issue with the default renderer which is JAVA2D if it is not added to size().

Try another renderer (JAVA2D is default, FX2D or P2D):

This shows differences:

Search for this in the forum:

pixelDensity(1)

It appears to solve a lot of issues.

Reference:

:)

you are right! and do you know why text is not centered vertically?

import processing.javafx.*;
void setup() {
  size(600, 600,FX2D);
  textSize(200);
  textAlign(CENTER, CENTER);
}

void draw() {
  background(0); // Clear the background
  String dateTimeString = nf(hour(), 2) + ":" + nf(minute(), 2);
  text(dateTimeString, width/2, height/2); // Display the formatted string

I do not know why it is WAY off with FX2D.

With JAVA2D and P2D it is a bit off and this code can show that:


void setup() 
  {
  size(700, 400, P2D);
  
  textSize(200);
  
  println(textAscent());
  println(textDescent());
  }

boolean tog;

void draw() {
  background(0); // Clear the background
  String dateTimeString = "IjTgJyF";
  float ta = textAscent();
  
  //BASELINE
  if(tog)
    {
    textAlign(CENTER, BASELINE);
    line(0, height/2 - ta, width, height/2 -ta);
    line(0, height/2 - ta/2, width, height/2 -ta/2);
    text(dateTimeString, width/2, height/2); 
    }
  // CENTERED
  else
    {
    textAlign(CENTER, CENTER);
    line(0, height/2 - ta/2, width, height/2-ta/2);  
    text(dateTimeString, width/2, height/2); 
    }
 
  stroke(255);
  line(0, height/2, width, height/2);
  line(width/2, 0, width/2, height);  
  }
  
// Press key to toggle
void keyPressed()
  {
  tog = !tog;
  }

Look up the references and what it says and compare to what was was drawn.
What do you notice?

Experiment with:
textAlign() / Reference / Processing.org

:)

To illustrate this:

import processing.javafx.*; 

void setup() 
  {
  size(700, 400, FX2D);
  textSize(200);
  
  println(textAscent());
  println(textDescent());
  
  noLoop();
  }

boolean tog;

void draw() {
  background(0); // Clear the background
  String str = "IjTgJyF";
  
  float ta = textAscent();
  stroke(0, 255, 0);
  line(0, height/2 - ta/2, width, height/2 - ta/2);  
  
  stroke(255);
  line(0, height/2, width, height/2);
  line(width/2, 0, width/2, height);  
  
  textAlign(CENTER, CENTER);
  text(str, width/2, height/2); 
  }

Output:

There may be a related issue in one of these repositories:

GitHub - processing/processing4: Source code for the Processing Core and Development Environment (PDE)

GitHub - processing/processing4-javafx: JavaFX library for Processing 4

If you do not find one consider submitting one.

:)