Jump to content

Search the Community

Showing results for tags '2d grid for pixel ordering'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Location


WWW


Interests

Found 1 result

  1. So I've been playing around with some RGB LEDs the last few days. I found some really nifty software called Glediator which I can use to control my LEDs. I thought it would be fun to build some sort of tool to build LED animations that would be compatible with the Glediator protocol / microcontroller code. The biggest challenge I was having was how to deal with mapping the pixel data to a specific LED. The LED Pixel data is fed to the microcontroller is Serial; so I had to bust out some math skills to "map" the serial pixel stream to the LEDs as they are arranged. Most RGB LED displays are either parallel strips, a "zig-zag" pattern (probably not the best term), a combo of the two or a custom design. For my purposes I'm dealing strictly with 2D grid style layouts. I wanted to come up with a dynamic way to create a virtual Pixel Grid that I could programmatically assign the pixel ordering to without hard coding the ordering. Here is what I've come up with. The math probably isn't great, but I'm not a math wiz and it was hard enough figuring this much out. ;P In this demo I am simply creating 2D arrays of various sizes and assigning each element a "Pixel Index" to another array with the binary stream of pixel data (not in this script). The arrays can be ordered/assigned using 1 of 4 modes (Horizontal Strips, Vertical Strips, Horizontal ZigZag and Vertical ZigZag) and the Starting point (dubbed Zero Pixel) can be located any of the four "corners" (Top Left, Top Right, Bottom Left and Bottom Right). #include <Array.au3> Global Enum Step *2 $PIXEL_GRID_MODE_HORIZONTAL_STRIPS, $PIXEL_GRID_MODE_VERTICAL_STRIPS, $PIXEL_GRID_MODE_HORIZONTAL_ZIGZAG, $PIXEL_GRID_MODE_VERTICAL_ZIGZAG Global Enum Step *2 $PIXEL_GRID_TOP_LEFT, $PIXEL_GRID_TOP_RIGHT, $PIXEL_GRID_BOTTOM_LEFT, $PIXEL_GRID_BOTTOM_RIGHT Global Const $PIXEL_GRID_ORDER_HSTL = "($iX + 1) + ($iY * ($iCols + 1))-1" Global Const $PIXEL_GRID_ORDER_HSTR = "Abs((($iCols + 1)*($iRows + 1))-($iY * ($iCols + 1))-(($iCols)-$iX)-(($iCols + 1)*($iRows + 1)))" Global Const $PIXEL_GRID_ORDER_HSBL = "(($iCols + 1)*($iRows + 1))-($iY * ($iCols + 1))-(($iCols)-$iX)-1" Global Const $PIXEL_GRID_ORDER_HSBR = "Abs(($iX + 1) + ($iY * ($iCols + 1)) - (($iCols + 1)*($iRows + 1))-1)-1" Global Const $PIXEL_GRID_ORDER_VSTL = "($iY + 1) + ($iX * ($iRows + 1))-1" Global Const $PIXEL_GRID_ORDER_VSTR = "(($iCols + 1)*($iRows + 1))-($iX * ($iRows + 1))-(($iRows)-$iY)-1" Global Const $PIXEL_GRID_ORDER_VSBL = "Abs((($iCols + 1)*($iRows + 1))-($iX * ($iRows + 1))-(($iRows)-$iY)-(($iCols + 1)*($iRows + 1)))" Global Const $PIXEL_GRID_ORDER_VSBR = "Abs(($iY + 1) + ($iX * ($iRows + 1)) - (($iCols + 1)*($iRows + 1))-1)-1" Global Const $PIXEL_GRID_ORDER_HZTL = "(Mod($iY+1,2)=0) ? (" & $PIXEL_GRID_ORDER_HSTR & ") : (" & $PIXEL_GRID_ORDER_HSTL & ")" Global Const $PIXEL_GRID_ORDER_HZTR = "(Mod($iY+1,2)=0) ? (" & $PIXEL_GRID_ORDER_HSTL & ") : (" & $PIXEL_GRID_ORDER_HSTR & ")" Global Const $PIXEL_GRID_ORDER_HZBL = "(Mod($iY+1,2)=0) ? (" & $PIXEL_GRID_ORDER_HSBR & ") : (" & $PIXEL_GRID_ORDER_HSBL & ")" Global Const $PIXEL_GRID_ORDER_HZBR = "(Mod($iY+1,2)=0) ? (" & $PIXEL_GRID_ORDER_HSBL & ") : (" & $PIXEL_GRID_ORDER_HSBR & ")" Global Const $PIXEL_GRID_ORDER_VZTL = "(Mod($iX+1,2)=0) ? (" & $PIXEL_GRID_ORDER_VSBL & ") : (" & $PIXEL_GRID_ORDER_VSTL & ")" Global Const $PIXEL_GRID_ORDER_VZTR = "(Mod($iCols+1,2)=0) ? ((Mod($iX+1,2)=0) ? (" & $PIXEL_GRID_ORDER_VSTR & ") : (" & $PIXEL_GRID_ORDER_VSBR & ")) : ((Mod($iX+1,2)=0) ? (" & $PIXEL_GRID_ORDER_VSBR & ") : (" & $PIXEL_GRID_ORDER_VSTR & "))" Global Const $PIXEL_GRID_ORDER_VZBL = "(Mod($iX+1,2)=0) ? (" & $PIXEL_GRID_ORDER_VSTL & ") : (" & $PIXEL_GRID_ORDER_VSBL & ")" Global Const $PIXEL_GRID_ORDER_VZBR = "(Mod($iCols+1,2)=0) ? ((Mod($iX+1,2)=0) ? (" & $PIXEL_GRID_ORDER_VSBR & ") : (" & $PIXEL_GRID_ORDER_VSTR & ")) : ((Mod($iX+1,2)=0) ? (" & $PIXEL_GRID_ORDER_VSTR & ") : (" & $PIXEL_GRID_ORDER_VSBR & "))" Local $iWidth = 6 Local $iHeight = 9 $aPixelGrid = _PixelGrid_Create($iWidth, $iHeight, $PIXEL_GRID_MODE_HORIZONTAL_STRIPS, $PIXEL_GRID_TOP_LEFT) _ArrayDisplay($aPixelGrid, "Horizontal Strips / Top Left") $iWidth = 4 $iHeight = 5 $aPixelGrid = _PixelGrid_Create($iWidth, $iHeight, $PIXEL_GRID_MODE_VERTICAL_STRIPS, $PIXEL_GRID_BOTTOM_RIGHT) _ArrayDisplay($aPixelGrid, "Vertical Strips / Bottom Right") $iWidth = 6 $iHeight = 4 $aPixelGrid = _PixelGrid_Create($iWidth, $iHeight, $PIXEL_GRID_MODE_HORIZONTAL_ZIGZAG, $PIXEL_GRID_TOP_RIGHT) _ArrayDisplay($aPixelGrid, "Horizontal ZigZag / Top Right") $iWidth = 5 $iHeight = 5 $aPixelGrid = _PixelGrid_Create($iWidth, $iHeight, $PIXEL_GRID_MODE_VERTICAL_ZIGZAG, $PIXEL_GRID_BOTTOM_LEFT) _ArrayDisplay($aPixelGrid, "Vertical ZigZag / Bottom Left") Func _PixelGrid_Create($iCols = 0, $iRows = 0, $iMode = 0, $iZeroPixel = 0) If $iCols <= 0 Or $iRows <= 0 Then Return SetError(1, 0, 0) ;Verify Columns and Rows are >= 1 If $iMode <= 0 Or $iZeroPixel <= 0 Then Return SetError(2, 0, 0) ;Verify Mode and ZeroPixel Local $aPixelGrid[$iRows][$iCols] ;Create Pixel Grid Array _PixelGrid_SetMode($aPixelGrid, $iMode, $iZeroPixel) ;Set Grid Numbering Based on Mode and Zero Pixel Return $aPixelGrid EndFunc ;==>_PixelGrid_Create Func _PixelGrid_SetOrder(ByRef $aPixelGrid, $sFormula = "") If Not UBound($aPixelGrid, 2) Or Not $sFormula Then Return SetError(1, 0, 0) ;Simple Error Checking Local $iRows = UBound($aPixelGrid, 1) - 1 ;Collect Rows and Columns Local $iCols = UBound($aPixelGrid, 2) - 1 For $iY = 0 To $iRows ;Loop Through Grid from Top Left to Bottom Right For $iX = 0 To $iCols $aPixelGrid[$iY][$iX] = Execute($sFormula) ;Use Order Formula to Assign Pixel Address Next Next EndFunc ;==>_PixelGrid_SetOrder Func _PixelGrid_SetMode(ByRef $aPixelGrid, ByRef $iMode, ByRef $iZeroPixel) Switch $iMode Case $PIXEL_GRID_MODE_HORIZONTAL_STRIPS Switch $iZeroPixel Case $PIXEL_GRID_TOP_LEFT _PixelGrid_SetOrder($aPixelGrid, $PIXEL_GRID_ORDER_HSTL) Case $PIXEL_GRID_BOTTOM_LEFT _PixelGrid_SetOrder($aPixelGrid, $PIXEL_GRID_ORDER_HSBL) Case $PIXEL_GRID_TOP_RIGHT _PixelGrid_SetOrder($aPixelGrid, $PIXEL_GRID_ORDER_HSTR) Case $PIXEL_GRID_BOTTOM_RIGHT _PixelGrid_SetOrder($aPixelGrid, $PIXEL_GRID_ORDER_HSBR) EndSwitch Case $PIXEL_GRID_MODE_VERTICAL_STRIPS Switch $iZeroPixel Case $PIXEL_GRID_TOP_LEFT _PixelGrid_SetOrder($aPixelGrid, $PIXEL_GRID_ORDER_VSTL) Case $PIXEL_GRID_BOTTOM_LEFT _PixelGrid_SetOrder($aPixelGrid, $PIXEL_GRID_ORDER_VSBL) Case $PIXEL_GRID_TOP_RIGHT _PixelGrid_SetOrder($aPixelGrid, $PIXEL_GRID_ORDER_VSTR) Case $PIXEL_GRID_BOTTOM_RIGHT _PixelGrid_SetOrder($aPixelGrid, $PIXEL_GRID_ORDER_VSBR) EndSwitch Case $PIXEL_GRID_MODE_HORIZONTAL_ZIGZAG Switch $iZeroPixel Case $PIXEL_GRID_TOP_LEFT _PixelGrid_SetOrder($aPixelGrid, $PIXEL_GRID_ORDER_HZTL) Case $PIXEL_GRID_BOTTOM_LEFT _PixelGrid_SetOrder($aPixelGrid, $PIXEL_GRID_ORDER_HZBL) Case $PIXEL_GRID_TOP_RIGHT _PixelGrid_SetOrder($aPixelGrid, $PIXEL_GRID_ORDER_HZTR) Case $PIXEL_GRID_BOTTOM_RIGHT _PixelGrid_SetOrder($aPixelGrid, $PIXEL_GRID_ORDER_HZBR) EndSwitch Case $PIXEL_GRID_MODE_VERTICAL_ZIGZAG Switch $iZeroPixel Case $PIXEL_GRID_TOP_LEFT _PixelGrid_SetOrder($aPixelGrid, $PIXEL_GRID_ORDER_VZTL) Case $PIXEL_GRID_BOTTOM_LEFT _PixelGrid_SetOrder($aPixelGrid, $PIXEL_GRID_ORDER_VZBL) Case $PIXEL_GRID_TOP_RIGHT _PixelGrid_SetOrder($aPixelGrid, $PIXEL_GRID_ORDER_VZTR) Case $PIXEL_GRID_BOTTOM_RIGHT _PixelGrid_SetOrder($aPixelGrid, $PIXEL_GRID_ORDER_VZBR) EndSwitch EndSwitch EndFunc ;==>_PixelGrid_SetMode Not only was this a fun, personal challenge, but it should integrate into the rest of my LED code nicely! I hope others find this example interesting and perhaps useful and/or inspiring. P.S. I know there are endless way to "formulate" the ordering of the grid, by this is all I need for now. As cool as diagonal zigzags, fills, spirals, etc. are, I haven't seen any LED panels designed with those physical layouts...they would be very specialized...and probably pretty awesome too; just not in the works for my needs. I'll save those cool "orderings" for when I get actual pixel animations designed.
×
×
  • Create New...