I've been writing a custom snake game using python, pygame, and pyopengl. I'm trying to draw a shape on the screen. However, I've stumbled upon this error:
Traceback (most recent call last):
File "F:\Projects\python\Python_Game\venv\lib\site-packages\OpenGL\latebind.py", line 43, in __call__
return self._finalCall( *args, **named )
TypeError: 'NoneType' object is not callable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "F:\Projects\python\Python_Game\src\game.py", line 35, in <module>
main()
File "F:\Projects\python\Python_Game\src\game.py", line 31, in main
game.draw_shapes()
File "F:\Projects\python\Python_Game\src\game_classes.py", line 203, in draw_shapes
f.draw()
File "F:\Projects\python\Python_Game\src\game_classes.py", line 128, in draw
shape.draw()
File "F:\Projects\python\Python_Game\src\opengl_classes.py", line 128, in draw
glVertex2fv(cosine, sine)
File "F:\Projects\python\Python_Game\venv\lib\site-packages\OpenGL\latebind.py", line 47, in __call__
return self._finalCall( *args, **named )
File "F:\Projects\python\Python_Game\venv\lib\site-packages\OpenGL\wrapper.py", line 689, in wrapperCall
pyArgs = tuple( calculate_pyArgs( args ))
File "F:\Projects\python\Python_Game\venv\lib\site-packages\OpenGL\wrapper.py", line 450, in calculate_pyArgs
yield converter(args[index], self, args)
File "F:\Projects\python\Python_Game\venv\lib\site-packages\OpenGL\arrays\arrayhelpers.py", line 115, in asArraySize
byteSize = handler.arrayByteCount( result )
AttributeError: ("'NumberHandler' object has no attribute 'arrayByteCount'", <function asArrayTypeSize.<locals>.asArraySize at 0x000002642A35DCA0>)
The console is throwing me a TypeError and an Attribute error. I'm not sure if this is due to my code or an issue with one of the libraries. I'm using Python 3.9.1, pygame 2.0.1, and PyOpenGL 3.1.5.
Here's the snippet of my script where the issue arises:
class Circle:
def __init__(self, pivot: Point, radius: int, sides: int, fill: bool, color: Color):
self.pivot = pivot
self.radius = radius
self.sides = sides
self.fill = fill
self.color = color
# Draw the shape of the circle
def draw(self):
glColor3f(self.color.r, self.color.g, self.color.b)
if self.fill:
glBegin(GL_POLYGON)
else:
glBegin(GL_LINE_LOOP)
for i in range(100):
cosine = self.radius * cos(i*2*pi/self.sides) + self.pivot.x
sine = self.radius * sin(i*2*pi/self.sides) + self.pivot.y
glVertex2fv(cosine, sine)
glEnd()
The argument of glVertex2fv must be an array with 2 elements. If you have two separate coordinates which are not aggregated in an array you must use glVertex2f. See glVertex:
glVertex2fv(cosine, sine)
glVertex2f(cosine, sine)
Related
The goal is to overlay pfp on top of template, and then place the string description underneath pfp. When I run the code, I get the error TypeError: argument must be sequence.
def edit(template, pfp, description):
x = (template.size[0] - image.size[0])/2
y = (template.size[1] - image.size[1])/2
Image.Image.paste(template, pfp, (round(x), round(y)))
draw = ImageDraw.Draw(template)
draw.text(round((template.size[0]/8), round(y-15)), description)
template.show()
return template
Full error message:
Traceback (most recent call last):
File "/Users/shalim/PycharmProjects/EDPtigerstars/main.py", line 30, in <module>
edit(background, image, x[1]).save(x[0])
File "/Users/shalim/PycharmProjects/EDPtigerstars/main.py", line 18, in edit
draw.text(round((template.size[0]/8), round(y-15)), description)
File "/Users/shalim/PycharmProjects/EDPtigerstars/venv/lib/python3.8/site-packages/PIL/ImageDraw.py", line 512, in text
draw_text(ink)
File "/Users/shalim/PycharmProjects/EDPtigerstars/venv/lib/python3.8/site-packages/PIL/ImageDraw.py", line 496, in draw_text
self.draw.draw_bitmap(coord, mask, ink)
TypeError: argument must be sequence
Process finished with exit code 1
Try putting your x, y coordinates inside a tuple:
draw.text((x,y)), "Text")
I am reading a set of coordinates from a file to produce a shape in the Python Turtle. After reading reading in the coordinates, I have written a for loop that goes through the list of coords and draws them. However, upon running with a correct file name, I get this error:
Traceback (most recent call last):
File "C:\Users\06113\Desktop\My Stuff\Python Saves\Vec Draw\Vec Draw.py", line 55, in <module>
t.goto(cs)
File "C:\Users\06113\AppData\Local\Programs\Python\Python38-32\lib\turtle.py", line 1774, in goto
self._goto(Vec2D(*x))
File "C:\Users\06113\AppData\Local\Programs\Python\Python38-32\lib\turtle.py", line 3195, in _goto
self._update() #count=True)
File "C:\Users\06113\AppData\Local\Programs\Python\Python38-32\lib\turtle.py", line 2660, in _update
self._update_data()
File "C:\Users\06113\AppData\Local\Programs\Python\Python38-32\lib\turtle.py", line 2650, in _update_data
self.screen._drawline(self.currentLineItem, self.currentLine,
File "C:\Users\06113\AppData\Local\Programs\Python\Python38-32\lib\turtle.py", line 543, in _drawline
cl.append(x * self.xscale)
TypeError: can't multiply sequence by non-int of type 'float'
Is there any way at all that I could fix this in MY file? I would rather not go into the turtle module where I could easily mess something up.
The code for this section in my file is:
t = turtle.Turtle(visible=False)
t.speed(0)
for i in range(0, len(coord_list), 2):
if i == 0 and i+1 == 1:
fcs = (coord_list[i], coord_list[i+1])
t.pu()
t.goto(fcs)
t.pd()
pass
else:
cs = (coord_list[i], coord_list[i+1])
t.goto(cs)
cs = None
pass
pass
t.goto(fcs)
print("Vector image drawn.")
Hi I am learning Google vision API and I implemented the text detection from file where I have to draw bounding boxes to visualize the words, paragraphs and blocks. But during execution I am getting an error in Pillow library. Can someone help me out? I have mentioned the error below and part of the code down here:
CODE:
def draw_boxes(image, bounds, color, width=5):
draw = ImageDraw.Draw(image)
for bound in bounds:
draw.line([
bound.vertices[0].x, bound.vertices[0].y,
bound.vertices[1].x, bound.vertices[1].y,
bound.vertices[2].x, bound.vertices[2].y,
bound.vertices[3].x, bound.vertices[3].y,
bound.vertices[0].x, bound.vertices[0].y], fill=color, width=width)
return image```
#CODE ENDS
#Error
```Traceback (most recent call last):
File "/home/sridhar/PycharmProjects/documentOCR/venv/lib/python3.6/site-packages/PIL/ImagePalette.py", line 99, in getcolor
return self.colors[color]
KeyError: (255, 255, 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "myOCR.py", line 60, in <module>
draw_boxes(image, bounds, 'yellow')
File "myOCR.py", line 37, in draw_boxes
bound.vertices[0].x, bound.vertices[0].y], fill=color, width=width)
File "/home/sridhar/PycharmProjects/documentOCR/venv/lib/python3.6/site-packages/PIL/ImageDraw.py", line 155, in line
ink = self._getink(fill)[0]
File "/home/sridhar/PycharmProjects/documentOCR/venv/lib/python3.6/site-packages/PIL/ImageDraw.py", line 112, in _getink
ink = self.palette.getcolor(ink)
File "/home/sridhar/PycharmProjects/documentOCR/venv/lib/python3.6/site-packages/PIL/ImagePalette.py", line 109, in getcolor
self.palette[index + 256] = color[1]
IndexError: bytearray index out of range```
EDIT:
This error happens only to specific images, when I tried with a new image it works perfectly fine.
I'm writing a function to convert and display an image to negative, when i call the function i get this error message:
Traceback (most recent call last):
File "C:/Users/User/PycharmProjects/Librophyton/Procdeimagenes/test.py",line 32, in <module>
makeNegative(dude)
File "C:\Python34\lib\ImageProcess.py", line 16, in makeNegative
old = FileImage(imageFile)
File "C:\Python34\lib\cImage.py", line 398, in __init__
super(FileImage, self).__init__(fname = thefile)
File "C:\Python34\lib\cImage.py", line 241, in __init__
self.loadImage(fname)
File "C:\Python34\lib\cImage.py", line 270, in loadTkImage
sufstart = fname.rfind('.')
AttributeError: 'FileImage' object has no attribute 'rfind'
Here is the function:
def makeNegative(imageFile):
window = ImageWin("Proceso de imagen", 1000-100, 900)
old = FileImage(imageFile)
old.draw(window)
window.exitOnClick()
w = old.getWidth()
h = old.getHeight()
new = EmptyImage(w,h)
for row in range(h):
for col in range(w):
pixelviejo = old.getPixel(col,row)
pixelnuevo = pixelNeg(pixelviejo)
new.setPixel(col, row, pixelnuevo)
new.setPosition(w+1, 0)
new.draw(window)
window.exitOnClick()
And here is the funciton call:
dude = FileImage("factores_de_conversion.gif" )
makeNegative(dude)
Any idea how to solve this? or how should i modify the module?
My program gives me this error:
Traceback (most recent call last):
File "C:\Simulation\SymDialog.py", line 153, in OnPaint
self.Redraw(False)
File "C:\Simulation\SymDialog.py", line 173, in Redraw
obj.Draw(self.dc)
File "C:\Simulation\SymDialog.py", line 207, in Draw
dc.DrawCircle(self._x, self._y, self._r)
File "E:\Python\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_gdi.py", line 3391, in DrawCircle
return _gdi_.DC_DrawCircle(*args, **kwargs)
OverflowError: Python int too large to convert to C long
Method from error:
OnPaint
def OnPaint(self, event):
self.Redraw(False)
wx.GCDC(wx.BufferedPaintDC(self, self._buffer))
event.Skip()
Redraw
def Redraw(self, clear):
if clear == True: del self.drawList[:]
self.dc = wx.GCDC(wx.BufferedDC(None, self._buffer))
self.dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
self.dc.Clear()
for obj in self.drawList:
obj.Draw(self.dc)
del self.dc
Draw
def Draw(self, dc):
self.setDC(dc)
dc.DrawCircle(self._x, self._y, self._r)
How can I fix this error ?
Thanks for answers
You might be mistakenly using too large values.
Edit: Since I can't comment, what are the sizes of self._x, self._y, and self._r?