[Tutor] converting processing code to python code

Erica Osher eosher at gmail.com
Mon Dec 1 21:48:59 CET 2008


I have a simple processing code that I'm trying to work with in python, but
I keep getting syntax errors. Any help on changing the code would be greatly
appreciated. Thanks.

void setup() {
 size(550, 500);
 noStroke();
 smooth();
 fill(255, 255, 255, 150);
}


//Square 1 vars
int x1 = 5;
int y1 = 10;

int x1Speed = 2;
int y1Speed = 2;

//Square 2 Vars
int x2 = 150;
int y2 = 100;

int x2Speed = 4;
int y2Speed = 4;

int size = 100;

void draw() {
 background(180, 0, 0);
 drawSquare1();
 drawSquare2();

 checkCollision();
}



void drawSquare1() {
 if(x1<0 || x1>width-size) {
  x1Speed = -x1Speed;
 }

 if(y1<0 || y1>height-size) {
  y1Speed = -y1Speed;
 }

 x1+= x1Speed;
 y1+= y1Speed;
 rect(x1, y1, size, size);
}

void drawSquare2() {
 if(x2<0 || x2>width-size) {
  x2Speed = -x2Speed;
 }

 if(y2<0 || y2>height-size) {
  y2Speed = -y2Speed;
 }

 x2+= x2Speed;
 y2+= y2Speed;
 rect(x2, y2, size, size);
}

void checkCollision() {
 if(abs(x1-x2) < size && abs(y1-y2) < size) {
  println("Collision");
  //fill(255, 255, 255, 200);
  x1Speed=-x1Speed;
  x2Speed=-x2Speed;

  y1Speed=-y1Speed;
  y2Speed=-y2Speed;
 } else {
  fill(255, 255, 255, 100);
 };
}


-- 
Erica Osher
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081201/b2fa8830/attachment-0001.htm>


More information about the Tutor mailing list