Random directions, with no repeat.. (Bad Description)

Posted by Neurofluxation on Stack Overflow See other posts from Stack Overflow or by Neurofluxation
Published on 2010-03-24T10:39:09Z Indexed on 2010/03/24 10:43 UTC
Read the original article Hit count: 301

Filed under:
|
|

Hey there, So I'm knocking together a random pattern generation thing.

My code so far:

  int permutes = 100;
  int y = 31;
  int x = 63;

  while (permutes > 0) {
    int rndTurn = random(1, 4);

    if (rndTurn == 1) { y = y - 1; } //go up
    if (rndTurn == 2) { y = y + 1; } //go down
    if (rndTurn == 3) { x = x - 1; } //go right
    if (rndTurn == 4) { x = x + 1; } //go left

    setP(x, y, 1);
    delay(250);
  }

My question is, how would I go about getting the code to not go back on itself?

e.g. The code says "Go Left" but the next loop through it says "Go Right", how can I stop this?

NOTE: setP turns a specific pixel on.

Cheers peoples!

© Stack Overflow or respective owner

Related posts about c

    Related posts about c#