1

règles:
- ça doit compiler et fonctionner (au moins à peu près) partout où il y a un compilateur C99
- peu importe ce que ça fait.
- ça ne doit pas utiliser de libs non portables (exemples: SDL ok, glut ok, Xlib pas ok)
on peut faire les 5 actions suivantes en même temps
- on ne peut supprimer que 3 lignes maximum
- on ne peut ajouter que 10 lignes maximum
- on ne peut éditer de manière minime (10 caractères par lignes maximum) que 10 lignes maximum
- on peut éditer pour corriger un bug sans limite
- on peut déplacer du code sans limite si ça ne modifie pas le comportement

edit: clarification pour vince

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

int main(int argc,char *argv[]){
  return 0;
}
avatar
fabetal_ > Hier, je me suis fait monter par un pote
redangel > et en chevals, ça donne quoi?
Nil> OMG I think I'm gay

2

Edited_3056

3

#include <stdio.h> 
#include <stdlib.h> 
#include <stdint.h> 
#include <SDL.h> 

/* amusons nous à dessiner avec les nombres premiers! */
uint8_t isprime(uint32_t n) {
  for (uint32_t d=2;d<n/2;d++)
    if(!(n%d))
      return 0;
  return 42;
}

int main(int argc,char *argv[]){ 
    SDL_Surface *screen;  
    SDL_Event event; 
    if(SDL_Init(SDL_INIT_VIDEO) == -1) 
        exit(1); 
    atexit(SDL_Quit);  
    screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE); 
    if (screen == NULL) 
        exit(1); 
    SDL_WM_SetCaption("Enjoy !", NULL); 
  return 0; 
}
avatar
fabetal_ > Hier, je me suis fait monter par un pote
redangel > et en chevals, ça donne quoi?
Nil> OMG I think I'm gay

4

#include <stdio.h> 
#include <stdlib.h> 
#include <stdint.h> 
#include <SDL.h> 

/* amusons nous à dessiner avec les nombres premiers! */
uint8_t isprime(uint32_t n) {
  for (uint32_t d=2;d*d<=n;d++)
    if(!(n%d))
      return 0;
  return 42;
}

int main(int argc,char *argv[]){ 
    SDL_Surface *screen;  
    SDL_Event event; 
    if(SDL_Init(SDL_INIT_VIDEO) == -1) 
        exit(1); 
    atexit(SDL_Quit);  
    screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE); 
    if (screen == NULL) 
        exit(1); 
    SDL_WM_SetCaption("Enjoy !", NULL); 

    /* youpi, ça bouge! */
    for (uint32_t n=0,c=0x123456; !SDL_PollEvent(&event) || event.type!=SDL_QUIT; n+=128*96,c=(c*189+123)%0xFF4221) {
        for (uint32_t x=0; x<128*96; x++)
            if (isprime(x+n)) {
                SDL_Rect r={x%128*5,x/128*5,5,5};
                SDL_FillRect(screen, &r, c);
            }
        SDL_Flip(screen);
    }

  return 0; 
}


« The biggest civil liberty of all is not to be killed by a terrorist. » (Geoff Hoon, ministre des transports anglais)

5

(ha ha quel con je fais, j'avais mis /2 parce que je connaissais pas la racine entière grin)
avatar
fabetal_ > Hier, je me suis fait monter par un pote
redangel > et en chevals, ça donne quoi?
Nil> OMG I think I'm gay

6

(ouais j'ai dû changer ça parce que ça finissait par ramer violemment happy)
((hmm il faudrait un moyen de signaler les changements qu'on a fait, parce que là c'est qd même difficile à voir sans faire un diff sad))

« The biggest civil liberty of all is not to be killed by a terrorist. » (Geoff Hoon, ministre des transports anglais)

7

glut et sdl existent sur ti68k ?
avatar
<<< Kernel Extremis©®™ >>> et Inventeur de la différence administratif/judiciaire ! (©Yoshi Noir)

<Vertyos> un poil plus mais elle suce bien quand même la mienne ^^
<Sabrina`> tinkiete flan c juste qu'ils sont jaloux que je te trouve aussi appétissant

8

Edited_3057

9

#include <stdio.h> 
#include <stdlib.h> 
#include <stdint.h> 
#include <SDL.h> 

/* amusons nous à dessiner avec les nombres premiers! */
uint8_t isprime(uint32_t n) {
  for (uint32_t d=2;d*d<=n;d++)
    if(!(n%d))
      return 0;
  return 42;
}


/* oui c'est moche et lent */
void addPixelSat(SDL_Surface *s, int x, int y, Uint32 c) {
  Uint32 cc = *((Uint32*)(s->pixels) + x + y * s->w);
  Uint16 nr = (c >> 16)+(cc >> 16);
  Uint16 ng = (c >> 8)+(cc >> 8);
  Uint16 nb = (c & 255)+(cc & 255);
  if (nr > 255) nr = 255;
  if (ng > 255) ng = 255;
  if (nb > 255) nb = 255;
  *((Uint32*)(s->pixels) + x + y * s->w) = (nr<<16)|(ng<<8)|nb;
}


#define mulRGB_tmp(k,x,n) ((128+(((x)>>n)&255)*(k))>>8)<<n
#define mulRGB(k,x) (mulRGB_tmp(k,x,16) | mulRGB_tmp(k,x,8) | mulRGB_tmp(k,x,0))

int main(int argc,char *argv[]){ 
    SDL_Surface *screen;  
    SDL_Event event; 
    if(SDL_Init(SDL_INIT_VIDEO) == -1) 
        exit(1); 
    atexit(SDL_Quit);  
    screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE); 
    if (screen == NULL) 
        exit(1); 
    SDL_WM_SetCaption("Enjoy !", NULL); 

    /* youpi, ça bouge! */
    for (uint32_t n=0,z=160+320*120,c=0x123456; !SDL_PollEvent(&event) || event.type!=SDL_QUIT; n+=64*48,c=(c*189+123)%0xFF7821,z=c/42<320*240?c/42:z) {
        for (uint32_t x=0; x<64*48; x++)
            if (isprime(x+n)) {
                SDL_Rect r={z%320+x%64*5,z/320+x/64*5,5,5};
                SDL_FillRect(screen, &r, c);
            }

        /* il est flou afflelou */
        uint32_t *pix = screen->pixels;
        for (int *p=(int[]){1,-1,640,-640,1,-1,640,-640,0}; *p; p++)
            for (uint32_t x=0; x<640*480; x++)
                pix[x] = mulRGB(256-20,pix[x])+mulRGB(20,pix[(x+*p)%(640*480)]);

        SDL_Flip(screen);
    }

  return 0; 
}

(bon en fait c'est con j'ai pas besoin de addPixelSat dans mon flou puisque ça sature jamais ^^)

« The biggest civil liberty of all is not to be killed by a terrorist. » (Geoff Hoon, ministre des transports anglais)

10

#include <stdio.h> 
#include <stdlib.h> 
#include <stdint.h> 
#include <SDL.h> 

/* amusons nous à dessiner avec les nombres premiers! */
uint8_t isprime(uint32_t n) {
  for (uint32_t d=2;d*d<=n;d++)
    if(!(n%d))
      return 0;
  return 42;
}


/* oui c'est moche et lent */
void addPixelSat(SDL_Surface *s, int x, int y, Uint32 c) {
  Uint32 cc = *((Uint32*)(s->pixels) + x + y * s->w);
  Uint16 nr = (c >> 16)+(cc >> 16);
  Uint16 ng = (c >> 8)+(cc >> 8);
  Uint16 nb = (c & 255)+(cc & 255);
  if (nr > 255) nr = 255;
  if (ng > 255) ng = 255;
  if (nb > 255) nb = 255;
  *((Uint32*)(s->pixels) + x + y * s->w) = (nr<<16)|(ng<<8)|nb;
}


#define mulRGB_tmp(k,x,n) ((128+(((x)>>n)&255)*(k))>>8)<<n
#define mulRGB(k,x) (mulRGB_tmp(k,x,16) | mulRGB_tmp(k,x,8) | mulRGB_tmp(k,x,0))

int main(int argc,char *argv[]){ 
    SDL_Surface *screen;  
    SDL_Event event; 
    if(SDL_Init(SDL_INIT_VIDEO) == -1) 
        exit(1); 
    atexit(SDL_Quit);  
    screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE); 
    if (screen == NULL) 
        exit(1); 
    SDL_WM_SetCaption("Enjoy !", NULL); 

    /* youpi, ça bouge! */
    for (uint32_t n=0,z=160+320*120,c=0x123456; !SDL_PollEvent(&event) || event.type!=SDL_QUIT; n+=64*48,c=(c*189+123)%0xFF7821,z=c/42<320*240?c/42:z) {
        for (uint32_t x=0; x<64*48; x++)
            if (isprime(x+n)) {
                SDL_Rect r={z%320+x%64*5,z/320+x/64*5,5,5};
                SDL_FillRect(screen, &r, c);
            }

        /* il est flou afflelou */
        uint32_t *pix = screen->pixels;
        for (int *p=(int[]){1,-1,640,-640,1,-1,640,-640,0}; *p; p++)
            for (uint32_t x=0; x<640*480; x++)
                pix[x] = mulRGB(256-20,pix[x])+mulRGB(20,pix[(x+*p)%(640*480)]);

        SDL_Flip(screen);
    }

  return 0; 
}
/*Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Aenean volutpat lorem ut enim. Cras accumsan porta augue.
Nulla quis magna. Morbi at dolor. Vivamus quam. Fusce feugiat egestas elit.
Nullam tincidunt. Donec et felis.
Fusce purus dui, semper vitae, tincidunt nec, malesuada id, purus.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Etiam a risus nec tellus ultrices tempor. Nunc mauris velit, euismod vitae, hendrerit et, auctor eget, odio.
Praesent dapibus nulla. Nunc et nulla.
Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec lobortis rhoncus tortor*/

avatar
Webmaster du site Ti-FRv3 (et aussi de DevLynx)
Si moins de monde enculait le système, alors celui ci aurait plus de mal à nous sortir de si grosses merdes !
"L'erreur humaine est humaine"©Nil (2006) // topics/6238-moved-jamais-jaurais-pense-faire-ca

11

#include <stdio.h>  
#include <stdlib.h>  
#include <stdint.h>  
#include <SDL.h>  
 
/* amusons nous à dessiner avec les nombres premiers! */ 
uint8_t isprime(uint32_t n) { 
  for (uint32_t d=2;d*d<=n;d++) 
    if(!(n%d)) 
      return 0; 
  return 42; 
} 
 
 
/* oui c'est moche et lent */ 
void addPixelSat(SDL_Surface *s, int x, int y, Uint32 c) { 
  Uint32 cc = *((Uint32*)(s->pixels) + x + y * s->w); 
  Uint16 nr = (c >> 16)+(cc >> 16); 
  Uint16 ng = (c >> 8)+(cc >> 8); 
  Uint16 nb = (c & 255)+(cc & 255); 
  if (nr > 255) nr = 255; 
  if (ng > 255) ng = 255; 
  if (nb > 255) nb = 255; 
  *((Uint32*)(s->pixels) + x + y * s->w) = (nr<<16)|(ng<<8)|nb; 
} 

char *lipsum = 
"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. "
"Aenean volutpat lorem ut enim. Cras accumsan porta augue. "
"Nulla quis magna. Morbi at dolor. Vivamus quam. Fusce feugiat egestas elit. "
"Nullam tincidunt. Donec et felis. "
"Fusce purus dui, semper vitae, tincidunt nec, malesuada id, purus. "
"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. "
"Etiam a risus nec tellus ultrices tempor. Nunc mauris velit, euismod vitae, hendrerit et, auctor eget, odio. "
"Praesent dapibus nulla. Nunc et nulla. "
"Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec lobortis rhoncus tortor"
  ;

int font[26][11]={{7,24,36,66,126,66,66,66,0,0,0},{8,240,136,136,252,130,130,252,0,0,0},{8,28,98,128,128,128,64,62,0,0,0},
{8,240,136,132,130,130,130,252,0,0,0},{8,252,128,128,240,128,128,254,0,0,0},{6,62,32,32,60,32,32,32,0,0,0},
{8,60,66,128,142,130,66,60,0,0,0},{7,66,66,66,126,66,66,66,0,0,0},{2,2,2,2,2,2,2,2,0,0,0},{5,2,2,2,2,18,18,12,0,0,0},
{7,66,68,72,80,104,68,66,0,0,0},{5,16,16,16,16,16,16,30,0,0,0},{8,130,198,170,146,130,130,130,0,0,0},
{6,34,34,50,42,38,34,34,0,0,0},{7,24,36,66,66,66,66,60,0,0,0},{6,56,36,34,60,32,32,32,0,0,0},
{8,48,72,132,132,148,140,118,0,0,0},{7,112,72,68,120,72,68,66,0,0,0},{6,14,16,32,28,2,4,56,0,0,0},
{6,62,8,8,8,8,8,8,0,0,0},{5,18,18,18,18,18,18,12,0,0,0},{8,130,130,68,68,40,40,16,0,0,0},
{8,130,130,130,146,146,146,108,0,0,0},{8,130,68,40,16,40,68,130,0,0,0},{6,34,34,20,20,8,8,16,0,0,0},
{8,254,4,8,16,32,64,252,0,0,0}};
 
#define mulRGB_tmp(k,x,n) ((128+(((x)>>n)&255)*(k))>>8)<<n 
#define mulRGB(k,x) (mulRGB_tmp(k,x,16) | mulRGB_tmp(k,x,8) | mulRGB_tmp(k,x,0)) 
 
int main(int argc,char *argv[]){  
  SDL_Surface *screen;   
  SDL_Event event;  
  if(SDL_Init(SDL_INIT_VIDEO) == -1)  
    exit(1);  
  atexit(SDL_Quit);   
  screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);  
  if (screen == NULL)  
    exit(1);  
  SDL_WM_SetCaption("Enjoy !", NULL);  
 
  /* youpi, ça bouge! */ 
  for (uint32_t n=0,z=160+320*120,c=0x123456; !SDL_PollEvent(&event) 
|| event.type!=SDL_QUIT; n+=64*48,c=(c*189+123)%0xFF7821,z=c/42<320*240?c/42:z) { 
    for (uint32_t x=0; x<64*48; x++) 
      if (isprime(x+n)) { 
	SDL_Rect r={z%320+x%64*5,z/320+x/64*5,5,5}; 
	SDL_FillRect(screen, &r, c); 
      } 
 
    /* il est flou afflelou */ 
    uint32_t *pix = screen->pixels; 
    for (int *p=(int[]){1,-1,640,-640,1,-1,640,-640,0}; *p; p++) 
      for (uint32_t x=0; x<640*480; x++) 
	pix[x] = mulRGB(256-20,pix[x])+mulRGB(20,pix[(x+*p)%(640*480)]) | 0xFF000000; 
 
    SDL_Flip(screen); 
  } 
 
  return 0;  
} 


j'ai ajouté les règles d'édition, j'ai corrigé parce qu'il y a pas que des gens avec des fenêtres de 24 bits ici, alors j'avais des tâches à moitié transparentes sur fond transparent, c'était magnifique!

et j'avais pas assez de lignes pour une fonction d'affichage de chaines happy
(la fonte est en 8x10 et préfixée par la largeur du char en colonnes)
avatar
fabetal_ > Hier, je me suis fait monter par un pote
redangel > et en chevals, ça donne quoi?
Nil> OMG I think I'm gay

12

Edited_3058

13

Edited_3059

14

cf plus bas

15

#include <stdio.h>    
#include <stdlib.h>    
#include <stdint.h>    
#include <SDL.h>    
   
/* amusons nous à dessiner avec les nombres premiers! */   
uint8_t isprime(uint32_t n) {   
  for (uint32_t d=2;d*d<=n;d++)   
    if(!(n%d))   
      return 0;   
  return 42;   
}   
   
   
/* oui c'est moche et lent */   
void addPixelSat(SDL_Surface *s, int x, int y, Uint32 c) {   
  Uint32 cc = *((Uint32*)(s->pixels) + x + y * s->w);   
  Uint16 nr = (c >> 16)+(cc >> 16);   
  Uint16 ng = (c >> 8)+(cc >> 8);   
  Uint16 nb = (c & 255)+(cc & 255);   
  if (nr > 255) nr = 255;   
  if (ng > 255) ng = 255;   
  if (nb > 255) nb = 255;   
  *((Uint32*)(s->pixels) + x + y * s->w) = (nr<<16)|(ng<<8)|nb;   
}   
  
char *lipsum =   
"Lorem ipsum dolor sit amet, consectetuer adipiscing elit "  
"Aenean volutpat lorem ut enim. Cras accumsan porta augue "  
"Nulla quis magna. Morbi at dolor. Vivamus quam. Fusce feugiat egestas elit "  
"Nullam tincidunt. Donec et felis "  
"Fusce purus dui, semper vitae, tincidunt nec, malesuada id, purus "  
"Lorem ipsum dolor sit amet, consectetuer adipiscing elit "  
"Etiam a risus nec tellus ultrices tempor. Nunc mauris velit, euismod vitae, hendrerit et, auctor eget, odio "  
"Praesent dapibus nulla. Nunc et nulla   "  
"Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec lobortis rhoncus tortor   "
  ;  
  
int font[26][11]={{7,24,36,66,126,66,66,66,0,0,0},{8,240,136,136,252,130,130,252,0,0,0},{8,28,98,128,128,128,64,62,0,0,0},  
		  {8,240,136,132,130,130,130,252,0,0,0},{8,252,128,128,240,128,128,254,0,0,0},{6,62,32,32,60,32,32,32,0,0,0},  
		  {8,60,66,128,142,130,66,60,0,0,0},{7,66,66,66,126,66,66,66,0,0,0},{2,2,2,2,2,2,2,2,0,0,0},{5,2,2,2,2,18,18,12,0,0,0},  
		  {7,66,68,72,80,104,68,66,0,0,0},{5,16,16,16,16,16,16,30,0,0,0},{8,130,198,170,146,130,130,130,0,0,0},  
		  {6,34,34,50,42,38,34,34,0,0,0},{7,24,36,66,66,66,66,60,0,0,0},{6,56,36,34,60,32,32,32,0,0,0},  
		  {8,48,72,132,132,148,140,118,0,0,0},{7,112,72,68,120,72,68,66,0,0,0},{6,14,16,32,28,2,4,56,0,0,0},  
		  {6,62,8,8,8,8,8,8,0,0,0},{5,18,18,18,18,18,18,12,0,0,0},{8,130,130,68,68,40,40,16,0,0,0},  
		  {8,130,130,130,146,146,146,108,0,0,0},{8,130,68,40,16,40,68,130,0,0,0},{6,34,34,20,20,8,8,16,0,0,0},  
		  {8,254,4,8,16,32,64,252,0,0,0}};  
   
#define mulRGB_tmp(k,x,n) ((128+(((x)>>n)&255)*(k))>>8)<<n   
#define mulRGB(k,x) (mulRGB_tmp(k,x,16) | mulRGB_tmp(k,x,8) | mulRGB_tmp(k,x,0))   
   
int main(int argc,char *argv[]){    
  SDL_Surface *screen;     
  SDL_Event event;    
  if(SDL_Init(SDL_INIT_VIDEO) == -1)    
    exit(1);    
  atexit(SDL_Quit);     
  screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);    
  if (screen == NULL)    
    exit(1);    
  SDL_WM_SetCaption("Enjoy !", NULL);    
   
  /* youpi, ça bouge! */   
  for (uint32_t n=0,z=160+320*120,c=0x123456; !SDL_PollEvent(&event)   
	 || event.type!=SDL_QUIT; n+=64*48,c=(c*189+123)%0xFF7821,z=c/42<320*240?c/42:z) {   
    for (uint32_t x=0; x<64*48; x++)   
      if (isprime(x+n)) {   
	SDL_Rect r={z%320+x%64*5,z/320+x/64*5,5,5};   
	SDL_FillRect(screen, &r, c);   
      }   
   
    /* il est flou afflelou */   
    uint32_t *pix = (uint32_t *)screen->pixels;   
    int pp[] = {1,-1,640,-640,1,-1,640,-640,0}; 
    for (int *p = pp; *p; p++)   
      for (uint32_t x=0; x<640*480; x++) 
	pix[x] = mulRGB(256-20,pix[x])+mulRGB(20,pix[(x+*p)%(640*480)]) | 0xFF000000; 
     
    static int tpos = 0; 
    for (Uint16 l = 0; l < tpos; l++) { 
      char huhu = lipsum[l]; 
	if ((huhu = (huhu > 'Z') ? (huhu - 'a') : (huhu - 'A')) != ' '-'A')
	  for (Uint16 y = 1; y < 10; y++) 
	    for (Uint16 x = 0; x < 8; x++) 
	      if (font[huhu][y]&(1<<(7-x))) 
		addPixelSat(screen,  160 + (x+((l * 8)))%320,
			    120 + (y + ((l * 8) / 320) * 10)%240, 0xff); 
    }
    if(lipsum[tpos] == 0) tpos = 0;
   
    SDL_Flip(screen);   
  }   
   
  return 0;    
}


corrections et centrage du texte
avatar
fabetal_ > Hier, je me suis fait monter par un pote
redangel > et en chevals, ça donne quoi?
Nil> OMG I think I'm gay

16

ARG cross!

edit: on garde la mienne, tu n'as pas respecté les règles! tongue
avatar
fabetal_ > Hier, je me suis fait monter par un pote
redangel > et en chevals, ça donne quoi?
Nil> OMG I think I'm gay

17

Edited_3060

18

Orion_ :
heu BookeldOr >
if(huhu != ' ') << ça c'est pas utile
ma ligne d'en dessous sert a rien xD


ok, édité
avatar
fabetal_ > Hier, je me suis fait monter par un pote
redangel > et en chevals, ça donne quoi?
Nil> OMG I think I'm gay

19

m enfin pkoi j ai pas respecté les regles?
Bon je peux tout compressé en moins de 10 lignes mais je voulais faire aac de propre lol

20

#include <stdio.h>     
#include <stdlib.h>     
#include <stdint.h>     
#include <SDL.h>     
   
typedef struct{ 
	unsigned int uWidth; 
	unsigned int uHeight; 
	SDL_Surface *pData; 
} SBitMapFont;

SBitMapFont* LoadBitMapFontFromFile(char *pFileName) 
{ 
	SBitMapFont* pReturn = NULL; // To be continued #triso#
	return pReturn; 
}
 
/* amusons nous à dessiner avec les nombres premiers! */    
uint8_t isprime(uint32_t n) {    
  for (uint32_t d=2;d*d<=n;d++)    
    if(!(n%d))    
      return 0;    
  return 42;    
}    
    
    
/* oui c'est moche et lent */    
void addPixelSat(SDL_Surface *s, int x, int y, Uint32 c) {    
  Uint32 cc = *((Uint32*)(s->pixels) + x + y * s->w);    
  Uint16 nr = (c >> 16)+(cc >> 16);    
  Uint16 ng = (c >> 8)+(cc >> 8);    
  Uint16 nb = (c & 255)+(cc & 255);    
  if (nr > 255) nr = 255;    
  if (ng > 255) ng = 255;    
  if (nb > 255) nb = 255;    
  *((Uint32*)(s->pixels) + x + y * s->w) = (nr<<16)|(ng<<8)|nb;    
}    
   
char *lipsum =    
"Lorem ipsum dolor sit amet, consectetuer adipiscing elit "   
"Aenean volutpat lorem ut enim. Cras accumsan porta augue "   
"Nulla quis magna. Morbi at dolor. Vivamus quam. Fusce feugiat egestas elit "   
"Nullam tincidunt. Donec et felis "   
"Fusce purus dui, semper vitae, tincidunt nec, malesuada id, purus "   
"Lorem ipsum dolor sit amet, consectetuer adipiscing elit "   
"Etiam a risus nec tellus ultrices tempor. Nunc mauris velit, euismod vitae, hendrerit et, auctor eget, odio "   
"Praesent dapibus nulla. Nunc et nulla   "   
"Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec lobortis rhoncus tortor   " 
  ;   
   
int font[26][11]={{7,24,36,66,126,66,66,66,0,0,0},{8,240,136,136,252,130,130,252,0,0,0},{8,28,98,128,128,128,64,62,0,0,0},   
		  {8,240,136,132,130,130,130,252,0,0,0},{8,252,128,128,240,128,128,254,0,0,0},{6,62,32,32,60,32,32,32,0,0,0},   
		  {8,60,66,128,142,130,66,60,0,0,0},{7,66,66,66,126,66,66,66,0,0,0},{2,2,2,2,2,2,2,2,0,0,0},{5,2,2,2,2,18,18,12,0,0,0},   
		  {7,66,68,72,80,104,68,66,0,0,0},{5,16,16,16,16,16,16,30,0,0,0},{8,130,198,170,146,130,130,130,0,0,0},   
		  {6,34,34,50,42,38,34,34,0,0,0},{7,24,36,66,66,66,66,60,0,0,0},{6,56,36,34,60,32,32,32,0,0,0},   
		  {8,48,72,132,132,148,140,118,0,0,0},{7,112,72,68,120,72,68,66,0,0,0},{6,14,16,32,28,2,4,56,0,0,0},   
		  {6,62,8,8,8,8,8,8,0,0,0},{5,18,18,18,18,18,18,12,0,0,0},{8,130,130,68,68,40,40,16,0,0,0},   
		  {8,130,130,130,146,146,146,108,0,0,0},{8,130,68,40,16,40,68,130,0,0,0},{6,34,34,20,20,8,8,16,0,0,0},   
		  {8,254,4,8,16,32,64,252,0,0,0}};   
    
#define mulRGB_tmp(k,x,n) ((128+(((x)>>n)&255)*(k))>>8)<<n    
#define mulRGB(k,x) (mulRGB_tmp(k,x,16) | mulRGB_tmp(k,x,8) | mulRGB_tmp(k,x,0))    
    
int main(int argc,char *argv[]){     
  SDL_Surface *screen;      
  SDL_Event event;     
  if(SDL_Init(SDL_INIT_VIDEO) == -1)     
    exit(1);     
  atexit(SDL_Quit);      
  screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);     
  if (screen == NULL)     
    exit(1);     
  SDL_WM_SetCaption("Enjoy !", NULL);     
    
  /* youpi, ça bouge! */    
  for (uint32_t n=0,z=160+320*120,c=0x123456; !SDL_PollEvent(&event)    
	 || event.type!=SDL_QUIT; n+=64*48,c=(c*189+123)%0xFF7821,z=c/42<320*240?c/42:z) {    
    for (uint32_t x=0; x<64*48; x++)    
      if (isprime(x+n)) {    
	SDL_Rect r={z%320+x%64*5,z/320+x/64*5,5,5};    
	SDL_FillRect(screen, &r, c);    
      }    
    
    /* il est flou afflelou */    
    uint32_t *pix = (uint32_t *)screen->pixels;    
    int pp[] = {1,-1,640,-640,1,-1,640,-640,0};  
    for (int *p = pp; *p; p++)    
      for (uint32_t x=0; x<640*480; x++)  
	pix[x] = mulRGB(256-20,pix[x])+mulRGB(20,pix[(x+*p)%(640*480)]) | 0xFF000000;  
      
    static int tpos = 0;  
    for (Uint16 l = 0; l < tpos; l++) {  
      char huhu = lipsum[l];  
	if ((huhu = (huhu > 'Z') ? (huhu - 'a') : (huhu - 'A')) != ' '-'A') 
	  for (Uint16 y = 1; y < 10; y++)  
	    for (Uint16 x = 0; x < 8; x++)  
	      if (font[huhu][y]&(1<<(7-x)))  
		addPixelSat(screen,  160 + (x+((l * 8)))%320, 
			    120 + (y + ((l * 8) / 320) * 10)%240, 0xff);  
    } 
    if(lipsum[tpos] == 0) tpos = 0; 
    
    SDL_Flip(screen);    
  }    
    
  return 0;     
}

21

ben voilà grin
avatar
fabetal_ > Hier, je me suis fait monter par un pote
redangel > et en chevals, ça donne quoi?
Nil> OMG I think I'm gay

22

Edited_3061

23

#include <stdio.h>      
#include <stdlib.h>      
#include <stdint.h>      
#include <SDL.h>     
#include <math.h>  
    
typedef struct{  
	unsigned int uWidth;  
	unsigned int uHeight;  
	SDL_Surface *pData;  
} SBitMapFont; 
 
SBitMapFont* LoadBitMapFontFromFile(char *pFileName)  
{  
	SBitMapFont* pReturn = NULL;
	SDL_Surface *pTmpSurface; 
	 
	if((pTmpSurface = SDL_LoadBMP(pFileName)) 
		&& !(pReturn  = malloc(sizeof(SFont)))) 
	{ 
		pReturn->uWidth  = (unsigned int)pTmpSurface->w/255; 
		pReturn->uHeight = (unsigned int)pTmpSurface->h; 
		pReturn->pData   = pTmpSurface; 
	} 
	else 
		fprintf(stderr,"[Erreur ::LoadFontFromFile] : Can't load %s\n",pFileName); 
	return pReturn;  
} 
  
/* amusons nous à dessiner avec les nombres premiers! */     
uint8_t isprime(uint32_t n) {     
  for (uint32_t d=2;d*d<=n;d++)     
    if(!(n%d))     
      return 0;     
  return 42;     
} 
     
     
/* oui c'est moche et lent */     
void addPixelSat(SDL_Surface *s, int x, int y, Uint32 c) {     
  Uint32 cc = *((Uint32*)(s->pixels) + x + y * s->w);     
  Uint16 nr = (c >> 16)+(cc >> 16);     
  Uint16 ng = (c >> 8)+(cc >> 8);     
  Uint16 nb = (c & 255)+(cc & 255);     
  if (nr > 255) nr = 255;     
  if (ng > 255) ng = 255;     
  if (nb > 255) nb = 255;     
  *((Uint32*)(s->pixels) + x + y * s->w) = (nr<<16)|(ng<<8)|nb;     
} 
 
 
void line (SDL_Surface *s, float x1, float y1, float x2, float y2, Uint32 c) 
{  double hl=fabs(x2-x1), vl=fabs(y2-y1), length=(hl>vl)?hl:vl; 
   float deltax=(x2-x1)/(float)length, deltay=(y2-y1)/(float)length; 
   for (int i=0; i<(int)length; i++) 
     addPixelSat(s, (int)(x1+=deltax), (int)(y1+=deltay), c); 
} 
 
    
char *lipsum =     
"Lorem ipsum dolor sit amet, consectetuer adipiscing elit "    
"Aenean volutpat lorem ut enim. Cras accumsan porta augue "    
"Nulla quis magna. Morbi at dolor. Vivamus quam. Fusce feugiat egestas elit "    
"Nullam tincidunt. Donec et felis "    
"Fusce purus dui, semper vitae, tincidunt nec, malesuada id, purus "    
"Lorem ipsum dolor sit amet, consectetuer adipiscing elit "    
"Etiam a risus nec tellus ultrices tempor. Nunc mauris velit, euismod vitae, hendrerit et, auctor eget, odio "    
"Praesent dapibus nulla. Nunc et nulla   "    
"Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec lobortis rhoncus tortor   "  
  ;    
    
int font[26][11]={{7,24,36,66,126,66,66,66,0,0,0},{8,240,136,136,252,130,130,252,0,0,0},{8,28,98,128,128,128,64,62,0,0,0},    
		  {8,240,136,132,130,130,130,252,0,0,0},{8,252,128,128,240,128,128,254,0,0,0},{6,62,32,32,60,32,32,32,0,0,0},    
		  {8,60,66,128,142,130,66,60,0,0,0},{7,66,66,66,126,66,66,66,0,0,0},{2,2,2,2,2,2,2,2,0,0,0},{5,2,2,2,2,18,18,12,0,0,0},    
		  {7,66,68,72,80,104,68,66,0,0,0},{5,16,16,16,16,16,16,30,0,0,0},{8,130,198,170,146,130,130,130,0,0,0},    
		  {6,34,34,50,42,38,34,34,0,0,0},{7,24,36,66,66,66,66,60,0,0,0},{6,56,36,34,60,32,32,32,0,0,0},    
		  {8,48,72,132,132,148,140,118,0,0,0},{7,112,72,68,120,72,68,66,0,0,0},{6,14,16,32,28,2,4,56,0,0,0},    
		  {6,62,8,8,8,8,8,8,0,0,0},{5,18,18,18,18,18,18,12,0,0,0},{8,130,130,68,68,40,40,16,0,0,0},    
		  {8,130,130,130,146,146,146,108,0,0,0},{8,130,68,40,16,40,68,130,0,0,0},{6,34,34,20,20,8,8,16,0,0,0},    
		  {8,254,4,8,16,32,64,252,0,0,0}};    
     
#define mulRGB_tmp(k,x,n) ((128+(((x)>>n)&255)*(k))>>8)<<n     
#define mulRGB(k,x) (mulRGB_tmp(k,x,16) | mulRGB_tmp(k,x,8) | mulRGB_tmp(k,x,0))     
     
int main(int argc,char *argv[]){      
  SDL_Surface *screen;       
  SDL_Event event;      
  if(SDL_Init(SDL_INIT_VIDEO) == -1)      
    exit(1);      
  atexit(SDL_Quit);       
  screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);      
  if (screen == NULL)      
    exit(1);      
  SDL_WM_SetCaption("Enjoy !", NULL);      
     
  /* youpi, ça bouge! */     
  for (uint32_t n=0,z=160+320*120,c=0x123456; !SDL_PollEvent(&event)     
	 || event.type!=SDL_QUIT; n+=64*48,c=(c*189+123)%0xFF7821,z=c/42<320*240?c/42:z) {     
    for (uint32_t x=0; x<64*48; x++)     
      if (isprime(x+n)) {     
	SDL_Rect r={z%320+x%64*5,z/320+x/64*5,5,5};     
	SDL_FillRect(screen, &r, c);     
      }     
     
    /* il est flou afflelou */     
    uint32_t *pix = (uint32_t *)screen->pixels;     
    int pp[] = {1,-1,640,-640,1,-1,640,-640,0};   
    for (int *p = pp; *p; p++)     
      for (uint32_t x=0; x<640*480; x++)   
	pix[x] = mulRGB(256-20,pix[x])+mulRGB(20,pix[(x+*p)%(640*480)]) | 0xFF000000;   
       
    static int tpos = 0;   
    for (Uint16 l = 0; l < tpos; l++) {   
      char huhu = lipsum[l];   
	if ((huhu = (huhu > 'Z') ? (huhu - 'a') : (huhu - 'A')) != ' '-'A')  
	  for (Uint16 y = 1; y < 10; y++)   
	    for (Uint16 x = 0; x < 8; x++)   
	      if (font[huhu][y]&(1<<(7-x)))   
		addPixelSat(screen,  160 + (x+((l * 8)))%320,  
			    120 + (y + ((l * 8) / 320) * 10)%240, 0xff);   
    }  
    if(lipsum[++tpos] == 0) tpos = 0; 
 
    static float xs = 0.0, ys = 0.0; 
    line(screen, sin(xs+=0.1)*320+320, cos(ys+=0.14)*240+240, cos(xs)*320+320, sin(ys)*240+240,rand()); 
     
    SDL_Flip(screen);     
  }     
     
  return 0;      
}

J'y arriverai wink

24

Edited_3062

25

Ha ct pas précisé triso
Pas grave je modifirai pour utiliser des bitmap interne si vous voulez ( ou alors j abandonne lol) mais une routine correcte pour afficher du text avec fps ou tu text avec un rotor zoom ca pouvait etre drole. (en utilisant du blit)

26

// gcc -std=c99 -O2 -W cccs.c -lSDL -o cccs && ./cccs

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <SDL/SDL.h>
#include <math.h>

typedef struct{
    unsigned int uWidth;
    unsigned int uHeight;
    SDL_Surface *pData;
} SBitMapFont;

SBitMapFont* LoadBitMapFontFromFile(char *pFileName)
{
    SBitMapFont* pReturn = NULL;
    SDL_Surface *pTmpSurface;

    if((pTmpSurface = SDL_LoadBMP(pFileName))
	    && !(pReturn  = malloc(sizeof(SBitMapFont))))
    {
	pReturn->uWidth  = (unsigned int)pTmpSurface->w/255;
	pReturn->uHeight = (unsigned int)pTmpSurface->h;
	pReturn->pData   = pTmpSurface;
    }
    else
	fprintf(stderr,"[Erreur ::LoadFontFromFile] : Can't load %s\n",pFileName);
    return pReturn;
}

/* amusons nous à dessiner avec les nombres premiers! */
uint8_t isprime(uint32_t n) {
    for (uint32_t d=2;d*d<=n;d++)
	if(!(n%d))
	    return 0;
    return 42;
}


/* oui c'est moche et lent */
void addPixelSat(SDL_Surface *s, int x, int y, Uint32 c) {
    Uint32 cc = *((Uint32*)(s->pixels) + x + y * s->w);
    Uint16 nr = ((c >> 16) & 255)+((cc >> 16) & 255);
    Uint16 ng = ((c >> 8) & 255)+((cc >> 8) & 255);
    Uint16 nb = (c & 255)+(cc & 255);
    if (nr > 255) nr = 255;
    if (ng > 255) ng = 255;
    if (nb > 255) nb = 255;
    *((Uint32*)(s->pixels) + x + y * s->w) = (nr<<16)|(ng<<8)|nb;
}


void line (SDL_Surface *s, float x1, float y1, float x2, float y2, Uint32 c) {
    double hl=fabs(x2-x1), vl=fabs(y2-y1), length=(hl>vl)?hl:vl;
    float deltax=(x2-x1)/(float)length, deltay=(y2-y1)/(float)length;
    for (int i=0; i<(int)length; i++)
	addPixelSat(s, (int)(x1+=deltax), (int)(y1+=deltay), c);
}


char *lipsum =
"Lorem ipsum dolor sit amet, consectetuer adipiscing elit "
"Aenean volutpat lorem ut enim. Cras accumsan porta augue "
"Nulla quis magna. Morbi at dolor. Vivamus quam. Fusce feugiat egestas elit "
"Nullam tincidunt. Donec et felis "
"Fusce purus dui, semper vitae, tincidunt nec, malesuada id, purus "
"Lorem ipsum dolor sit amet, consectetuer adipiscing elit "
"Etiam a risus nec tellus ultrices tempor. Nunc mauris velit, euismod vitae, hendrerit et, auctor eget, odio "
"Praesent dapibus nulla. Nunc et nulla   "
"Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec lobortis rhoncus tortor   "
;

int font[26][11]={{7,24,36,66,126,66,66,66,0,0,0},{8,240,136,136,252,130,130,252,0,0,0},{8,28,98,128,128,128,64,62,0,0,0},
    {8,240,136,132,130,130,130,252,0,0,0},{8,252,128,128,240,128,128,254,0,0,0},{6,62,32,32,60,32,32,32,0,0,0},
    {8,60,66,128,142,130,66,60,0,0,0},{7,66,66,66,126,66,66,66,0,0,0},{2,2,2,2,2,2,2,2,0,0,0},{5,2,2,2,2,18,18,12,0,0,0},
    {7,66,68,72,80,104,68,66,0,0,0},{5,16,16,16,16,16,16,30,0,0,0},{8,130,198,170,146,130,130,130,0,0,0},
    {6,34,34,50,42,38,34,34,0,0,0},{7,24,36,66,66,66,66,60,0,0,0},{6,56,36,34,60,32,32,32,0,0,0},
    {8,48,72,132,132,148,140,118,0,0,0},{7,112,72,68,120,72,68,66,0,0,0},{6,14,16,32,28,2,4,56,0,0,0},
    {6,62,8,8,8,8,8,8,0,0,0},{5,18,18,18,18,18,18,12,0,0,0},{8,130,130,68,68,40,40,16,0,0,0},
    {8,130,130,130,146,146,146,108,0,0,0},{8,130,68,40,16,40,68,130,0,0,0},{6,34,34,20,20,8,8,16,0,0,0},
    {8,254,4,8,16,32,64,252,0,0,0}};

#define mulRGB_tmp(k,x,n) ((128+(((x)>>n)&255)*(k))>>8)<<n
inline uint32_t mulRGB(int k,uint32_t x) { return mulRGB_tmp(k,x,16) | mulRGB_tmp(k,x,8) | mulRGB_tmp(k,x,0); }

int main(int argc,char *argv[]){
    SDL_Surface *screen;
    SDL_Event event;
    if(SDL_Init(SDL_INIT_VIDEO) == -1)
	exit(1);
    atexit(SDL_Quit);
    screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);
    if (screen == NULL)
	exit(1);
    SDL_WM_SetCaption("Enjoy !", NULL);

    /* youpi, ça bouge! */
    for (uint32_t n=0,z=160+320*120,c=0x123456; !SDL_PollEvent(&event)
	    || event.type!=SDL_QUIT; n+=64*48,c=(c*189+123)%0xFF7821,z=c/21<320*240?c/21:z) {
	for (uint32_t x=0; x<64*48; x++)
	    if (isprime(x+n)) {
		SDL_Rect r={z%320+x%64*5,z/320+x/64*5,5,5};
		SDL_FillRect(screen, &r, c);
	    }

	/* il est flou afflelou */
	uint32_t *pix = (uint32_t *)screen->pixels;
	int pp[] = {1,640*480-1,640,640*480-640,1,640*480-1,640,640*480-640,0};
	for (int *p = pp; *p; p++) {
	    uint32_t x=0,y=*p;
	    for (; y<640*480; x++,y++)
		pix[x] = pix[x]-((pix[x]>>4)&0x0F0F0F)+((pix[y]>>4)&0x0F0F0F);
	    for (y=0; x<640*480; x++,y++)
		pix[x] = pix[x]-((pix[x]>>4)&0x0F0F0F)+((pix[y]>>4)&0x0F0F0F);
	}

	static int tpos = 0;
	for (Uint16 l = 0; l < tpos; l++) {
	    char huhu = lipsum[l];
	    if ((huhu = (huhu > 'Z') ? (huhu - 'a') : (huhu - 'A')) != ' '-'A')
	       for (Uint16 y = 1; y < 10; y++)
		   for (Uint16 x = 0; x < 8; x++)
		       if (font[huhu][y]&(1<<(7-x)))
			   addPixelSat(screen,  160 + (x+((l * 8)))%320,
				   120 + (y + ((l * 8) / 320) * 10)%240, 0xffffff);
	}
	if(lipsum[++tpos] == 0) tpos = 0;

	static float xs = 0.0, ys = 0.0;
	line(screen, sin(xs+=0.1)*320+320, cos(ys+=0.07)*240+240, cos(xs)*320+320, sin(ys)*240+240,rand());

	SDL_Flip(screen);
	SDL_Delay(20);
    }

    return 0;
}


EDIT : résumé : optimisation du flou, correction d'un bug de addPixelSat ^^

« The biggest civil liberty of all is not to be killed by a terrorist. » (Geoff Hoon, ministre des transports anglais)

27

Orion_ :
heu ché moi ça "for (int *p=(int[]){1,-1,640,-640,1,-1,640,-640,0}; *p; p++) " ça compile pas du tout :/
"initializer for scalar variable requires one element "
j'utilise devcpp

Euh, c'est que tu dois pas être en C99 alors confus Ou alors tu utilises un vieux GCC ?

« The biggest civil liberty of all is not to be killed by a terrorist. » (Geoff Hoon, ministre des transports anglais)

28

Edited_3063

29

Ben il faut mettre en .c et rajouter l'option de GCC "-std=c99" ^^

« The biggest civil liberty of all is not to be killed by a terrorist. » (Geoff Hoon, ministre des transports anglais)

30

Si quelqu'un pouvait poster un screenshot du résultat, ce serai super!
J'ai pas de compilateur sous la main...et de toute facon ce PC est beaucoup trop
restreint pour y faire quoi que ce soit!
Merci!