Skip to content

Instantly share code, notes, and snippets.

@hpwit
Created May 13, 2018 09:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hpwit/e8d98c75b11872715fb8e495514891d1 to your computer and use it in GitHub Desktop.
Save hpwit/e8d98c75b11872715fb8e495514891d1 to your computer and use it in GitHub Desktop.
turn a picture around
//this is may pacman
int pacmab[256]={
9,9,9,9,9,9,9,9,
9,1,1,1,9,9,9,9,
1,1,1,1,1,9,9,9,
1,1,1,1,1,9,9,9,
1,1,1,1,1,9,9,9,
9,1,1,1,9,9,9,9,
9,9,9,9,9,9,9,9,
9,9,9,9,9,9,9,9,
9,9,9,9,9,9,9,9,
9,1,1,1,9,9,9,9,
1,1,1,1,1,9,9,9,
9,9,1,1,1,9,9,9,
1,1,1,1,1,9,9,9,
9,1,1,1,9,9,9,9,
9,9,9,9,9,9,9,9,
9,9,9,9,9,9,9,9,
9,9,9,9,9,9,9,9,
9,1,1,1,9,9,9,9,
9,9,1,1,1,9,9,9,
9,9,9,1,1,9,9,9,
9,9,1,1,1,9,9,9,
9,1,1,1,9,9,9,9,
9,9,9,9,9,9,9,9,
9,9,9,9,9,9,9,9,
9,9,9,9,9,9,9,9,
9,1,1,1,9,9,9,9,
1,1,1,1,1,9,9,9,
9,9,1,1,1,9,9,9,
1,1,1,1,1,9,9,9,
9,1,1,1,9,9,9,9,
9,9,9,9,9,9,9,9,
9,9,9,9,9,9,9,9,
};
void displaygifdir( CRGB *pica, long int x0, long int y0, long int h, long int w,long pic,int direc)
{
//pic is a number that allow me to select the picture i want i store all pacman faces in the same array
//direct is an number to decide in wich direction to turn the image
CRGB *bitmapRGB =(CRGB*)malloc(w*h*sizeof(CRGB)) ;
if(bitmapRGB==NULL)
{
Serial.println("immossibnle de créer l'image");
return;
}
memcpy ( bitmapRGB, pica+(h*w*pic), h*w*sizeof(CRGB) );
//Serial.println((h*w*pic)*sizeof(CRGB));
switch(direc){
case 1:
for(int i=0 ;i<h;i++)
{
for(int j=0;j<int(w/2);j++)
{
CRGB dd=bitmapRGB[i*w+j];
bitmapRGB[i*w+j]=bitmapRGB[i*w+(w-1-j)];
bitmapRGB[i*w+(w-j-1)]=dd;
}
}
break;
case 2:
//Symetrie diagoonale
for(int i=0 ;i<=h-1;i++)
{
for(int j=i+1;j<w;j++)
{
CRGB dd=bitmapRGB[i*w+j];
bitmapRGB[i*w+j]=bitmapRGB[j*w+i];
bitmapRGB[j*w+i]=dd;
}
}
//sympetrie horizonatle
for(int i=0 ;i<int(h/2);i++)
{
for(int j=0;j<w;j++)
{
CRGB dd=bitmapRGB[i*w+j];
bitmapRGB[i*w+j]=bitmapRGB[(h-1-i)*w+j];
bitmapRGB[(h-1-i)*w+j]=dd;
}
}
break;
case 4:
for(int i=0 ;i<h;i++)
{
for(int j=0;j<int(w/2);j++)
{
CRGB dd=bitmapRGB[i*w+j];
bitmapRGB[i*w+j]=bitmapRGB[i*w+(w-1-j)];
bitmapRGB[i*w+(w-j-1)]=dd;
}
}
//Symetrie diagoonale
for(int i=0 ;i<=h-1;i++)
{
for(int j=i+1;j<w;j++)
{
CRGB dd=bitmapRGB[i*w+j];
bitmapRGB[i*w+j]=bitmapRGB[j*w+i];
bitmapRGB[j*w+i]=dd;
}
}
//sympetrie horizonatle
for(int i=0 ;i<int(h/2);i++)
{
for(int j=0;j<w;j++)
{
CRGB dd=bitmapRGB[i*w+j];
bitmapRGB[i*w+j]=bitmapRGB[(h-1-i)*w+j];
bitmapRGB[(h-1-i)*w+j]=dd;
}
}
break;
}
displayPicNew( bitmapRGB, x0, y0, h, w); //here replace with your function to display
free(bitmapRGB);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment