Start position in "key pressed"

Hello!

I am trying to create drawing letter, witch consist of ellipse. Every next letter type after key pressed. I can’t change fist position every next letter to create new letter after previous letter and gap space.

ell [][] newell;
int cols = 40;
int rows = 40;
float dist;
int x2;
int y2;

void setup()
{
  size(1000,1000);
  background(255);
  newell = new ell [cols][rows];
  ellipseMode(CORNER);
  
  dist = min(width/cols, height/rows);
  
  for (int i = 0; i < cols; i++)
  {
    for (int j = 0; j < rows; j++)
    {
      if (i%2==0)
      {
        newell [i][j] = new ell (i*dist, j*dist, dist-3);
      } else 
      {
        newell [i][j] = new ell (i*dist, j*dist + 10, dist-3);
      }
      }
    }
}

void draw ()
{ 
  drawdot();
  posXY();
}

void drawdot()
{
  for (int i = 0; i < cols; i++)
  {
    for (int j = 0; j < rows; j++)
    {
      newell [i][j].update();
    }
  }
}

void posXY()
{
  for (int x1 = 2; x1 < 30; x1++) //x1 = 2; y1 = 2; fist dot
  {
    for (int y1 = 2; y1 < rows; y1++)
    {
      x2 = x1 + 4;
      y2 = y1; 
    }
  }
  
  //drawA(x2, y2); not work
  
  drawA(2, 2);
}


void drawA(int x, int y)
{
  if (keyPressed)
  {
    if (key == 'a')
    {
      newell [x][y+1].c1 = 255;
      newell [x+1][y].c1 = 255;
      newell [x+2][y+1].c1 = 255;
      newell [x+2][y+2].c1 = 255;
      newell [x+2][y+3].c1 = 255;
      newell [x+0][y+3].c1 = 255;
      newell [x+1][y+2].c1 = 255;
      newell [x+1][y+3].c1 = 255;
    }
  }
}

class ell
{
  color c1;
  float x;
  float y;
  float s;
  
  ell (float tempx, float tempy, float temps)
  {
    x=tempx;
    y=tempy;
    s=temps;
    c1 = #C0CBD1;
  }
  
  void update()
  {
    fill (c1);
    stroke(#C0CBD1);
    ellipse (x, y, s, s);
  }
}

Thank you for every advice!
And sorry for my bad English. I hope I could explain what I plan to do and what my problem

1 Like

Kill the ; it breaks the if clause

1 Like

Thank you! I delete this, but It’s still not working this way what I wish.

Only one letter ‘a’ is printed. It works without loop. When I try to execute a loop in “void posXY” Processing answer “ArrayIndexOutOfBoundsException: 40”

In which line is this error?

it’s here, in line 72

When y+1 you might want to do the for loop to one less than now

-1

1 Like

@Chrisir thank you for advices, but I understand that I even don’t know how to do what I wish for more simple sketch. I don’t understand how to change position of cursor.

I try to add the size of the object to the X coordinate with each press, as happens when printing letters, for example, in Microsoft Word or a typewriter. Maybe you can suggest a strategy by which this can be done? Or what processing reference to look at?

void setup()
{
  size(500,500);
  background(255);
  ellipseMode(CORNER);
}
void draw()
{
  xFistPos=100; // fist position of X position of rectangle
  objektSize = 40; // size of ellipse or rectangle
  cursorPosition = xFistPos + objektSize; // I don't undestand how I can change cursor position
  
  if (keyPressed)
  {
    if (key == 'a')
    {
      rect(cursorPosition,100, objektSize, objektSize);
    }
    if(key == 'b')
    {
      ellipse(cursorPosition,100, objektSize, objektSize);
    }
  }
}

Welcome to the forum!

This line

cursorPosition = xFistPos + objektSize; //

must be inside the if clause

1 Like