Update MultipleConstructors.pyde
I have changed this example so it ressembles more the original Java example.
But I left the extra instantiations and the tuple structure for calling the objects, this can be brought down too.
MODIFY
mode/examples/Basics/Objects/MultipleConstructors/MultipleConstructors.pyde
mode/examples/Basics/Objects/MultipleConstructors/MultipleConstructors.pyde
parameters to the fields, but other times it might be appropriate to define only
one or a few.
- Advanced example written in Python Mode by: Prabhjot Singh (NITH)
- Original example in Java Mode: Example->Basic->Objects->MultipleConstructors
+In Python, as there is no method overloading, one can provide different ways of creating
+instances by setting default values for parameters in the __init__ method.
'''
+
def setup():
size(640, 360)
- smooth(4)
+ background(204)
noLoop()
- ellipseMode(CENTER)
- strokeWeight(2.5)
- stroke(0)
- fill('#FFFF00')
-
global spots
- spots = Spot(), Spot(radius=58), Spot(x=120, y=70),\
- Spot(width / 2, height / 2, 120)
-
+ spots = (Spot(),
+ Spot(x=120, y=70),
+ Spot(width / 2, height / 2, 120),
+ Spot(radius=10),
+ )
def draw():
- background(0300)
for sp in spots:
sp.display()
@@ -48,4 +45,4 @@ class Spot:
def display(self):
- ellipse(self.x, self.y, self.radius, self.diam)
+ ellipse(self.x, self.y, self.diam, self.diam)

Update MultipleConstructors.pyde

I have changed this example so it ressembles more the original Java example.
But I left the extra instantiations and the tuple structure for calling the objects, this can be brought down too.