loop
mousewhere (mx, my, mb)
if mb = 1 and mx > 10 and mx < 70 and my > 10 and my < 70 then
tool := "pencil"
elsif tool = "pencil" and mb = 1 and pen = 0 and mx > 180 and mx < 990 and my > 10 and my < 550 then
drawdot (mx, my, col)
pen := 1
oldx := mx
oldy := my
elsif mb = 1 and pen = 1 and tool = "pencil" and mx > 180 and mx < 990 and my > 10 and my < 550 then
drawdot (mx, my, col)
drawline (mx, my, oldx, oldy, col)
pen := 1
oldx := mx
oldy := my
elsif mb = 0 and pen = 1 and tool = "pencil" and mx > 180 and mx < 990 and my > 10 and my < 550 then
pen := 0