Skip to content

Instantly share code, notes, and snippets.

@soscler
Last active April 25, 2019 22:26
Show Gist options
  • Save soscler/29a2043f2e88927f0f7a54b66fff157b to your computer and use it in GitHub Desktop.
Save soscler/29a2043f2e88927f0f7a54b66fff157b to your computer and use it in GitHub Desktop.
Rectangle and circle drawing with opengl (glut)
#include<stdio.h>
#include<stdlib.h>
#include "libgraphique.h"
#define x0 200 /* origine grille X */
#define y0 100 /* origine grille Y */
#define LARGEUR 8 /* nombre de cases en largeur d'une grille */
#define HAUTEUR 8 /* nombre de cases en largeur d'une grille */
#define COTE 50 /* nombre de pixels d'un cote d'une case de la grille */
#define RAYON 15 /* rayon du disque representant le curseur */
#define NB_LIGNE 8
#define NB_COL 8
#define X_START 50
#define X_END (NB_COL * COTE + X_START)
#define Y_START 50
#define Y_END (NB_LIGNE * COTE + Y_START)
int main()
{
int lg = LARGEUR, h = HAUTEUR, t = COTE, r = RAYON; int colonne[NB_COL][NB_COL]; int ligne[NB_LIGNE][NB_COL];
int x=X_START + COTE/2;
int y=Y_END - COTE/2;
/* pour passer au mode graphique */
start_graphics();
draw_rectangle(X_START, Y_START,X_END,Y_END);
for(int i=0; i<NB_COL; i++){
draw_line(X_START, Y_START * 2 + i*COTE ,X_END, Y_START * 2 + i*COTE);
}
for(int i=0; i<NB_LIGNE; i++){
draw_line(X_START * 2 + i*COTE, Y_START,X_START * 2 + i*COTE, Y_END);
}
update_graphics();
set_drawing_color(color_GREEN);
draw_circle_full(x, y, RAYON);
update_graphics();
int xe; int ye;
for( xe=0; xe<=3; xe++) {colonne[10][10]=1;}
for(ye=0; ye<=3; ye++) {ligne[10][10]=1;}
/* pour la saisie des fleches du clavier */
int action=0;
int z= 75; //((x)-(50+t/2))/t;
int p= 75; //((y)-(50+t/2))/t;
while (action != 'F')
{
action = get_key();
set_drawing_color(color_WHITE);
draw_circle_full(x,y,RAYON);
update_graphics();
switch (action)
{
case key_RIGHT:
if (x != (X_END - COTE/2)) x += t;
break;
case key_LEFT:
if (x != (X_START + COTE/2)) x -= t;
break;
case key_UP:
if (y != (Y_END - COTE/2)) y += t;
break;
case key_DOWN:
if (y != (Y_START + COTE/2)) y -= t;
break;
default:
draw_string(x,y,"");
break;
}
set_drawing_color(color_GREEN);
draw_circle_full(x,y,RAYON);
update_graphics();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment