in roboschool/cpp-household/render-hud.cpp [109:144]
void Viz::drawhist(
QPainter& p,
const char* label, int bracketn,
const QRect& r,
const float* sensors_hist,
const float* sensors)
{
QColor bg = Qt::black;
bg.setAlpha(100);
p.setCompositionMode(QPainter::CompositionMode_Source);
p.fillRect(r, bg);
int mid_y = r.center().y();
float half_height = r.height()*0.5f;
QImage& img = render_viewport->hud_image;
for (int h=0; h<HIST; h++) {
int x = r.left() + h;
float clamp = sensors_hist[h]*0.5;
if (clamp > 1.0f) clamp = 1.0f;
if (clamp < -1.0f) clamp = -1.0f;
int mag = int( 0.5 + mid_y - clamp*half_height );
for (int y=mid_y; y<mag; y++)
img.setPixel(x, y, 0xFFFF8080);
for (int y=mid_y; y>=mag; y--)
img.setPixel(x, y, 0xFF80FF80);
}
char buf[100];
snprintf(buf, sizeof(buf), "%s[%02i] = %+0.2f", label, bracketn, sensors[0]);
p.setCompositionMode(QPainter::CompositionMode_SourceOver);
p.setOpacity(0.7);
p.drawText(r, QString::fromUtf8(buf), Qt::AlignLeft|Qt::AlignTop);
render_viewport->hud_update(r);
}