I am writing my first Python program. The code so far is what is shown below. For right now, it draws a square grid on the left side of the screen, in landscape mode. When I get parts of it working, I will begin to worry about issues like switching from landscape to portrait, but that’s for later. The goal right now is to draw a 6x6 grid and respond to finger touches.
<
Before I lost track of where I was, I started to explain that the program crashes after 20 seconds. I’m using the Python 3.x version to run it.
I conjecture two explanations:
-
There is a bug in Pythonista or Python that I am hitting
-
I am doing something in this code that is frantically consuming resources, and when they run out, instead of a friendly warning telling me where it failed, it just quits.
The most likely candidate is the second item. Can someone check the code below and see if I have committed some egregious newbie errot?
from scene import *
# A square is defined by a tuple
# x0, y0, x1, y1, count
#
class dig (Scene):
def setup(self):
self.background_color = 'green'
def update(self) :
width = min(self.size[0], self.size[1])
background('green')
fill('red')
stroke(1,1,0)
stroke_weight(3)
rect(0,0,width,width)
print('rect(', 0, ',', 0, ',', width, ',', width, ')')
delta = width/6
# draw the vertical grid lines
stroke_weight(1)
for i in range(1, 6):
line(i * delta, 0, i * delta, width)
# draw the horizontal grid lines
for i in range(1,6):
line(0, i * delta, width, i * delta)
run(dig())
<
But the problem is that this runs for about 20 seconds,