Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Status Updates

View All Updates

- - - - -

Draw on grig (matrix of cells) source


  • Please log in to reply
2 replies to this topic

#1 j0x51


    CC Lurker

  • Just Joined
  • Pip
  • 2 posts

Posted 25 June 2010 - 03:45 AM

I'm developing a single color LED matrix and I want to connect it to a PC.

The software must contain matrix field (2d set of cells) of the size of real LED display, and every picture (graphic primitive, text) must be divided into set of pixels.

Could anyone give me source that can do the similar thing (C/C++ source, I'm not familiar with other languages)? For example software that contains something like grid and user can draw on that grid by clicking on the cells with mouse. Like the one at the following screen shot (unfortunately, I don't have sources for it)

Posted Image
  • 0

#2 manux


    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 211 posts

Posted 25 June 2010 - 09:53 AM

For something that simple you might want to use something like Python (or any scripting language).

I'm not aware of any open-source program that does exactly this, but then I'm not aware of much programs anyway, so I'm not really a reliable source for this.
I recommend you do it yourself, it's really something simple to do.

Here, I have some little time to loose, using Python/pygame see how simple it is:
import pygame

#40x40 grid, 10x10 pixel per cell
screen = pygame.display.set_mode((400,400))

carry_on = True

#this little python syntax sugar creates a 40x40 array
#containing only -1
cells = [[-1 for i in range(40)] for j in range(40)]

while carry_on:
    for x in range(40):
        for y in range(40):
            if cells[x][y]>0:
                #args is dest,color,rect
                #rect is (x,y,w,h)
                pygame.draw.rect(screen,(0, 0, 0),(x*10,y*10,10,10))
    for e in pygame.event.get():
        if e.type==pygame.MOUSEBUTTONDOWN:
            posx = e.pos[0]/10
            posy = e.pos[1]/10
            #-1 becomes 1, the light is lit!
        elif e.type==pygame.KEYUP:
            carry_on = False

#send "cells" to your device...
I didn't test the code, but I read it twice to check for stupid errors ;)
  • 0

#3 j0x51


    CC Lurker

  • Just Joined
  • Pip
  • 2 posts

Posted 25 June 2010 - 11:07 AM

It's pity, but I don't have time for starting with Python. In the other set of circumstances I'd like to, but not now.
But thanks anyway.
  • 0

Also tagged with one or more of these keywords: matrix

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download