This Python code isn't working. "takes exactly one argument, 2 given."

I'm trying to project a few tridimensional points in a 2d surface. I'm using the example from the magnificent book "algorithms for visual design using processing". I get an error when invoking the rotatey function. It says I'm sending it two arguments when I'm clearly using just one. I've used both this version of the code:

 def mouseDragged():
        xoff = radians(mouseX - pmouseX)
        yoff = mouseY - pmouseY
        pointy.rotatey(xoff)

and this one:

 def mouseDragged():
        xoff = mouseX - pmouseX
        yoff = mouseY - pmouseY
        pointy.rotatey(radians(xoff))

And I get the same error. Here is my full code:

class MyPoint(object):

    def __init__ (self, sx, sy, sz):
        self.x = sx
        self.y = sy
        self.z = sz

    def move(xoff, yoff, zoff):
        self.x + xoff
        self.y + yoff
        self.z + zoff

    def scale(xs, xy, xz):
        self.x *= xs
        self.y *= xy
        self.z *= xz

    def rotatez(angle):
        tempx = self.x * cos (angle) - self.y * sin (angle)
        tempy = self.y * cos (angle) + self.x * sin (angle)
        self.x = tempx
        self.y = tempy


    def rotatex(angle):
        tempx = self.y * cos (angle) - self.z * sin (angle)
        tempz = self.z * cos (angle) + self.y * sin (angle)
        self.y = tempy
        self.z = tempz

    def rotatey(angle):
        tempx = self.x * cos (angle) - self.z * sin (angle)
        tempz = self.z * cos (angle) + self.x * sin (angle)
        self.x = tempx
        self.z = tempz

#points = [MyPoint(3,3,3) for i in range(7)]


def setup():
    global pointy
    pointy = MyPoint(90, 90, 90)
    size(300,300)
    pointy.x = 90
    pointy.y = 90
    pointy.z = 90

def draw():
    background(255)
    strokeWeight(4)
    print(pointy.x, ", ", pointy.y)
    point(pointy.x, pointy.y)
    point(80,80)

def mouseDragged():
    xoff = radians(mouseX - pmouseX)
    yoff = mouseY - pmouseY

    pointy.rotatey(xoff)
    pointy.rotatex(radians(yoff))
Tagged:

Answers

  • According to its reference, it's rotateY(): http://py.processing.org/reference/rotateY.html

  • edited April 2015 Answer ✓

    Python class methods works a little different than usual functions. First argument for class method is a link to instance of class which method you are calling, it passed to the class method implicitly.

    Correct function declaration inside class must be:

    class MyPoint(object):
        def rotatey(self, angle):
            ....
    
  • Thank you, I'm learning Python while working on this code examples. @letsprocessing had the answer. Thanks to both of you!

Sign In or Register to comment.