I would like to draw a “pixelated” string in Java. Here is an example of what I mean by a "pixel" row:

This is my code that my code is trying to do. Suppose the line goes from (x1, y1)to (x2, y2)and that I want a 10 "block long line between them (I would call them pixels, but they will be displayed using a large number of pixels):
( , ...) grid, grid[i][j] (is true), 10 (x1 + (i * widthScalingFactor), yOffset + (j * heightScalingFactor)).
:
public static void drawPixelatedLine(Graphics g, int x1, int y1, int x2, int y2) {
int widthOriginal = x2 - x1;
int heightOriginal = y2 - y1;
if(widthOriginal <= 0 && heightOriginal <= 0){
int temp = x2;
x2 = x1;
x1 = temp;
temp = y2;
y2 = y1;
y1 = temp;
}
double cOriginal = Math.sqrt(widthOriginal * widthOriginal + heightOriginal * heightOriginal);
double shrinkingFactor = 10d / cOriginal;
int newWidth = (int) Math.round(shrinkingFactor * widthOriginal);
int newHeight = (int) Math.round(shrinkingFactor * heightOriginal);
newWidth = (newWidth <= 0 ? 1 : newWidth);
newHeight = (newHeight <= 0 ? 1 : newHeight);
boolean[][] grid = new boolean[newWidth][newHeight];
int rescaledX1 = 0;
int rescaledY1 = 0;
int rescaledX2 = newWidth - 1;
int rescaledY2 = newHeight - 1;
int x = rescaledX1;
int y = rescaledY1;
int dx = Math.abs(rescaledX2 - rescaledX1);
int dy = Math.abs(rescaledY2 - rescaledY1);
int s1 = Utils.sign(rescaledX2 - rescaledX1);
int s2 = Utils.sign(rescaledY2 - rescaledY1);
boolean swap = false;
if (dy > dx) {
int temp = dx;
dx = dy;
dy = temp;
swap = true;
}
int D = 2 * dy - dx;
for (int i = 0; i < dx; i += 1) {
grid[x][y] = true;
while (D >= 0) {
D = D - 2 * dx;
if (swap) {
x += s1;
}
else {
y += s2;
}
}
D = D + 2 * dy;
if (swap) {
y += s2;
}
else {
x += s1;
}
}
int xOffset = x1;
int yOffset = y1;
float widthScalingFactor = (float) widthOriginal / (float) newWidth;
float heightScalingFactor = (float) heightOriginal / (float) newHeight;
for(int i = 0; i < grid.length; i++){
for(int j = 0; j < grid[0].length; j++){
if(grid[i][j]){
g.fillRect((int) (xOffset + (i * widthScalingFactor)), (int) (yOffset + (j * heightScalingFactor)), 10, 10);
}
}
}
, - -, , , (, , , 10 10 , , , ~ 140 . , - -, . .
, - ( /).

, -, , , , . -, , y.

, , -, 2 , -. , , .
, "" ?