1

I tried to make a simple program in Processing Python, it's an ellipse that moves from the center of the screen towards right. The X value of its center increments and that's how it moves. It did not work the way I thought it would, I see only the black background and that's it.

I tried the same code in Processing Java and it works. The codes are identical, at least they seem so to me. Do I miss something here? Thanks in advance!

Code in Python:

i = 250

def setup():
    size(500, 500)
    background(0)
    noStroke()

def draw():
    fill(255)
    ellipse(i, 250, 20, 20)
    i = i + 10

Code in Java:

int x = 250;

void setup() {
  size(500, 500);
  background(0);
  noStroke();
}
    
void draw() {
    fill(255);
    ellipse(x, 250, 20, 20);
    x = x + 10;
}

EDIT: The problem is solved, thanks to the stackoverflow community! The thing is, in the Python part I needed to specify explicitly that the i variable is the global one. So yes, adding global i solved it perfectly!

Serge
  • 31
  • 2

1 Answers1

0

They are not identical. The identical Python code would also use instance members:

class Test:
    def __init__(self):
        self.x = 250
    
    def setup(self):
        size(500, 500)
        background(0)
        noStroke()
    
    def draw(self):
        fill(255)
        ellipse(self.x, 250, 20, 20)
        self.x = self.x + 10
Dave Doknjas
  • 6,394
  • 1
  • 15
  • 28