user2510694
user2510694

Reputation: 15

Im having an issue with an argument when I run in IDLE

My argument is as follows:

self.draw(self.pen, side, u0, v0, x, y);

For it to run it needs to be 6 arguments, but it is considering "self.pen" as 2. Why is it doing this and how can I make it read it correctly? Thanks

# A Mandelbrot patterns class:
class MandelbrotPatterns:
    # Initialize the pen, and determine the window width and height:
    def __init__(self):
        self.pen = turtle.Pen(); 
        self.width = self.pen.window_width();
        self.height = self.pen.window_height();

    # Given numbers self, u0, v0, and side, design a pattern:
    def mandelbrot(self, u0, v0, side):
        self.pen.tracer(False);   
        for x in range(-self.width/2, +self.width/2):
            for y in range (-self.height/2, +self.height/2):
                self.draw(self.pen, side, u0, v0, x, y);
            if (x % 20 == 0):
                self.pen.tracer(True); self.pen.tracer(False);
        self.pen.tracer(True);

    # Draw in color a pattern element at point (x, y):
    def draw(self, side, u0, v0, x, y):
        maxCount = 25;
        u = u0 + x * (side / 100.0);
        v = v0 - y * (side / 100.0);
        a = 0 ; b = 0; count = 0; 
        while (count < maxCount and a * a + b * b <= 4):
            count = count + 1;
            a1 = a * a - b * b + u;
            b1 = 2 * a * b + v;
            a = a1; b = b1;
        ez = float(count) / maxCount;
        color = colorsys.hsv_to_rgb(ez, ez, ez);
        self.pen.color(color);
        self.pen.up(); self.pen.goto(x, y); self.pen.down();
        self.pen.forward(1);

Upvotes: 0

Views: 77

Answers (3)

Mark Ransom
Mark Ransom

Reputation: 308111

It's not considering self.pen as 2, it's inserting self as the first argument. That's normal for all object method functions.

Your definition of draw doesn't have a pen argument, nor does it need one as you use self.pen whenever one is needed. Just drop it off the function call.

Upvotes: 0

One Bad Panda
One Bad Panda

Reputation: 664

how is self initialized? I'm assuming something along the lines of:

class Foo(object):
def __init__(self, pen):
    self.pen = pen

def draw(self, pen, side, u0, v0, x, y):
    return pen,side,u0,v0,x,y

if so, the following:

foo1 = Foo('ink pen')
bar = foo1.draw(foo1.pen, 'left','0','1','2','3')

should return:

('ink pen', 'left', '0', '1', '2', '3')

EDIT: after your additional code was added above, it becomes clear that the issue is:

def draw(self, side, u0, v0, x, y):

it has no "pen" parameter. You should update it to be:

def draw(self, pen side, u0, v0, x, y): as I listed above initially.

Upvotes: 0

Free Monica Cellio
Free Monica Cellio

Reputation: 2290

Here's your problem:

def draw(self, side, u0, v0, x, y)

You have no pen parameter. Try this:

def draw(self, pen, side, u0, v0, x, y)

Upvotes: 1

Related Questions