I came across this article. I wonder if it is possible to make a stellar chart with Python? (see picture).
I have had a look at the matplotlib and seaborn galleries, but apparently they do not have any built in function to create such a chart (neither radar charts).
Is there any way to draw a chart like this easily using Python?
Following is a rendition of a StellarChart, as per your specifications.
It is derived from a SpiderChart (a RadarChart) build with tkinter to answer an earlier question
You can see them both side by side hereunder:
It takes a list of tuples('label', score), with the score expressed as a percentage (value in the interval [0, 100]).
The number of data points adjusts to the data provided.
The scale of the chart can be adjusted.
import math
import tkinter as tk
class SpiderChart(tk.Canvas):
"""a canvas that displays datapoints as a SpiderChart
"""
width=500
height=500
def __init__(self, master, datapoints, concentrics=10, scale=200):
super().__init__(master, width=self.width, height=self.height)
self.scale = scale
self.center = self.width // 2, self.height // 2
self.labels = tuple(d[0] for d in datapoints)
self.values = tuple(d[1] for d in datapoints)
self.num_pts = len(self.labels)
self.concentrics = [n/(concentrics) for n in range(1, concentrics + 1)]
self.draw()
def position(self, x, y):
"""use +Y pointing up, and origin at center
"""
cx, cy = self.center
return x + cx, cy - y
def draw_circle_from_radius_center(self, radius):
rad = radius * self.scale
x0, y0 = self.position(-rad, rad)
x1, y1 = self.position(rad, -rad)
return self.create_oval(x0, y0, x1, y1, dash=(1, 3))
def draw_label(self, idx, label):
angle = idx * (2 * math.pi) / self.num_pts
d = self.concentrics[-1] * self.scale
x, y = d * math.cos(angle), d * math.sin(angle)
self.create_line(*self.center, *self.position(x, y), dash=(1, 3))
d *= 1.1
x, y = d * math.cos(angle), d * math.sin(angle)
self.create_text(*self.position(x, y), text=label)
def draw_polygon(self):
points = []
for idx, val in enumerate(self.values):
d = (val / 100) * self.scale
angle = idx * (2 * math.pi) / self.num_pts
x, y = d * math.cos(angle), d * math.sin(angle)
points.append(self.position(x, y))
self.create_polygon(points, fill='cyan')
def draw(self):
self.draw_polygon()
for concentric in self.concentrics:
self.draw_circle_from_radius_center(concentric)
for idx, label in enumerate(self.labels):
self.draw_label(idx, label)
class StellarChart(SpiderChart):
"""a canvas that displays datapoints as a StellarChart
"""
def draw_polygon(self):
points = []
da = math.pi / self.num_pts
b = .05 * self.scale
for idx, val in enumerate(self.values):
d = (val / 100) * self.scale
angle = idx * (2 * math.pi) / self.num_pts
x, y = d * math.cos(angle), d * math.sin(angle)
points.append(self.position(x, y))
xb, yb = b * math.cos(angle + da), b * math.sin(angle+da)
points.append(self.position(xb, yb))
self.create_polygon(points, width=3, outline='red', fill='pink', join=tk.ROUND)
data = [('stamina', 70), ('python-skill', 100), ('strength', 80), ('break-dance', 66), ('speed', 45), ('health', 72), ('healing', 90), ('energy', 12), ('libido', 100)]
root = tk.Tk()
stellar = StellarChart(root, data)
stellar.pack(side=tk.LEFT)
spider = SpiderChart(root, data)
spider.pack(side=tk.LEFT)
root.mainloop()
The Plotly library includes a starchart: https://plotly.com/python/radar-chart/
Related
i am trying to make planets using pyglet but they end up looking like stars result
here is my code
also i need a way to convert a batch to a sprite (to move it easily)
import pyglet
from pyglet import shapes
import opensimplex
import math
import time
brtd = 0
######## planets###########
class planetobj():
def __init__(self,seed=1234,age=68,position=(0,0),color=(0,1,0),name="planet",description=" 127.0.0.1 , home sweet home never will thy become infected with the virus that has a closedcure"):
self.seed = seed
self.age = age
self.position = position
self.color = color
self.name = name
self.description = description
def gplanet(self,size):
opensimplex.seed(self.seed)
done = 0
xc = 0
c = 0
self.terrain = []
start = opensimplex.noise2(x=0, y=self.age)
while (done == 0 or xc < 50) and not xc > 100 :
xc = xc + 1
c = c + size
value = opensimplex.noise2(x=xc, y=self.age)
self.terrain.append(value * size)
if xc > 50:
if math.floor(value * 100 ) == math.floor(start * 100):
self.done = 1
def mkplanet(self, x,y):
self.batch = pyglet.graphics.Batch()
corner1 = (x,y)
self.trias = []
counter = 0
cornerback = [0,0]
for i in self.terrain:
counter += 1
radi = (360 / len(self.terrain)) * counter
radi2 = (360 / len(self.terrain)) * ((counter + 1 ) % len(self.terrain))
theta = self.terrain[(counter +1 ) % len(self.terrain)]
corner3 = (x + math.sin(radi) * ( i ) ,math.cos(radi) * ( i ) + y )
corner2 = (x + math.sin(radi2) * ( theta ) ,math.cos(radi2) * ( theta ) + y )
self.trias.append(shapes.Triangle( x,y,corner2[0], corner2[1], corner3[0], corner3[1], color=(255, counter % 255, 255), batch=self.batch) )
############ basic game logic & rendering ###########
scr_X = 400
scr_Y = 300
window = pyglet.window.Window(scr_X,scr_Y)
samplebatch = pyglet.graphics.Batch()
earth = planetobj()
earth.gplanet(200)
planets = []
planets.append(earth)
earth.mkplanet( 50 ,50)
#window.event
def on_draw():
window.clear()
earth.batch.draw()
pyglet.app.run()
i tried changing the values that get divided by 'len(self.terrain)'
but i could not find out how to make the planets look round
EDIT
thank you kind commenter (and also the rest of stackoverflow)
now i made a working version feel free to use it
'''
import opensimplex
import math
import pyglet
from pyglet import shapes
pi = 3.1459
debug = 0
class planetobj():
def __init__(self,seed=1234,age=68,position=(0,0),color=(0,1,0),name="planet",description=" 127.0.0.1 , home sweet home never will thy become infected with the virus that has a closedcure"):
self.seed = seed
self.age = age
self.position = position
self.color = color
self.name = name
self.description = description
def gplanet(self,size):
self.batch = pyglet.graphics.Batch()
opensimplex.seed(self.seed)
done = 0
xc = 0
c = 0
self.terrain = []
start = opensimplex.noise2(x=0, y=self.age)
while (done == 0 or xc < 50) and not xc > 100 :
xc = xc + 1
c = c + size
value = opensimplex.noise2(x=xc, y=self.age)
self.terrain.append(value * 10 + size)
if xc > 36:
if math.floor(value * 100 ) == math.floor(start * 100):
self.done = 1
def mkplanet(self, x,y):
global debug
corner1 = (x,y)
self.trias = []
deltatheta = 360 / len(self.terrain)
for counter,i in enumerate(self.terrain):
theta1 = ((deltatheta * counter)/180) * 3.1459
theta2 = (deltatheta * (counter + 2)/180) * 3.1459
radius = self.terrain[counter]
print(str(theta1) + "," + str(theta2))
radius2 = self.terrain[(counter + 1 )% len(self.terrain)]
corner2 = (x + radius2 * math.cos(theta1), y + radius * math.sin(theta1))
corner3 = ( (x + radius2 * math.cos(theta2)), (y + radius2 * math.sin(theta2)))
self.trias.append(shapes.Triangle(x,y,corner2[0], corner2[1], corner3[0], corner3[1], color=(255, counter % 255, 255), batch=self.batch) )
if debug == 1:
self.trias.append(shapes.Circle( corner2[0], corner2[1], 2, color=(255, counter % 255, 40), batch=self.batch) )
self.trias.append(shapes.Circle( corner3[0], corner3[1], 2, color=(255,255, 255), batch=self.batch) )
############ basic game logic & rendering ###########
scr_X = 400
scr_Y = 300
window = pyglet.window.Window(scr_X,scr_Y)
samplebatch = pyglet.graphics.Batch()
earth = planetobj()
earth.gplanet(150)
earth.mkplanet( 250,150)
print(earth.batch)
earth.batch.draw
#window.event
def on_draw():
window.clear()
earth.batch.draw()
print("drawing")
pyglet.app.run()
'''
OK, I've corrected your trigonometry, but there are some other issues. The random values you get back from the noise generator are between -1 and 1. You are then multiplying that by the planet size, which gives you wild variations from wedge to wedge. What you want is to have a basic wedge size, which you use the noise to adjust bit by bit. Here, I'm saying that the noise should be 3% of the wedge size (size/30).
I didn't want to download opensimplex, so I've used a uniform random number generator. I'm also using matplotlib to plot the triangle, but see if this is closer to what you intended.
import math
import random
import numpy as np
import matplotlib.pyplot as plt
class planetobj():
def __init__(self,seed=1234,age=68,position=(0,0),color=(0,1,0),name="planet",description=""):
self.seed = seed
self.age = age
self.position = position
self.color = color
self.name = name
self.description = description
def gplanet(self,size):
done = 0
xc = 0
self.terrain = []
start = random.uniform(-1,1)
while (done == 0 or xc < 50) and not xc > 100 :
xc = xc + 1
value = random.uniform(-1,1)
self.terrain.append(size + value * size / 30)
if xc > 50 and math.floor(value * 100) == math.floor(start * 100):
done = 1
def mkplanet(self, x,y):
corner1 = (x,y)
self.trias = []
deltatheta = 360 / len(self.terrain)
for counter,i in enumerate(self.terrain):
theta1 = deltatheta * counter
theta2 = deltatheta * (counter + 1)
radius = self.terrain[counter]
corner2 = (x + radius * math.cos(theta1), y + radius * math.sin(theta1))
corner3 = (x + radius * math.cos(theta2), y + radius * math.sin(theta2))
# self.trias.append(shapes.Triangle( x, y, corner2[0], corner2[1], corner3[0], corner3[1], color=(255, counter % 255, 255), batch=self.batch) )
self.trias.append(( x, y, corner2[0], corner2[1], corner3[0], corner3[1], (1.0,(counter%255)/255,1.0) ))
earth = planetobj()
earth.gplanet(200)
earth.mkplanet(50 ,50)
print(earth.trias)
plt.figure()
plt.scatter( [48,48,52,52],[-50,50,-50,50] )
for t in earth.trias:
tri = np.array(t[:6]).reshape(3,2)
plt.gca().add_patch(plt.Polygon( tri, color=t[6] ))
plt.show()
Output:
I am having trouble trying to finish a python turtle program. When I attempt to input x and y coordinates as well as a radius value for the function like
t.drawSnowman(x = 25,y = 25,radius = 25) the program misbehaves when I input values.but if I leave out the parameters above and instead just use t.drawSnowman() the program works as intended but I am not able to create various instances of the snowman.
I would really like help trying to figure out how to input the parameters and still have the program function.
here's my code
import turtle
class MyTurtle(turtle.Turtle):
""""""
def __init__(self):
"""Turtle Constructor"""
turtle.Turtle.__init__(self, shape="turtle")
def drawNose(self, x=0, y=0, radius = 15, circle_color = "black"):
'''draw nose '''
self.pendown()
self.goto(-(radius) * (0.25),(radius * 6)+(radius * 4)+(radius))
self.goto(0,(radius * 6)+(radius * 4)+(radius)+(radius * (0.25)))
self.goto((radius) * (0.25),(radius * 6)+(radius * 4)+(radius))
self.goto(0,(radius * 6)+(radius * 4)+(radius))
self.penup()
def leftEye(self, x=0, y=0, radius = 15, circle_color = "black"):
'''draw left eye'''
self.pendown()
self.circle(radius*(.25))
self.penup()
def rightEye(self, x=0, y=0, radius = 15, circle_color = "black"):
'''draw right eye'''
self.pendown()
self.circle(radius*(.25))
self.penup()
def bottomOfHat(self, x=0, y=0, radius = 15, circle_color = "black"):
''' draw the long part of the hat at the bottom '''
self.goto(0,(radius * 6)+(radius * 4)+(radius * 2))
self.pendown()
self.goto(-(radius),(radius * 6)+(radius * 4)+(radius * 2))
self.goto(-(radius),(radius * 6)+(radius * 4)+(radius * 2)+(radius * (0.5)))
self.goto(radius,(radius * 6)+(radius * 4)+(radius * 2)+(radius * (0.5)))
self.goto(radius,(radius * 6)+(radius * 4)+(radius * 2))
self.goto(0,(radius * 6)+(radius * 4)+(radius * 2))
self.penup()
def topOfHat(self, x=0, y=0, radius = 15, circle_color = "black"):
'''draw the top bigger part of the hat'''
self.goto(radius*(.75),(radius * 6)+(radius * 4)+(radius * 2)+(radius * (0.5)))
self.pendown()
self.goto(radius*(.75),(radius * 6)+(radius * 4)+(radius * 2)+(radius * 2))
self.goto(-(radius)*(.75),(radius * 6)+(radius * 4)+(radius * 2)+(radius * 2))
self.goto(-(radius)*(.75),(radius * 6)+(radius * 4)+(radius * 2)+(radius * (0.5)))
def bottomCircle(self, x=0, y=0, radius = 15, circle_color = "black"):
'''draws the bottom circle'''
self.pendown()
self.circle(radius * 3)
self.penup()
def middleCircle(self, x=0, y=0, radius = 15, circle_color = "black"):
'''draw the middle circle'''
self.pendown()
self.circle(radius * 2)
self.penup()
def topCircle(self, x=0, y=0, radius = 15, circle_color = "black"):
'''draw the top circle'''
self.pendown()
self.circle(radius)
self.penup()
def drawSnowman(self, x=0, y=0, radius = 15, circle_color = "black"):
self.bottomCircle()
self.goto(0,radius * 6)
self.middleCircle()
self.goto(0,(radius * 6)+(radius * 4))
self.topCircle()
self.goto(-(radius) * (0.5),(radius * 6)+(radius * 4)+(radius))
self.leftEye()
self.goto((radius) * (0.5),(radius * 6)+(radius * 4)+(radius))
self.rightEye()
self.goto(0,(radius * 6)+(radius * 4)+(radius))
self.drawNose()
self.bottomOfHat()
self.topOfHat()
t = MyTurtle()
t.hideturtle()
radius = 15
t.drawSnowman(x = 25,y = 25,radius = 25)
this is a picture of the snowman when I use the parameters
t.drawsnowman(x = 25 y=25 radius = 25)
this is the snowman when I inuput no parameters t.drawsnowman()
Try going step-by-step and work out what your code actually does (or use a debugger).
If you call t.drawSnowman(), radius will 15.
You call bottomCircle() which will draw a circle with a radius of radius * 3 = 45
You move radius * 6 = 90 on the y axis (you're now "on top" of the circle)
You call middleCircle() which will a circle with a radius of radius * 2 = 30
...
Now, see what happens if you call your function with parameters:
If you call t.drawSnowman(x = 25,y = 25,radius = 25), radius will 25.
You call bottomCircle() which will draw a circle with a radius of radius * 3 = 45. Note how the local variable radius is 15, since it's the default value of that parameter, and you don't pass the value you passed to drawSnowman down to the bottomCircle method.
You move radius * 6 = 150 on the y axis (you're now far off of the circle)
You call middleCircle() which will a circle with a radius of radius * 2 = 30. Note how the local variable radius is 15, too.
...
So, you problem is that you pass in a value for radius, but you use that value only for moving the turtle in drawSnowman, not further down in any of the other functions.
I have the following code which draws ellipse on the circumference of a circle and then draws chords between ellipses. The chords are drawn fine but the event bombs on me and goes into a infinite loop.
def binomial(i, n):
return math.factorial(n) / float(
math.factorial(i) * math.factorial(n - i))
def bernstein(t, i, n):
return binomial(i, n) * (t ** i) * ((1 - t) ** (n - i))
def bezier(t, points):
n = len(points) - 1
x = y = 0
for i, pos in enumerate(points):
bern = bernstein(t, i, n)
x += pos[0] * bern
y += pos[1] * bern
return x, y
def bezier_curve_range(n, points):
for i in xrange(n):
t = i / float(n - 1)
yield bezier(t, points)
def getControlPt(x1, y1, x2, y2, t):
new_px = (1 - t) * x1 + t * x2
new_py = (1 - t) * y1 + t * y2
return new_px, new_py
class Temp1(QWidget):
def __init__(self, c, parent=None):
super(Temp1, self).__init__(parent)
self.text = "Hi"
self.cords = c
def paintEvent(self, e):
qp = QPainter(self)
qp.setPen(Qt.red)
bluePen = QPen(Qt.blue, 1, Qt.DashLine)
steps = 10000
for i in range(15):
for j in range(15):
if i == j:
continue
px, py = getControlPt(self.cords[i][0], self.cords[i][1], self.cords[j][0], self.cords[j][1], 0.55)
px1, py1 = getControlPt(px, py, self.cords[j][0], self.cords[j][1], 0.25)
px2, py2 = getControlPt(px1, py1, self.cords[j][0], self.cords[j][1], 0.75)
cp = (self.cords[i], (px, py) , (px1, py1), (px2, py2), self.cords[j])
oldPoint = cp[0]
qp.setPen(bluePen)
for point in bezier_curve_range(steps, cp):
qp.drawLine(oldPoint[0], oldPoint[1], point[0], point[1])
oldPoint = point
class Temp(QPushButton):
def __init__(self, x, y, w, h, theta, cords, parent=None):
super(Temp, self).__init__(parent)
self.w = w
self.h = h
self.x = x
self.y = y
self.text = "test"
self.angle = theta
self.cords = cords
def paintEvent(self, e):
qp = QPainter(self)
qp.setPen(Qt.red)
qp.drawEllipse(0, 0, self.w - 2, self.h -2)
class Example(QWidget):
def __init__(self):
super(Example, self).__init__()
self.cords = []
self.initUI()
def initUI(self):
self.setWindowTitle('Points')
self.drawP()
def drawP(self):
theta = 2 * np.pi / 15
for i in range(15):
angle = theta * (i + 1)
dx = int(round(400 + 300 * np.cos(angle)))
dy = int(round(400 + 300 * np.sin(angle)))
self.cords.append((dx, dy))
for i in range(15):
t = Temp(self.cords[i][0], self.cords[i][1], 45, 20, np.degrees(angle), self.cords, parent=self)
t.setGeometry(self.cords[i][0], self.cords[i][1] , 45, 20)
t1 = Temp1(self.cords, parent = self)
t1.setGeometry(0, 0, 800, 600)
app = QApplication(sys.argv)
ex = Example()
ex.setGeometry(0, 0, 800, 600)
ex.show()
sys.exit(app.exec_())
The problem is with the paintevent function of class Temp1.
If you throw a print 'Temp1.paintEvent', e, i, j inside the nested for loops inside of Temp1.paintEvent, you'll see that it's not hanging, it's just slow, and every time you hide the window, then bring it back up, it has to go through the whole paintEvent again before actually showing it. If you're patient the window will eventually pop up.
I can not seem draw lines between the old pixel and the new pixel making a smooth Bezier curve. I have the Bezier curve, but it is only made up of pixels alone. Also, when I click on the canvas to update the Bezier curve I can't get the old one to delete. I have tried canvas.delete(line) and also canvas.delete(tk.ALL), but this gets rid of everything and i need to be able to keep my click_points or the where the ovals where drawn. Any help would be greatly appreciated.
import tkinter as tk
#Screen creation.
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 800
SIZE = 4
**# Creates the canvas.**
root_window = tk.Tk()
canvas = tk.Canvas(root_window, width = SCREEN_WIDTH, height = SCREEN_HEIGHT)
canvas.pack()
**#Plots each pixel**
def plot_pixel(x0, y0):
line = canvas.create_line(x0, y0, x0 + 1, y0)
**#Pre: Takes a list of points.
#Post: Recursively iterates through the list to find the
# linear interpolation (x, y)**
def draw_curve(points, t):
if len(points) == 1:
plot_pixel(points[0][0], points[0][1])
else:
newpoints = []
for i in range(0, len(points) - 1):
# old_point_x = (1 - t) * points[i - 1][0] + t * points[i][0]
# old_point_y = (1 - t) * points[i - 1][1] + t * points[i][1]
x = (1 - t) * points[i][0] + t * points[i + 1][0]
y = (1 - t) * points[i][1] + t * points[i + 1][1]
newpoints.append((x, y))
draw_curve(newpoints, t)
Recursion call to draw_curve while t <= 1.
def draw(points):
t = 0
while t <= 1:
draw_curve(points, t)
t += 0.01
#Mouse B-1 bound, for every click draw an oval and append to
#list -- click_points.
click_points = []
def click(event):
click_points.append((event.x, event.y))
oval = canvas.create_oval(event.x - SIZE,
event.y - SIZE,
event.x + SIZE,
event.y + SIZE,
fill = "red")
draw(click_points)
canvas.bind("<Button-1>", click)
root_window.mainloop()
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
I have a compiler error “not defined” although there is a definition
from gasp import *
GRID_SIZE = 30
MARGIN = GRID_SIZE
BACKGROUND_COLOR = color.BLACK # Colors we use
WALL_COLOR = (0.6 * 255, 0.9 * 255, 0.9 * 255)
# The shape of the maze. Each character
# represents a different type of object
# % - Wall
# . - Food
# o - Capsule
# G - Ghost
# P - Chomp
# Other characters are ignored
the_layout = [
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%",
"%.....%.................%.....%",
"%o%%%.%.%%%.%%%%%%%.%%%.%.%%%o%",
"%.%.....%......%......%.....%.%",
"%...%%%.%.%%%%.%.%%%%.%.%%%...%",
"%%%.%...%.%.........%.%...%.%%%",
"%...%.%%%.%.%%% %%%.%.%%%.%...%",
"%.%%%.......%GG GG%.......%%%.%",
"%...%.%%%.%.%%%%%%%.%.%%%.%...%",
"%%%.%...%.%.........%.%...%.%%%",
"%...%%%.%.%%%%.%.%%%%.%.%%%...%",
"%.%.....%......%......%.....%.%",
"%o%%%.%.%%%.%%%%%%%.%%%.%.%%%o%",
"%.....%........P........%.....%",
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"]
class Immovable:
def is_a_wall(self):
return False
class Nothing(Immovable):
pass
class Maze:
def __init__(self):
self.have_window = False
self.game_over = False
self.set_layout(the_layout)
set_speed(20)
def set_layout(self, layout):
height = len(layout)
width = len(layout[0])
self.make_window(width, height)
self.make_map(width, height)
max_y = height - 1
for x in range( width ):
for y in range(height):
char = layout[max_y - y][x]
self.make_object((x, y), char)
def make_window(self, width, height):
grid_width = (width -1) * GRID_SIZE
grid_height = (height - 1) * GRID_SIZE
screen_width = 2 * MARGIN + grid_width
screen_height = 2 * MARGIN + grid_height
begin_graphics(screen_width, screen_height,"Chomp",BACKGROUND_COLOR)
def to_screen(self, point):
(x,y) = point
x = x * GRID_SIZE + MARGIN
y = y * GRID_SIZE + MARGIN
return(x,y)
def make_map(self, width, height):
self.width = width
self.height = height
self.map = []
for y in range(width):
new_row = []
for x in range(width):
new_row.append(Nothing())
self.map.append(new_row)
def make_object(self,point,charactor):
(x,y) = point
if charactor == "%":
self.map[y][x] = Wall(self,point)
def finished(self):
return self.game_over
def play(self):
update_when('next_tick')
def done(self):
end_graphics()
self.map = []
def object_at(self,point):
(x,y) = point
if y < 0 or y >= self.height:
return Nothing()
if x < 0 or x >= self.width:
return Nothing()
return self.map[y][x]
class Wall(Immovable):
def __init__(self, maze, point):
self.place = point # Store our position
self.screen_point = maze.to_screen(point)
self.maze = maze # Keep hold of Maze
self.draw()
def draw(self):
(screen_x, screen_y) = self.screen_point
dot_size = GRID_SIZE * 0.2
Circle(self.screen_point, dot_size,
color = WALL_COLOR, filled = 1)
(x, y) = self.place
neighbors = [ (x+1, y), (x-1, y)]
for neighbor in neighbors:
self.check_neighbor(neighbor)
def check_neighbor(self,neighbor):
maze = self.maze
object = maze.object_at(neighbor)
if object.is_a_wall():
here = self.screen_point
there = maze.to_screen(neighbor)
Line(here, there, color = WALL_COLOR,thickness = 2)
def is_a_wall(self):
return True
the_maze = Maze()
while not the_maze.finished():
the_maze.play()
the_maze.done()
I got this error..
Traceback (most recent call last): File "chomp.py", line 110, in
class Wall(Immovable): File "chomp.py", line 124, in Wall
for neighbor in neighbors: NameError: name '
neighbors' is not defined
I spent lot of time still can't find what's wrong, need some help
You never close the function call to Circle() two lines about line 122, that's probably it. You're probably missing an argument based on the trailing comma.
dot_size = GRID_SIZE * 0.2
Circle(self.screen_point, dot_size, # No closing parentheses
(x, y) = self.place
neighbors = [ (x+1, y), (x-1, y)]
for neighbor in neighbors:
self.check_neighbor(neighbor)
Circle(self.screen_point, dot_size,
missing something at the end of that line