I am trying to visualize the network load in a network simulation tool. I 
want to display the network nodes as a grid of squares in a window (e.g. a 
4x4 mesh network) where I can individually pick the fill-color for each 
square based on the traffic across the node (the traffic info has to be 
read from a dump file but thats for later). I am trying to see if I can use 
pyglet for this. So, for example, lets say we have a 2x2 network (4 
squares). I want a 2x2 matrix of squares where I can change the fill-color 
of each element individually. I am beginner and so far I have learnt to 
draw a single filled square after looking up a lot of references. See the 
code:

###################################################################
import sys, time, math, os, random
from pyglet.gl import *
 
window = pyglet.window.Window()

label = pyglet.text.Label('Simulation', 
                          font_name='Times New Roman', 
                          font_size=16,
                          color=(204,204,0,255),      #red font (255,0,0) 
opacity=255
                          x=window.width, y=window.height,
                          anchor_x='right', anchor_y='top') 
 
class FilledSquare:
    def __init__(self, width, height, xpos, ypos):
        self.xpos = xpos
        self.ypos = ypos
        self.angle = 0
        self.size = 1
        x = width/2.0
        y = height/2.0
        self.vlist = pyglet.graphics.vertex_list(4, ('v2f', [-x,-y, x,-y, 
-x,y, x,y]), ('t2f', [0,0, 1,0, 0,1, 1,1]), 
('c3B',(0,255,0,0,255,0,0,255,0,0,255,0)))
    def draw(self,w,h,x,y):
        self.width=w
        self.height=h
        self.xpos=x
        self.ypos=y
        glPushMatrix()
        glTranslatef(self.xpos, self.ypos, 0)
        self.vlist.draw(GL_TRIANGLE_STRIP)        
        glPopMatrix()
 
 
@window.event
def on_draw():
    window.clear()
    glClearColor(0, 0.3, 0.5, 0)
    glClear(GL_COLOR_BUFFER_BIT)
    label.draw()
    square1.draw(60,60,460,240)
  
 
square1 = FilledSquare(30, 30, 100, 200)
pyglet.app.run()

  ################################################


   1. I think in this way, the fill-color is static as it is initialized. 
   How can I pass the fill-color?
   2. How to create a 2D array of FilledSquare (maybe something like 
   square[i][j] which I can access in a loop.

Please let me know if it is possible at all. I have already spent a lot of 
time and this is not my main focus and I am short of time. I hope its 
easier than what I am imagining.

-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to