1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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;
}
|