jdf / processing-py-site

Site for processing.py.
MIT License
197 stars 52 forks source link

super() is not working in Python #194

Closed gouravkadiankad closed 3 years ago

gouravkadiankad commented 3 years ago

The super function showing an unexpected error

def setup():
    size(900, 600)
    background(0)
    lens = Convex_Lens(50)
    lens.draw_lens((450, 300))

def draw():
    pass

class Lens:
    def __init__(self, radiusofC):
        self.radius = radiusofC
        self.aperture = radiusofC*(6/5)

class Convex_Lens(Lens):
    def __init__(self, radiusofC):
        super(Convex_Lens, self).__init__(radiusofC)   
    def draw_lens(self, pole):
        arc(pole[0]-self.radiusofC, pole[1]-self.radiusofC, 2*self.radiusofC, 2*self.radiusofC,PI/4,-PI/4)

Error TypeError: super: argument 1 must be type

Screenshot 2021-04-28 210444

tabreturn commented 3 years ago

Processing uses the Jython interpreter (Python 2.7 syntax). Add (object) to the Lens line for new style classes, and a . following the 6 for floating-point division:

class Lens(object):
    def __init__(self, radiusofC):
        self.radius = radiusofC
        self.aperture = radiusofC*(6./5)