FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Programs
(Moderators: fry, REAS)
   very odd...
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: very odd...  (Read 258 times)
Mythmon


very odd...
« on: Feb 28th, 2004, 6:03am »

Im trying to make a small A-Life experimant, to help me learn P5. When its done, the dots (currently disabled) will move around and when the hit and edge the will bounce off and when the hit a grey "antiDot" they will either turn left or right. Now my problem is that these "antiDots" arn't drawing! As far as i can tell they _should_ be drawing, but they arnt, I would appreciate it if someone would look over this and help me troubleshoot it.
 
Thanks in advance.
 
 
Code:

int black = 0x000000, grey = 0x7F7F7F, white = 0xFFFFFF;
 
int howManyDots = 0;
Dot[] dots = new Dot[howManyDots];
 
int howManyAntiDots = 10;
AntiDot[] antiDots = new AntiDot[howManyAntiDots];
 
int[][] screen = new int[200][200];
 
void setup()
{
  size(200,200);
  background(white);
  makeDots();
  makeAntiDots();
  clearScreen();
  colorMode(RGB);
}
 
void clearScreen()
{
  background(0xFFFFFF);
  for (int i=0; i<200; i++)
  {
    for (int j=0; j<200; j++)
    {
 screen[i][j] = 0;
    }
  }
}
 
void makeDots()
{
  for (int i=0; i<howManyDots; i++)
  {
    dots[i] = new Dot(int(random(200)),int(random(200)),int(random(-1,8)));
  }
}
 
void makeAntiDots()
{
  for(int i=0; i<howManyAntiDots; i++)
  {
    antiDots[i] = new AntiDot(int(random(200)),int(random(200)));
  }
}
 
void loop()
{
  for (int i=0; i<howManyDots; i++)
  {
    dots[i].move();
  }
}
 
class Dot
{
  int myX, myY;
  int dir;
  Dot (int x, int y, int direction)
  {
    setBig(x, y, black,4);
    myX = x;
    myY = y;
    dir = direction;
    screen[x-1][y-1] = 1;
  }
  void move()
  {
    if(dir == 0 && myY == 1) {dir = 4;}
    if(dir == 1 && myX == 200) {dir = 7;}
    if(dir == 1 && myY == 1) {dir = 3;}
    if(dir == 2 && myX == 200) {dir = 6;}
    if(dir == 3 && myX == 200) {dir = 5;}
    if(dir == 3 && myY == 200) {dir = 1;}
    if(dir == 4 && myY == 200) {dir = 0;}
    if(dir == 5 && myX == 1) {dir = 3;}
    if(dir == 5 && myY == 200) {dir = 7;}
    if(dir == 6 && myX == 1) {dir = 2;}
    if(dir == 7 && myY == 1) {dir = 5;}
    if(dir == 7 && myX == 1) {dir = 1;}
 
    setBig(myX,myY,white,4);
    screen[myX-1][myY-1] = 0;
    if(dir == 0) {myY--;}
    if(dir == 1) {myX++; myY--;}
    if(dir == 2) {myX++;}
    if(dir == 3) {myX++; myY++;}
    if(dir == 4) {myY++;}
    if(dir == 5) {myX--; myY++;}
    if(dir == 6) {myX--;}
    if(dir == 7) {myX--; myY--;}
    setBig(myX,myY,black,4);
    screen[myX-1][myY-1] = 1;
  }
}
 
class AntiDot
{
  int myX, myY;
  AntiDot(int x,int y)
  {
    myX = x;
    myY = y;
    screen[myX-1][myY-1] = 2;
    setBig(myX,myY,grey,4);
  }
}
 
void setBig(int x, int y, int myColor, int howBig)
{
  for (int k = 0; k<(howBig); k++)
  {
    for (int l = 0; l<(howBig); l++)
    {
 set(x+k,y+l,myColor);
    }
  }
}
 
TomC

WWW
Re: very odd...
« Reply #1 on: Feb 28th, 2004, 2:32pm »

It looks like you're only drawing them when you create them.  Move clearScreen to before your makeAntiDots function in setup, and it will probably work how you expect.
 
Only drawing your fixed dots once is admirable, but it means you're spending a lot of effort remembering to undraw your dots before drawing them again.  Why not just draw everything in every frame until you're sure it's working properly?  That way you won't get the issues you have now when a dot scrubs out an antidot.
 
It looks like you'll run into problems with using random(200) to set the position in the screen array though (I notice you're already using myX-1, myY-1 to counter this) the problem will occur when random(200) gives you zero.
 
Let us know how you get on.
« Last Edit: Feb 28th, 2004, 2:32pm by TomC »  
Mythmon


Re: very odd...
« Reply #2 on: Feb 28th, 2004, 4:18pm »

ok, i think i found the problem, i just added and update function to the fixed dots that is called every time loop goes around, and the show up just fine now, maybe it has something to do with the fact that P5 is supposed to clear the screen after every frame, is this right?
 
Pages: 1 

« Previous topic | Next topic »