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.
<<How do you use this forum? I can’t scroll it up to see my message as I am typing it in! I lost track of where I was and can’t figure out how to get back to it. Attempts to position the caret seem to just toggle between composition (keyboard active) and display (keyboard gone). Attempts to position the caret are frustrating because instead of dragging the carer, it scrolls the window. And the caret seems to have an off-by-one-line error; when I finally get it positioned, the typing goes into the line avove. And the window does not autoscroll when I’m typing into it, so the bottomost line is invisible behind the keyboard.>>
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())
<<this line was the vestigial line that I lost track of>>
But the problem is that this runs for about 20 seconds,