Hi to all
I'm newbie in the python and this is my first program in it.
I have created a board that it LEDs can on/off like the checkbox. and a Timeline that has 20 Frames for controlling the animation (Frames are like the RadioButton).
Can you help me :

  • Frames would can save their Frames (on/off). (now they are saving all status to theirselve)
  • this timeline would works as well for playing animation.
  • Thank you for your replying!

-----

import pygame

pygame.init()



size = (800, 600)
screen = pygame.display.set_mode(size)
pygame.display.set_caption("Tablo")

black    = (   0,   0,   0)
white    = ( 255, 255, 255)
green    = (   0, 255,   0)
red      = ( 255,   0,   0)
blue     = (   0,   0, 255)  



done = False

first_nps = True

first_kh = True

ni = 0
nj = 0
nps = 0
R = {}
F = 0
FC = {}


clock = pygame.time.Clock()



while done == False:
  #Event processing:
  for event in pygame.event.get():
    if event.type == pygame.QUIT:
      done = True
    p = pygame.mouse.get_pos()
    x = p[0]
    y = p[1]
    ms = pygame.mouse.get_pressed()
  #Event processing

  #Draw Table
  for x_offest in range(0, 850, 50):
    pygame.draw.line(screen, blue, (x_offest, 0), (x_offest, 400), 5)
  for y_offest in range(0, 650, 50):
    pygame.draw.line(screen, blue, (0 , y_offest), (800 , y_offest), 5)
  pygame.draw.line(screen, black, (0 , 0 + 500), (800 ,  500), 5)
  #Draw Table

  #on/off LEDs
  if ms == (1,0,0):
    for i in range(0, 800, 50):
      for j in range(0, 400,50):
        if x > i and x < i + 50 and y > j and y < j + 50:
          ni = i / 50
          nis = str(ni)
          nj = j / 50
          njs = str(nj)
          nps = nis + njs

          if R.has_key(nps) == 0:
            pygame.draw.circle(screen, red, (i + 25, j+ 25), 20, 20)
            R[nps] = 1
            pygame.time.delay(200)
          else:
            pygame.draw.circle(screen, black, (i + 25, j + 25), 20, 20)
            del R[nps]
            pygame.time.delay(200)

          pygame.display.flip()
  #on/off LEDs

  #Draw Timeline
  for x_offest in range(0, 800, 40):
    pygame.draw.line(screen, white, (x_offest, 450), (x_offest, 550), 4)
  #Draw Timeline
    if ms == (1,0,0) and x > x_offest and x < x_offest + 40 and y > 450 and y < 550:
      fi = x_offest / 40
      F = fi + 1
      FC[F] = R
      print FC

          #Frames radio button
      for gclearer in range(0, 800, 40):
        pygame.draw.circle(screen, black, (gclearer + 20, 500), 15 , 4)
      pygame.draw.circle(screen, green, (x_offest + 20, 500), 15 , 4)
          #Frames radio button




      pygame.time.delay(50)
      pygame.display.flip()  

  pygame.display.flip()
  clock.tick(25)

I don't really see what you're asking. What problem are you having?

I'm a little curious about the control work starting at line 40 above. When you get a pygame.QUIT event, setting done=True doesn't automagically exit the loop...you just fall thru to the next set of code. It doesn't look like you should. Howzabout using break instead?

Speaking of which, shouldn't the next set of code (from line 42 on) be under some sort of mouse event conditional?

I know this is probably not what you were asking but you'll eventually hit this problem too.

I use for event in pygame.event.get() for getting mouse event. ok ok at line 40 and 41 I cancell the main loop after one more time execution (I don't know how to use break for exit), perhaps sys.exit would be better.

I have edited the code, maybe anyone can help me:

import pygame
import sys

pygame.init()


size = (800, 600)
screen = pygame.display.set_mode(size)
pygame.display.set_caption("Tablo")

black    = (   0,   0,   0)
white    = ( 255, 255, 255)
green    = (   0, 255,   0)
red      = ( 255,   0,   0)
blue     = (   0,   0, 255)  



done = False
first_mouse_event = True


LEDs_on = {}
current_frame = 0
Timeline = {}


clock = pygame.time.Clock()



while done == False:
  #Event processing:
  for event in pygame.event.get():
    if event.type == pygame.QUIT:
      sys.exit()
      # or done = True
    mouse_postion = pygame.mouse.get_pos()
    x_mouse = mouse_postion[0]
    y_mouse = mouse_postion[1]
    mouse_status = pygame.mouse.get_pressed()
  #Event processing

  #Draw Table
  for x_offest in range(0, 850, 50):
    pygame.draw.line(screen, blue, (x_offest, 0), (x_offest, 400), 5)
  for y_offest in range(0, 650, 50):
    pygame.draw.line(screen, blue, (0 , y_offest), (800 , y_offest), 5)
  pygame.draw.line(screen, black, (0 , 0 + 500), (800 ,  500), 5)
  #Draw Table

  #on/off LEDs
  first_mouse_event = True
  if mouse_status == (1, 0, 0):
    for i in range(0, 800, 50):
      for j in range(0, 400,50):
        if x_mouse > i and x_mouse < i + 50 and y_mouse > j and y_mouse < j + 50:
          column_number = i / 50
          column_number_string = str(column_number)
          row_number = j / 50
          row_number_string = str(row_number)
          location_string = column_number_string + row_number_string

          if LEDs_on.has_key(location_string) == 0:
            pygame.draw.circle(screen, red, (i + 25, j+ 25), 20, 20)
            while first_mouse_event:
             for event in pygame.event.get():
              mouse_status = pygame.mouse.get_pressed()
              if mouse_status == (0, 0, 0):
                LEDs_on[location_string] = 1
                first_mouse_event = False
          else:
            pygame.draw.circle(screen, black, (i + 25, j + 25), 20, 20)
            while first_mouse_event:
             for event in pygame.event.get():
              mouse_status = pygame.mouse.get_pressed()
              if mouse_status == (0, 0, 0):
                del LEDs_on[location_string]
                first_mouse_event = False


  #on/off LEDs

  #Draw Timeline
  for x_offset in range(0, 800, 40):
    pygame.draw.line(screen, white, (x_offset, 450), (x_offset, 550), 4)
  #Draw Timeline
    if mouse_status == (1,0,0) and x_mouse > x_offset and x_mouse < x_offset + 40 and y_mouse > 450 and y_mouse < 550:
      current_frame = x_offset / 40 + 1
      Timeline[current_frame] = LEDs_on
      print Timeline

          #Frames radio button
      for other_frame_cleaner in range(0, 800, 40):
        pygame.draw.circle(screen, black, (other_frame_cleaner + 20, 500), 15 , 4)
      pygame.draw.circle(screen, green, (x_offset + 20, 500), 15 , 4)
          #Frames radio button





  pygame.display.flip()
  clock.tick(25)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.