diff options
Diffstat (limited to 'PIPET-1/pipet_view.c')
-rw-r--r-- | PIPET-1/pipet_view.c | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/PIPET-1/pipet_view.c b/PIPET-1/pipet_view.c new file mode 100644 index 0000000..2bb1380 --- /dev/null +++ b/PIPET-1/pipet_view.c @@ -0,0 +1,92 @@ +// +// pipet_view.c +// PIPET-1 +// +// Created by dianshi on 3/28/20. +// Copyright © 2020 dianshi. All rights reserved. +// + +#include "pipet_view.h" + +int pv_init(pipet_view *pv, int32_t max_dots, int32_t w, int32_t h) +{ + pv->dots_size = max_dots; + + pv->dots = malloc(sizeof(uint64_t)*max_dots); + memset(pv->dots,0,sizeof(uint64_t)*max_dots); + + pv->dots_relative = malloc(sizeof(float)*max_dots); + memset(pv->dots_relative,0,sizeof(float)*max_dots); + + pv->width = w; + pv->height = h; + pv->cur_dot = 0; + + return 0; +} + +int pv_set_color(pipet_view *pv, int32_t color) +{ + pv->color = color; + + return 0; +} + +int pv_add_dot(pipet_view *pv, uint64_t val) +{ + int i=0; + float f = 0.0f; + + pv->dots[pv->cur_dot] = val; + pv->cur_dot = (pv->cur_dot+1)%pv->dots_size; + + if (val > pv->max_dot_value) + { + pv->max_dot_value = val; + //printf("New max value %d\n",val); + } + + for (i=0;i<pv->dots_size;i++) + { + f = 1.0f*pv->dots[i]/pv->max_dot_value; + + //pv->dots_relative[i] = (uint8_t)(f*255); + pv->dots_relative[i] = f; + //printf("%.3f %f (%d-%d) ",f, pv->dots_relative[i], pv->dots[i], pv->max_dot_value); + + } + printf("Max:%d K Val:%d K \n",pv->max_dot_value/1024,val/1024); + + return 0; +} + + +int pv_destroy(pipet_view *pv) +{ + free(pv->dots); + free(pv->dots_relative); + return 0; +} + +int pv_draw_texture(pipet_view *pv, SDL_Renderer *renderer, int x, int y) +{ + SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255); + SDL_RenderDrawPoint(renderer,x,y); + return 0; +} + + +int pv_render(pipet_view *pv, SDL_Renderer *renderer) +{ + int i; + float f=1.0f*pv->width/pv->dots_size; + float fx = 0.0f; + + for (i=0;i<pv->width;i++) + { + fx+=f; + pv_draw_texture(pv, renderer, fx, (pv->height-pv->height*pv->dots_relative[i]-1)); + } + + return 0; +} |