Niiiice glitch art...
This commit is contained in:
parent
18fd12e916
commit
ec0233f756
5 changed files with 35 additions and 44 deletions
|
|
@ -54,10 +54,10 @@ unsigned const char const FUCKED_UP_BOTTLE_MAP[CRATE_SIZE] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned const char const CRATE_MAP[CRATE_COUNT] = {
|
unsigned const char const CRATE_MAP[CRATE_COUNT] = {
|
||||||
0x37, 0x35, 0x33, 0x31, 0x21, 0x23, 0x25, 0x27,
|
0x07, 0x05, 0x03, 0x01, 0x10, 0x12, 0x14, 0x16,
|
||||||
0x36, 0x34, 0x32, 0x30, 0x20, 0x22, 0x24, 0x26,
|
0x06, 0x04, 0x02, 0x00, 0x11, 0x13, 0x15, 0x17,
|
||||||
0x16, 0x14, 0x12, 0x10, 0x00, 0x02, 0x04, 0x06,
|
0x26, 0x24, 0x22, 0x20, 0x31, 0x33, 0x35, 0x37,
|
||||||
0x17, 0x15, 0x13, 0x11, 0x01, 0x03, 0x05, 0x07
|
0x27, 0x25, 0x23, 0x21, 0x30, 0x32, 0x34, 0x36
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SYSTICKS_PER_SECOND 100
|
#define SYSTICKS_PER_SECOND 100
|
||||||
|
|
@ -149,8 +149,8 @@ unsigned long framebuffer_read(void *data, unsigned long len) {
|
||||||
for(unsigned int x=0; x<CRATE_WIDTH; x++){
|
for(unsigned int x=0; x<CRATE_WIDTH; x++){
|
||||||
for(unsigned int y=0; y<CRATE_HEIGHT; y++){
|
for(unsigned int y=0; y<CRATE_HEIGHT; y++){
|
||||||
unsigned int bottle = BOTTLE_MAP[x + y*CRATE_WIDTH];
|
unsigned int bottle = BOTTLE_MAP[x + y*CRATE_WIDTH];
|
||||||
if(idx == 0x07)
|
// if(idx == 0x07)
|
||||||
bottle = FUCKED_UP_BOTTLE_MAP[x + y*CRATE_WIDTH];
|
// bottle = FUCKED_UP_BOTTLE_MAP[x + y*CRATE_WIDTH];
|
||||||
unsigned int dst = bus*BUS_SIZE + (crate*CRATE_SIZE + bottle)*3;
|
unsigned int dst = bus*BUS_SIZE + (crate*CRATE_SIZE + bottle)*3;
|
||||||
unsigned int src = (y*CRATE_WIDTH + x)*3;
|
unsigned int src = (y*CRATE_WIDTH + x)*3;
|
||||||
// Copy r, g and b data
|
// Copy r, g and b data
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@
|
||||||
|
|
||||||
|
|
||||||
void free_framebuffer(framebuffer_t *fb){
|
void free_framebuffer(framebuffer_t *fb){
|
||||||
printf("Freeing %lx and %lx\n", fb->data, fb);
|
|
||||||
free(fb->data);
|
free(fb->data);
|
||||||
free(fb);
|
free(fb);
|
||||||
}
|
}
|
||||||
|
|
@ -303,20 +302,16 @@ framebuffer_t *framebuffer_render_text(char *s, glyphtable_t *glyph_table){
|
||||||
fb->w = gbufwidth;
|
fb->w = gbufwidth;
|
||||||
fb->h = gbufheight;
|
fb->h = gbufheight;
|
||||||
fb->data = gbuf;
|
fb->data = gbuf;
|
||||||
printf("Returning buffer with w %ld h %ld memory location %lx\n", gbufwidth, gbufheight, gbuf);
|
|
||||||
return fb;
|
return fb;
|
||||||
error:
|
error:
|
||||||
free(gbuf);
|
free(gbuf);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void console_render_buffer(framebuffer_t *fb){
|
void console_render_buffer(color_t *data, size_t w, size_t h){
|
||||||
/* Render framebuffer to terminal, two pixels per character using Unicode box drawing stuff */
|
/* Render framebuffer to terminal, two pixels per character using Unicode box drawing stuff */
|
||||||
color_t lastfg = {0, 0, 0}, lastbg = {0, 0, 0};
|
color_t lastfg = {0, 0, 0}, lastbg = {0, 0, 0};
|
||||||
printf("\e[38;5;0;48;5;0m");
|
printf("\e[38;5;0;48;5;0m");
|
||||||
color_t *data = fb->data;
|
|
||||||
size_t w = fb->w;
|
|
||||||
size_t h = fb->h;
|
|
||||||
for(size_t y=0; y < h; y+=2){
|
for(size_t y=0; y < h; y+=2){
|
||||||
for(size_t x=0; x < w; x++){
|
for(size_t x=0; x < w; x++){
|
||||||
/* Da magicks: ▀█▄ */
|
/* Da magicks: ▀█▄ */
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,6 @@
|
||||||
#include "font.h"
|
#include "font.h"
|
||||||
|
|
||||||
framebuffer_t *framebuffer_render_text(char *s, glyphtable_t *glyph_table);
|
framebuffer_t *framebuffer_render_text(char *s, glyphtable_t *glyph_table);
|
||||||
void console_render_buffer(framebuffer_t *fb);
|
void console_render_buffer(color_t *data, size_t w, size_t h);
|
||||||
|
|
||||||
#endif//__MAIN_H__
|
#endif//__MAIN_H__
|
||||||
|
|
|
||||||
|
|
@ -14,22 +14,35 @@ FRAME_SIZE = CRATE_WIDTH*CRATE_HEIGHT*3
|
||||||
|
|
||||||
dev = usb.core.find(idVendor=0x1cbe, idProduct=0x0003)
|
dev = usb.core.find(idVendor=0x1cbe, idProduct=0x0003)
|
||||||
|
|
||||||
def sendframe(framedata):
|
def sendframe(framedata, index):
|
||||||
""" Send a frame to the display
|
""" Send a frame to the display
|
||||||
|
|
||||||
The argument contains a h * w array of 3-tuples of (r, g, b)-data or 4-tuples of (r, g, b, a)-data where the a
|
The argument contains a h * w array of 3-tuples of (r, g, b)-data or 4-tuples of (r, g, b, a)-data where the a
|
||||||
channel is ignored.
|
channel is ignored.
|
||||||
"""
|
"""
|
||||||
|
for y in range(DISPLAY_HEIGHT):
|
||||||
|
for x in range(DISPLAY_WIDTH):
|
||||||
|
r, g, b, _ = framedata[y][x]
|
||||||
|
print('#' if r > 10 else ' ', end='')
|
||||||
|
print()
|
||||||
for cx, cy in product(range(CRATES_X), range(CRATES_Y)):
|
for cx, cy in product(range(CRATES_X), range(CRATES_Y)):
|
||||||
data = [ v for x in range(CRATE_WIDTH) for y in range(CRATE_HEIGHT) for v in framedata[cy*CRATE_HEIGHT + y][cx*CRATE_WIDTH + x][:3] ]
|
data = [0,0,0]*CRATE_WIDTH*CRATE_HEIGHT
|
||||||
# data = [0,0,0]*CRATE_WIDTH*CRATE_HEIGHT
|
print('CRATE X {} Y {}'.format(cx, cy))
|
||||||
# for x, y in product(range(CRATE_WIDTH), range(CRATE_HEIGHT)):
|
for y in range(CRATE_HEIGHT):
|
||||||
# r, g, b, _ = framedata[cy*CRATE_HEIGHT + y][cx*CRATE_WIDTH + x]
|
for x in range(CRATE_WIDTH):
|
||||||
# data[x*3 + y*CRATE_WIDTH*3 + 0] = r
|
r, g, b, _ = framedata[cy*CRATE_HEIGHT + y][cx*CRATE_WIDTH + x]
|
||||||
# data[x*3 + y*CRATE_WIDTH*3 + 1] = g
|
# import colorsys
|
||||||
# data[x*3 + y*CRATE_WIDTH*3 + 2] = b
|
# r,g,b = colorsys.hsv_to_rgb(cx*0.1+cy*0.2, 1, 1)
|
||||||
# print(r, g, b)
|
# r,g,b = int(r*255), int(g*255), int(b*255)
|
||||||
|
#r,g,b = (255,0,255) if cy*CRATES_X+cx == index else (0,0,0)
|
||||||
|
#print('#' if r > 10 else ' ', end='')
|
||||||
|
data[x*3 + y*CRATE_WIDTH*3 + 0] = r
|
||||||
|
data[x*3 + y*CRATE_WIDTH*3 + 1] = g
|
||||||
|
data[x*3 + y*CRATE_WIDTH*3 + 2] = b
|
||||||
|
print()
|
||||||
|
#data = [ v for x in range(CRATE_WIDTH) for y in range(CRATE_HEIGHT) for v in framedata[cy*CRATE_HEIGHT + y][cx*CRATE_WIDTH + x][:3] ]
|
||||||
#data = [ framedata[DISPLAY_WIDTH*3*(cy*CRATE_HEIGHT + y) + 3*(cx*CRATE_WIDTH + x)+c] for x in range(CRATE_WIDTH) for y in range(CRATE_HEIGHT) for c in range(3) ]
|
#data = [ framedata[DISPLAY_WIDTH*3*(cy*CRATE_HEIGHT + y) + 3*(cx*CRATE_WIDTH + x)+c] for x in range(CRATE_WIDTH) for y in range(CRATE_HEIGHT) for c in range(3) ]
|
||||||
|
data = framedata[cy*CRATE_HEIGHT:(cy+1)*CRATE_HEIGHT, cx*CRATE_WIDTH:(cx+1)*CRATE_WIDTH, :3].flat
|
||||||
if len(data) != FRAME_SIZE:
|
if len(data) != FRAME_SIZE:
|
||||||
raise ValueError('Invalid frame data. Expected {} bytes, got {}.'.format(FRAME_SIZE, len(data)))
|
raise ValueError('Invalid frame data. Expected {} bytes, got {}.'.format(FRAME_SIZE, len(data)))
|
||||||
# Send framebuffer data
|
# Send framebuffer data
|
||||||
|
|
|
||||||
|
|
@ -22,38 +22,21 @@ def render_text(text):
|
||||||
assert unifont
|
assert unifont
|
||||||
fb = bdf.framebuffer_render_text(bytes(str(text), 'UTF-8'), unifont)
|
fb = bdf.framebuffer_render_text(bytes(str(text), 'UTF-8'), unifont)
|
||||||
fbd = fb.contents
|
fbd = fb.contents
|
||||||
print('FB STRUCT: w {} h {} memory location {:x}'.format(fbd.w, fbd.h, addressof(fbd.data.contents)))
|
|
||||||
print("TYPE:", type(fbd.data))
|
|
||||||
casted = cast(fbd.data, POINTER(c_uint8))
|
|
||||||
print("CASTED TYPE:" , type(casted))
|
|
||||||
buf = np.ctypeslib.as_array(cast(fbd.data, POINTER(c_uint8)), shape=(fbd.h, fbd.w, 4))
|
buf = np.ctypeslib.as_array(cast(fbd.data, POINTER(c_uint8)), shape=(fbd.h, fbd.w, 4))
|
||||||
print('RAW DATA:')
|
|
||||||
alen = fbd.h*fbd.w
|
|
||||||
# for i in range(alen):
|
|
||||||
# c = fbd.data[i]
|
|
||||||
# print('{:x}'.format(addressof(c)), c.r, c.g, c.b)
|
|
||||||
print('BUF', buf.shape, buf.dtype)
|
|
||||||
# for x, y, z in product(range(fbd.h), range(fbd.w), range(4)):
|
|
||||||
# print(buf[x][y][z])
|
|
||||||
|
|
||||||
# Set data pointer to NULL before freeing framebuffer struct to prevent free_framebuffer from also freeing the data
|
# Set data pointer to NULL before freeing framebuffer struct to prevent free_framebuffer from also freeing the data
|
||||||
# buffer that is now used by numpy
|
# buffer that is now used by numpy
|
||||||
bdf.console_render_buffer(fb)
|
bdf.console_render_buffer(fb)
|
||||||
fbd.data = cast(c_void_p(), POINTER(COLOR))
|
fbd.data = cast(c_void_p(), POINTER(COLOR))
|
||||||
bdf.free_framebuffer(fb)
|
bdf.free_framebuffer(fb)
|
||||||
print('Rendered {} chars into a buffer of w {} h {} numpy buf {}'.format(len(text), fbd.w, fbd.h, buf.shape))
|
|
||||||
return buf
|
return buf
|
||||||
|
|
||||||
|
def printframe(fb):
|
||||||
|
h,w,_ = fb.shape
|
||||||
|
bdf.console_render_buffer(fb.ctypes.data_as(ctypes.POINTER(ctypes.c_uint8)), w, h)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
fb = render_text('foobarbaz');
|
fb = render_text('foobarbaz');
|
||||||
print('buffer shape {} dtype {}'.format(fb.shape, fb.dtype))
|
|
||||||
# import colorsys
|
|
||||||
# h, w, _ = fb.shape
|
|
||||||
# for x, y in product(range(w), range(h)):
|
|
||||||
# r,g,b = colorsys.hsv_to_rgb(x*0.03+y*0.05, 1, 1)
|
|
||||||
# fb[x][y] = (r,g,b,0)
|
|
||||||
# print(fb)
|
|
||||||
sendframe(fb)
|
sendframe(fb)
|
||||||
#printframe(fb)
|
# printframe(fb)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue