Advertisement
prjbrook

BMPDots7.cpp

Jan 31st, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.68 KB | None | 0 0
  1. //BMPDots7 makes a BMP of last digit of all randoms up to 1M. Plus does similar to program generated random numbers' last digit.
  2. // Gives two BMPs. One for last digit of prmes, other for random 1,3,7,9. Hard to tell the difference.
  3. //To do: Create file of 1,3,7,9 from rand(). Read file in a place relevant dot on BMP.
  4.  
  5. #include "EasyBMP.h"
  6. #include<stdlib.h>
  7. #include<conio.h>
  8. using namespace std;
  9. int main( int argc, char* argv[] )
  10. {
  11.      
  12.         BMP PrimePic0;
  13.         PrimePic0.SetSize(640,480);
  14.         PrimePic0.SetBitDepth(8);
  15.  
  16.         int xxcount3 = 0;
  17.         int ones2=0;
  18.         int threes2=0; int sevens2=0; int nines2=0; long nonPrimes2 = 0; long allLines=0;
  19.         FILE *ptr_file;
  20.         char buf[1000];
  21.            
  22.         ptr_file =fopen("upTo1GlastNum3.txt","r");         
  23.         int h=0; int k=0;
  24.         while ((fgets(buf,1000, ptr_file)!=NULL) && (k<480)){
  25.                
  26.             allLines++;
  27.             switch (buf[0]) {
  28.  
  29.                 case '1':
  30.                     PrimePic0(h,k)->Red = 255;
  31.                     PrimePic0(h,k)->Green = 255;
  32.                     PrimePic0(h,k)->Blue = 0;
  33.                     ones2++;
  34.                     break;
  35.                 case '3':
  36.                     PrimePic0(h,k)->Red = 255;
  37.                     PrimePic0(h,k)->Green = 0;
  38.                     PrimePic0(h,k)->Blue = 0;
  39.                     threes2++;
  40.                     break;
  41.                 case '7':
  42.                     PrimePic0(h,k)->Red = 0;
  43.                     PrimePic0(h,k)->Green = 255;
  44.                     PrimePic0(h,k)->Blue = 0;
  45.                     sevens2++;
  46.                     break;
  47.                 case '9':
  48.                     PrimePic0(h,k)->Red = 0;
  49.                     PrimePic0(h,k)->Green = 0;
  50.                     PrimePic0(h,k)->Blue = 255;
  51.                     nines2++;
  52.                     break;
  53.                 default:
  54.                     cout << "Not prime" << allLines <<endl;
  55.                     nonPrimes2++;
  56.                     printf("Non prime");
  57.             }
  58.             h++;
  59.             if (h==640) {
  60.                     h=0;
  61.                     k++;
  62.             }  
  63.         }
  64.         fclose(ptr_file);
  65.         PrimePic0.WriteToFile("prime0Pic.bmp");
  66.    
  67. //Now do case where 1,3,7,9 are generated by random numbers via c-rand().  
  68.         BMP AnImage;
  69.         AnImage.SetSize(640,480);
  70.         AnImage.SetBitDepth(8);
  71.         cout << "File info:" << endl;
  72.         cout << AnImage.TellWidth() << " x " << AnImage.TellHeight() << " at " << AnImage.TellBitDepth() << " bpp" << endl;
  73.         cout << "colors: " << AnImage.TellNumberOfColors() << endl;
  74.         cout << "(" << (int) AnImage(14,18)->Red << "," << (int) AnImage(14,18)->Green << "," << (int) AnImage(14,18)->Blue << "," << (int) AnImage(14,18)->Alpha << ")" << endl;
  75.  
  76.  
  77.         int randDigit,i,j,ones,threes,sevens,nines;
  78.         long nonPrimes=0;
  79.         long allNums = 0;
  80.         j=0; ones=threes=sevens=nines=0; i=0;
  81.  
  82.         while (j<480)
  83.         {
  84.             randDigit = rand()%10;
  85.             allNums++;
  86.             switch (randDigit)
  87.             {
  88.                 case 1:
  89.                     AnImage(i,j)->Red = 255;
  90.                     AnImage(i,j)->Green = 255;
  91.                     AnImage(i,j)->Blue = 0;
  92.                     ones++;
  93.                     break;
  94.                 case 3:
  95.                     AnImage(i,j)->Red = 255;
  96.                     AnImage(i,j)->Green = 0;
  97.                     AnImage(i,j)->Blue = 0;
  98.                     threes++;
  99.                     break;
  100.                 case 7:
  101.                     AnImage(i,j)->Red = 0;
  102.                     AnImage(i,j)->Green = 255;
  103.                     AnImage(i,j)->Blue = 0;
  104.                     sevens++;
  105.                     break;
  106.                 case 9:
  107.                     AnImage(i,j)->Red = 0;
  108.                     AnImage(i,j)->Green = 0;
  109.                     AnImage(i,j)->Blue = 255;
  110.                     nines++;
  111.                     break;
  112.                 default:
  113.                     nonPrimes++;
  114.                     i--;
  115.             }
  116.             i++;
  117.             if (i==640) {
  118.                 i=0;
  119.                 j++;
  120.             }
  121.         }
  122.    
  123.         AnImage.WriteToFile("copied1dots3.bmp");
  124.         cout << "Non primes= " << nonPrimes << endl;
  125.         cout << "Ones =" << ones;
  126.         cout << "  Threes =" << threes;
  127.         cout << "  Sevens =" << sevens;
  128.         cout << "  Nines =" << nines << endl;
  129.         cout << "  xxcount3 " << xxcount3 << endl;
  130.         cout << "  allNums " << allNums << endl;
  131.         cout << "  ones2 " << ones2 << endl;
  132.         cout << "  Threes2 =" << threes2;
  133.         cout << "  Sevens2 =" << sevens2;
  134.         cout << "  Nines2 =" << nines2 << endl;
  135.         cout << "Non primes2 = " << nonPrimes2 << endl;
  136.         cout << "allLines = " << allLines << endl;
  137.         cout << "Sum of primes = " << ones2+threes2+sevens2+nines2 << endl;
  138.  return 0;
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement