# Start position in "key pressed"

**URL:** <https://discourse.processing.org/t/start-position-in-key-pressed/18477>\
**Category:** Coding Questions\
**Created:** [March 7, 2020, 8:11am UTC](https://discourse.processing.org/t/start-position-in-key-pressed/18477 "2020-03-07T08:11:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![lemoskava](https://avatars.discourse-cdn.com/v4/letter/l/5f9b8f/32.png) [@lemoskava](https://discourse.processing.org/u/lemoskava)\
**Post date:** [March 7, 2020, 8:11am UTC](https://discourse.processing.org/t/start-position-in-key-pressed/18477/1 "2020-03-07T08:11:40Z")

</div>

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.

```auto
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

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [March 7, 2020, 10:37am UTC](https://discourse.processing.org/t/start-position-in-key-pressed/18477/2 "2020-03-07T10:37:06Z")

</div>

> [@lemoskava](#):
>
> if (keyPressed);

Kill the ; it breaks the if clause

---

<div class="post-metadata">

**Author:** ![lemoskava](https://avatars.discourse-cdn.com/v4/letter/l/5f9b8f/32.png) [@lemoskava](https://discourse.processing.org/u/lemoskava)\
**Post date:** [March 7, 2020, 12:36pm UTC](https://discourse.processing.org/t/start-position-in-key-pressed/18477/3 "2020-03-07T12:36:35Z")

</div>

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”

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [March 7, 2020, 12:37pm UTC](https://discourse.processing.org/t/start-position-in-key-pressed/18477/4 "2020-03-07T12:37:33Z")

</div>

In which line is this error?

---

<div class="post-metadata">

**Author:** ![lemoskava](https://avatars.discourse-cdn.com/v4/letter/l/5f9b8f/32.png) [@lemoskava](https://discourse.processing.org/u/lemoskava)\
**Post date:** [March 7, 2020, 12:42pm UTC](https://discourse.processing.org/t/start-position-in-key-pressed/18477/5 "2020-03-07T12:42:07Z")

</div>

> [@lemoskava](#):
>
> newell [y+1].c1 = 255;

it’s here, in line 72

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [March 7, 2020, 12:54pm UTC](https://discourse.processing.org/t/start-position-in-key-pressed/18477/6 "2020-03-07T12:54:19Z")

</div>

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

-1

---

<div class="post-metadata">

**Author:** ![lemoskava](https://avatars.discourse-cdn.com/v4/letter/l/5f9b8f/32.png) [@lemoskava](https://discourse.processing.org/u/lemoskava)\
**Post date:** [March 14, 2020, 5:52pm UTC](https://discourse.processing.org/t/start-position-in-key-pressed/18477/7 "2020-03-14T17:52:24Z")

</div>

@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?

```auto
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);
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [March 14, 2020, 6:01pm UTC](https://discourse.processing.org/t/start-position-in-key-pressed/18477/8 "2020-03-14T18:01:55Z")

</div>

Welcome to the forum!

This line

cursorPosition = xFistPos + objektSize; //

must be inside the if clause
