Geometry of flowers


#1

It says error on line 21 move xy requires to numbers as arguments x is nan which is type ‘number’, not ‘number’

# You now have the Ring of Flowers! You can do:
# toggleFlowers(True/False) - turns flowers on or off.
# setFlowerColor("random") - can also be "pink", "red", "blue", "purple", "yellow", or "white".

# Here are some functions for drawing shapes:
# x, y - center of the shape
# size - size of the shape (radius, side length)
def drawCircle(x, y, size):
    angle = 0
    self.toggleFlowers(False)
    while angle <= Math.PI * 2:
        newX = x + (size * Math.cos(angle))
        newY = y + (size * Math.sin(angle))
        self.moveXY(newX, newY)
        self.toggleFlowers(True)
        angle += 0.2

def drawSquare(x, y, size):
    self.toggleFlowers(False)
    cornerOffset = size / 2
    self.moveXY(x - cornerOffset, y - cornerOffset)
    self.toggleFlowers(True)
    self.moveXY(x + cornerOffset, y - cornerOffset)
    self.moveXY(x + cornerOffset, y + cornerOffset)
    self.moveXY(x - cornerOffset, y + cornerOffset)
    self.moveXY(x - cornerOffset, y - cornerOffset)


redX = {"x": 28, "y": 36}
whiteX = {"x": 44, "y": 36}

# Pick a color.
self.setFlowerColor("red")
# Draw a size 10 circle at the redX.
drawCircle(28, 36, 10)
# Change the color!
self.setFlowerColor("white")
# Draw a size 10 square at the whiteX.
drawSquare({"x": 44, "y": 36}, 10)


# Now experiment with drawing whatever you want!
self.setFlowerColor("blue")
drawCircle(61, 42, 3)

#2

Nvm i beat it i just had to fix the drawSquare part

# You now have the Ring of Flowers! You can do:
# toggleFlowers(True/False) - turns flowers on or off.
# setFlowerColor("random") - can also be "pink", "red", "blue", "purple", "yellow", or "white".

# Here are some functions for drawing shapes:
# x, y - center of the shape
# size - size of the shape (radius, side length)
def drawCircle(x, y, size):
    angle = 0
    self.toggleFlowers(False)
    while angle <= Math.PI * 2:
        newX = x + (size * Math.cos(angle))
        newY = y + (size * Math.sin(angle))
        self.moveXY(newX, newY)
        self.toggleFlowers(True)
        angle += 0.2

def drawSquare(x, y, size):
    self.toggleFlowers(False)
    cornerOffset = size / 2
    self.moveXY(x - cornerOffset, y - cornerOffset)
    self.toggleFlowers(True)
    self.moveXY(x + cornerOffset, y - cornerOffset)
    self.moveXY(x + cornerOffset, y + cornerOffset)
    self.moveXY(x - cornerOffset, y + cornerOffset)
    self.moveXY(x - cornerOffset, y - cornerOffset)


redX = {"x": 28, "y": 36}
whiteX = {"x": 44, "y": 36}

# Pick a color.
self.setFlowerColor("red")
# Draw a size 10 circle at the redX.
drawCircle(28, 36, 10)
# Change the color!
self.setFlowerColor("white")
# Draw a size 10 square at the whiteX.
drawSquare(44, 36, 10)


# Now experiment with drawing whatever you want!
self.setFlowerColor("blue")
drawCircle(61, 42, 3)

#3

Nan means"Not a Number". It is a special value which that x cannot be used as a number.
In your case drawSquare expected 3 values (x,y,size) and you gave him a structure and a value
( (x,y), value).

If you have a structure such a pos, you can get the value in the structure with pos.x an pos.y:

whiteX = {"x": 44, "y": 36}
#drawSquare(44, 36, 10)
drawSquare(whiteX.x, whiteX.y, 10)