static void draw_dots(const wtree<3>& t, float depth) { glColor3f(1.0*depth, 1.0*depth, 1.0*depth); glVertex3f(t.element[0], t.element[1], t.element[2]); for(size_t i = 0; i < wtree<3>::node_count; i++) if(t.nodes[i].count > 0) draw_dots(*t.nodes[i].wtree, depth*0.7); }
void wtree3_viewer::draw() { const wtree<3>& t = *tree_ptr; constexpr float dist = 2.0; float rad = in_range(i, 360, 0, 2.0 * M_PI); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60.0, 1.333, 1.0, 100.0); gluLookAt(0.5+dist*std::cos(rad), 0.5, 0.5+dist*std::sin(rad), 0.5, 0.5, 0.5, 0.0, 1.0, 0.0); //glTranslatef(-0.5, -0.5, 0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClear(GL_COLOR_BUFFER_BIT); glLineWidth(5.0); glBegin(GL_LINES); for(size_t i = 0; i < 3; i++) { glColor3f(i == 0, i == 1, i == 2); glVertex3f(0.0, 0.0, 0.0); glVertex3f(i == 0, i == 1, i == 2); } glEnd(); glLineWidth(1.0); glBegin(GL_LINES); draw_bounds(t, {{{{0.0, 1.0}}, {{0.0, 1.0}}, {{0.0, 1.0}}}}, 1.0); glEnd(); glPointSize(3.0); glBegin(GL_POINTS); draw_dots(t, 1.0); glEnd(); glFlush(); glutSwapBuffers(); glutPostRedisplay(); i++; }
static void color_graticule(VectorscopeContext *s, AVFrame *out, int X, int Y, int D, int P) { const float o = s->opacity; int i; for (i = 0; i < 12; i++) { int x = positions[P][i][X]; int y = positions[P][i][Y]; int d = positions[P][i][D]; draw_dots(out->data[D] + y * out->linesize[D] + x, out->linesize[D], d, o); draw_dots(out->data[X] + y * out->linesize[X] + x, out->linesize[X], x, o); draw_dots(out->data[Y] + y * out->linesize[Y] + x, out->linesize[Y], y, o); if (out->data[3]) draw_dots(out->data[3] + y * out->linesize[3] + x, out->linesize[3], 255, o); } if (s->flags & 1) { int x = positions[P][12][X]; int y = positions[P][12][Y]; int d = positions[P][12][D]; draw_dots(out->data[D] + y * out->linesize[D] + x, out->linesize[D], d, o); draw_dots(out->data[X] + y * out->linesize[X] + x, out->linesize[X], x, o); draw_dots(out->data[Y] + y * out->linesize[Y] + x, out->linesize[Y], y, o); if (out->data[3]) draw_dots(out->data[3] + y * out->linesize[3] + x, out->linesize[3], 255, o); } if (s->flags & 2) { int x = positions[P][13][X]; int y = positions[P][13][Y]; int d = positions[P][12][D]; draw_dots(out->data[D] + y * out->linesize[D] + x, out->linesize[D], d, o); draw_dots(out->data[X] + y * out->linesize[X] + x, out->linesize[X], x, o); draw_dots(out->data[Y] + y * out->linesize[Y] + x, out->linesize[Y], y, o); if (out->data[3]) draw_dots(out->data[3] + y * out->linesize[3] + x, out->linesize[3], 255, o); } }
static void green_graticule(VectorscopeContext *s, AVFrame *out, int X, int Y, int D, int P) { const float o = s->opacity; int i; for (i = 0; i < 12; i++) { int x = positions[P][i][X]; int y = positions[P][i][Y]; draw_dots(out->data[0] + y * out->linesize[0] + x, out->linesize[0], 128, o); draw_dots(out->data[1] + y * out->linesize[1] + x, out->linesize[1], 0, o); draw_dots(out->data[2] + y * out->linesize[2] + x, out->linesize[2], 0, o); if (out->data[3]) draw_dots(out->data[3] + y * out->linesize[3] + x, out->linesize[3], 255, o); } if (s->flags & 1) { int x = positions[P][12][X]; int y = positions[P][12][Y]; draw_dots(out->data[0] + y * out->linesize[0] + x, out->linesize[0], 128, o); draw_dots(out->data[1] + y * out->linesize[1] + x, out->linesize[1], 0, o); draw_dots(out->data[2] + y * out->linesize[2] + x, out->linesize[2], 0, o); if (out->data[3]) draw_dots(out->data[3] + y * out->linesize[3] + x, out->linesize[3], 255, o); } if (s->flags & 2) { int x = positions[P][13][X]; int y = positions[P][13][Y]; draw_dots(out->data[0] + y * out->linesize[0] + x, out->linesize[0], 128, o); draw_dots(out->data[1] + y * out->linesize[1] + x, out->linesize[1], 0, o); draw_dots(out->data[2] + y * out->linesize[2] + x, out->linesize[2], 0, o); if (out->data[3]) draw_dots(out->data[3] + y * out->linesize[3] + x, out->linesize[3], 255, o); } }
ENTRYPOINT void draw_spiral(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); GC gc = MI_GC(mi); int i, j; spiralstruct *sp; if (spirals == NULL) return; sp = &spirals[MI_SCREEN(mi)]; if (sp->traildots == NULL) return; MI_IS_DRAWN(mi) = True; if (sp->erase == 1) { XSetForeground(display, gc, MI_BLACK_PIXEL(mi)); draw_dots(mi, sp->inc); } sp->cx += sp->dx; sp->traildots[sp->inc].hx = sp->cx; if ((sp->cx > 9000.0) || (sp->cx < 1000.0)) sp->dx *= -1.0; sp->cy += sp->dy; sp->traildots[sp->inc].hy = sp->cy; if ((sp->cy > 9000.0) || (sp->cy < 1000.0)) sp->dy *= -1.0; sp->radius += sp->dr; sp->traildots[sp->inc].hr = sp->radius; if ((sp->radius > 2500.0) && (sp->dr > 0.0)) sp->dr *= -1.0; else if ((sp->radius < 50.0) && (sp->radius < 0.0)) sp->dr *= -1.0; /* Randomly give some variations to: */ /* spiral direction (if it is within the boundaries) */ if ((NRAND(3000) < 1 * JAGGINESS) && (((sp->cx > 2000.0) && (sp->cx < 8000.0)) && ((sp->cy > 2000.0) && (sp->cy < 8000.0)))) { sp->dx = (float) (10 - NRAND(20)) * SPEED; sp->dy = (float) (10 - NRAND(20)) * SPEED; } /* The speed of the change in size of the spiral */ if (NRAND(3000) < 1 * JAGGINESS) { if (LRAND() & 1) sp->dr += (float) (NRAND(3) + 1); else sp->dr -= (float) (NRAND(3) + 1); /* don't let it get too wild */ if (sp->dr > 18.0) sp->dr = 18.0; else if (sp->dr < 4.0) sp->dr = 4.0; } /* The speed of rotation */ if (NRAND(3000) < 1 * JAGGINESS) sp->da = (float) NRAND(360) / 7200.0 + 0.01; /* Reverse rotation */ if (NRAND(3000) < 1 * JAGGINESS) sp->da *= -1.0; sp->angle += sp->da; sp->traildots[sp->inc].ha = sp->angle; if (sp->angle > TWOPI) sp->angle -= TWOPI; else if (sp->angle < 0.0) sp->angle += TWOPI; sp->colors += (float) MI_NPIXELS(mi) / ((float) (2 * sp->nlength)); if (sp->colors >= (float) MI_NPIXELS(mi)) sp->colors = 0.0; if (MI_NPIXELS(mi) > 2) XSetForeground(display, gc, MI_PIXEL(mi, (int) sp->colors)); else XSetForeground(display, gc, MI_WHITE_PIXEL(mi)); draw_dots(mi, sp->inc); sp->inc++; if (sp->inc > sp->nlength - 1) { sp->inc -= sp->nlength; sp->erase = 1; } if (sp->redrawing) { for (i = 0; i < REDRAWSTEP; i++) { j = (sp->inc - sp->redrawpos + sp->nlength) % sp->nlength; draw_dots(mi, j); if (++(sp->redrawpos) >= sp->nlength) { sp->redrawing = 0; break; } } } }
int main(int argc, char **argv) { // On initialise la SDL if ( SDL_Init( SDL_INIT_VIDEO ) < 0 ) { printf( "Erreur init SDL: %s\n", SDL_GetError() ); return 1; } // On s'assure que SDL est quitté correctement à l'arrêt du prog atexit(SDL_Quit); // Création d'une fenêtre Uint32 screenFlags = SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_RESIZABLE; int screenBPP = 32; SDL_Surface* screen = SDL_SetVideoMode(470, 470, screenBPP, screenFlags); if ( !screen ) { printf("Impossible d'utiliser la résolution souhaitée: %s\n", SDL_GetError()); return 1; } // Couleurs des éléments visuels Uint32 couleurRoue = SDL_MapRGB(screen->format, 255, 0, 0); Uint32 couleurCadran = SDL_MapRGB(screen->format, 255, 0, 0); Uint32 couleurRoueOff = SDL_MapRGB(screen->format, 32, 32, 32); Uint32 couleurDigits = SDL_MapRGB(screen->format, 255, 0, 0); Uint32 couleurDigitsOff = SDL_MapRGB(screen->format, 32, 32, 32); // Rayons des éléments int rayonPoint = 6; int rayonHorloge = 294; int ecartCadran = 22; // Stockage du temps time_t tempsBrut; struct tm *temps; const int framerate = 10; int timeDelta = 1000/framerate; // Boucle principale int done = 0; while (!done) { // Traitement des évènements SDL_Event event; while (SDL_PollEvent(&event)) { // Message ou pas message ? switch (event.type) { case SDL_VIDEORESIZE: screen = SDL_SetVideoMode(event.resize.w, event.resize.h, screenBPP, screenFlags); break; case SDL_QUIT: done = 1; break; case SDL_KEYDOWN: { // exit if ESCAPE is pressed if (event.key.keysym.sym == SDLK_ESCAPE) done = 1; break; } } } // DEBUT DE L'AFFICHAGE // Vidange de la surface d'affichage SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0)); // Calcul rayon horloge en fonction de la largeur de l'écran (nb: 300) rayonHorloge = (screen->h / 2) - rayonPoint - (screen->h * 0.05); // Limitation rayon horloge en fonction de la hauteur de l'écran if(rayonHorloge > (screen->h / 2) - rayonPoint - ecartCadran) { rayonHorloge = (screen->h / 2) - rayonPoint - ecartCadran; } if(rayonHorloge > (screen->w / 2) - rayonPoint - ecartCadran) { rayonHorloge = (screen->w / 2) - rayonPoint - ecartCadran; } // Calcul rayon point rayonPoint = rayonHorloge * 0.023; // Calcul écart cadran ecartCadran = rayonPoint * 4; // On récupère l'heure et la date time(&tempsBrut); temps = localtime(&tempsBrut); //printf("%d\n", temps->tm_sec); // On affiche la roue en mode "off" draw_dots(screen, 60, 60, (screen->w / 2) - rayonHorloge, (screen->h / 2) - rayonHorloge, rayonHorloge, rayonPoint, couleurRoueOff); // Puis on affiche le cadran autour de la roue draw_dots(screen, 12, 12, (screen->w / 2) - (rayonHorloge + ecartCadran), (screen->h / 2) - (rayonHorloge + ecartCadran), (rayonHorloge + ecartCadran), rayonPoint, couleurCadran); // Et enfin on affiche la roue des secondes draw_dots(screen, temps->tm_sec, 60, (screen->w / 2) - rayonHorloge, (screen->h / 2) - rayonHorloge, rayonHorloge, rayonPoint, couleurRoue); draw_digit_clock(screen, (screen->w / 2), (screen->h / 2), rayonHorloge, rayonPoint, couleurDigitsOff, NULL); draw_digit_clock(screen, (screen->w / 2), (screen->h / 2), rayonHorloge, rayonPoint, couleurDigits, tempsBrut); // FIN DE L'AFFICHAGE // Mise à jour de l'affichage SDL_Flip(screen); // Méthode dégueulasse pour restreindre le nombre de FPS // Par extension, réduit la conso CPU SDL_Delay(timeDelta); } return 0; }