PDA

View Full Version : ws812 matrix rotate



richard
- 21st May 2015, 11:37
just playing with a ws812 8x8 array and looking for a nice way to rotate a 8x3x8 byte array through 90 degrees, I have left and right shift and up/down sorted but a tidy rotate cw and ccw method is eluding me . any thoughts

the code here is a work in progress and not very well commented

richard
- 21st May 2015, 13:02
I'm thinking complete new array, an inplace rotate give me brain fade



for row = 0 to 7
for column = 0 to 7
for element = 0 to 2
new_pixel[column*(7-row)+row*(7-column)+element]= pixel[row*8+column*3+element ]
next
next
next

richard
- 21st May 2015, 13:38
the penny dropped its a 24 byte wide row , had 8x8 burnt into brain

for row = 0 to 7
for column = 0 to 7
for element = 0 to 2
new_pixel[3*(7-row)+24*column+element]= pixel[row*24+column*3+element ]
next
next
next

richard
- 21st May 2015, 14:10
its so easy when you know how

to go ccw
for row = 0 to 7
for column = 0 to 7
for element = 0 to 2
new_pixel[3*(row)+24*(7-column)+element]= pixel[row*24+column*3+element ]
next
next
next

Art
- 22nd May 2015, 10:12
Hi Richard, did you mean rotating 2D 90 degrees each time you call the function?
If so I wish I’d looked a this. It's in my display code, Tetris has to do it :D I used a lookup table for block rotation,
but rotated digits for vertical orientation.

richard
- 22nd May 2015, 10:32
its a 2d 8x8 matrix each element is 24 bits (rgb) the lot rotate 90 deg with each call . the cw and ccw both work flawlessly and are fairly quick too .
a 45 deg rotate would be interesting.

Art
- 24th May 2015, 13:32
At 8x8 resolution, as you get away from even 90 deg angles, it looks horrible.