-
| I have this minimal example for Processing Python mode: def setup():
    size(200, 300)
    second_window = OtherWindow("2nd")  
    
def draw():
    background(0)
    ellipse(mouseX, mouseY, 10, 10)
class OtherWindow(PApplet):  
        
    def __init__(self, title=""):
        switches = ('--sketch-path=' + sketchPath(), '')
        PApplet.runSketch(switches, self)  
        self.surface.setTitle(title)
        
    def settings(self):
        self.size(300, 200)
        
    def draw(self):  # draw for the second window
        self.background(255)
        self.fill(0)
        self.rect(self.mouseX, self.mouseY, 10, 10)Will this be possible in py5 with imported mode / module mode, or just with class mode? This is my first attempt at class mode, no luck yet, I guess I'll need some help... from py5 import Sketch
class SketchySketch(Sketch):
    def __init__(self, title=""):
        if title:
            self.window_title = title
        self.title = title
        print(f"I'm {self.title}'s __init__!")
        super().__init__()
    def settings(self):
        self.size(300, 200)
        print(f"I'm {self.title}'s settings!")
    def draw(self):  # este é o draw pra a segunda janela
        if self.title == 'B':
            self.background(255)
            self.fill(0)
        else:
            self.background(0)
            self.fill(255)
        self.rect(self.mouse_x, self.mouse_y, 10, 10)
a = SketchySketch('A')
b = SketchySketch('B')
a.run_sketch()
b.run_sketch()  # I also tried this inside the __init__ mimicking the Py.Processing example Looks like the second sketch is initialized but does not run. UPDATE: The second sketch  | 
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 19 replies
-
| Some progress, I suppose...  from py5 import Sketch
class SketchySketch(Sketch):
    def __init__(self, title=""):
        self.window_title = title
        print(f"I'm {self.window_title}'s __init__!")
        super().__init__()
        self.run_sketch(block=False)            
    def settings(self):
        self.size(300, 200)
        print(f"I'm {self.window_title}'s settings!")
    def setup(self):
        if self.window_title == 'B':
            self.c = SketchySketch('C')
        print(f"I'm {self.window_title}'s setup!")
    def draw(self):  # este é o draw pra a segunda janela
        if self.window_title == 'B':
            self.background(255)
            self.fill(0)
        elif self.window_title == 'C':
            self.background(0, 0, 100)
            self.fill(0, 200, 0)
        else:
            self.background(0)
            self.fill(255)
        self.rect(self.mouse_x, self.mouse_y, 10, 10)
a = SketchySketch('A')
b = SketchySketch('B')And I could get  | 
Beta Was this translation helpful? Give feedback.
-
| Interesting that this is valid Processing Python code: class OtherWindow(PApplet):  
        
    def __init__(self, title=""):
        switches = ('--sketch-path=' + sketchPath(), '')
        PApplet.runSketch(switches, self)  
        self.surface.setTitle(title)You can call  Also, the variable  In your  Try this instead: from py5 import Sketch
class SketchySketch(Sketch):
    def __init__(self, title=""):
        super().__init__()
        self._window_title = title
        print(f"I'm {self._window_title}'s __init__!")
    def settings(self):
        self.size(300, 200)
        print(f"I'm {self._window_title}'s settings!")
    def setup(self):
        self.window_title(self._window_title)
        print(f"I'm {self._window_title}'s setup!")
    def draw(self):  # este é o draw pra a segunda janela
        if self._window_title == 'B':
            self.background(255)
            self.fill(0)
        elif self._window_title == 'C':
            self.background(0, 0, 100)
            self.fill(0, 200, 0)
        else:
            self.background(0)
            self.fill(255)
        self.rect(self.mouse_x, self.mouse_y, 10, 10)
a = SketchySketch('A')
b = SketchySketch('B')
c = SketchySketch('C')
a.run_sketch()
b.run_sketch()
c.run_sketch()This should work better. | 
Beta Was this translation helpful? Give feedback.
-
| So this is my silly example, for now... from py5 import Sketch
class SketchySketch(Sketch):
    def __init__(self, title="", other=None):
        self.other = other
        self.title = title
        self.clicked = False
        super().__init__()        
    def settings(self):
        self.size(300, 200)
    def setup(self):
        self.window_resizable(True)
        if self.title:
            self.window_title(self.title)
        if self.other:
            self.other.other = self
    def draw(self):
        if self.title == 'A':
            self.background(255)
            self.fill(0)
        else:
            self.background(0)
            self.fill(255)
        self.rect(self.mouse_x, self.mouse_y, 10, 10)
        
        if self.clicked:
            w, h = self.width, self.height
            self.fill(128, 128)
            self.circle(w / 2, h / 2, min(w, h) * 0.8)
            
    def mouse_pressed(self):
        self.clicked = not self.clicked
        if self.other:
            self.other.clicked = self.clicked
a = SketchySketch('A')
a.run_sketch(block=False)
b = SketchySketch('B', a)
b.run_sketch(block=False) | 
Beta Was this translation helpful? Give feedback.




So this is my silly example, for now...