Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //BMPDots7 makes a BMP of last digit of all randoms up to 1M. Plus does similar to program generated random numbers' last digit.
- // Gives two BMPs. One for last digit of prmes, other for random 1,3,7,9. Hard to tell the difference.
- //To do: Create file of 1,3,7,9 from rand(). Read file in a place relevant dot on BMP.
- #include "EasyBMP.h"
- #include<stdlib.h>
- #include<conio.h>
- using namespace std;
- int main( int argc, char* argv[] )
- {
- BMP PrimePic0;
- PrimePic0.SetSize(640,480);
- PrimePic0.SetBitDepth(8);
- int xxcount3 = 0;
- int ones2=0;
- int threes2=0; int sevens2=0; int nines2=0; long nonPrimes2 = 0; long allLines=0;
- FILE *ptr_file;
- char buf[1000];
- ptr_file =fopen("upTo1GlastNum3.txt","r");
- int h=0; int k=0;
- while ((fgets(buf,1000, ptr_file)!=NULL) && (k<480)){
- allLines++;
- switch (buf[0]) {
- case '1':
- PrimePic0(h,k)->Red = 255;
- PrimePic0(h,k)->Green = 255;
- PrimePic0(h,k)->Blue = 0;
- ones2++;
- break;
- case '3':
- PrimePic0(h,k)->Red = 255;
- PrimePic0(h,k)->Green = 0;
- PrimePic0(h,k)->Blue = 0;
- threes2++;
- break;
- case '7':
- PrimePic0(h,k)->Red = 0;
- PrimePic0(h,k)->Green = 255;
- PrimePic0(h,k)->Blue = 0;
- sevens2++;
- break;
- case '9':
- PrimePic0(h,k)->Red = 0;
- PrimePic0(h,k)->Green = 0;
- PrimePic0(h,k)->Blue = 255;
- nines2++;
- break;
- default:
- cout << "Not prime" << allLines <<endl;
- nonPrimes2++;
- printf("Non prime");
- }
- h++;
- if (h==640) {
- h=0;
- k++;
- }
- }
- fclose(ptr_file);
- PrimePic0.WriteToFile("prime0Pic.bmp");
- //Now do case where 1,3,7,9 are generated by random numbers via c-rand().
- BMP AnImage;
- AnImage.SetSize(640,480);
- AnImage.SetBitDepth(8);
- cout << "File info:" << endl;
- cout << AnImage.TellWidth() << " x " << AnImage.TellHeight() << " at " << AnImage.TellBitDepth() << " bpp" << endl;
- cout << "colors: " << AnImage.TellNumberOfColors() << endl;
- cout << "(" << (int) AnImage(14,18)->Red << "," << (int) AnImage(14,18)->Green << "," << (int) AnImage(14,18)->Blue << "," << (int) AnImage(14,18)->Alpha << ")" << endl;
- int randDigit,i,j,ones,threes,sevens,nines;
- long nonPrimes=0;
- long allNums = 0;
- j=0; ones=threes=sevens=nines=0; i=0;
- while (j<480)
- {
- randDigit = rand()%10;
- allNums++;
- switch (randDigit)
- {
- case 1:
- AnImage(i,j)->Red = 255;
- AnImage(i,j)->Green = 255;
- AnImage(i,j)->Blue = 0;
- ones++;
- break;
- case 3:
- AnImage(i,j)->Red = 255;
- AnImage(i,j)->Green = 0;
- AnImage(i,j)->Blue = 0;
- threes++;
- break;
- case 7:
- AnImage(i,j)->Red = 0;
- AnImage(i,j)->Green = 255;
- AnImage(i,j)->Blue = 0;
- sevens++;
- break;
- case 9:
- AnImage(i,j)->Red = 0;
- AnImage(i,j)->Green = 0;
- AnImage(i,j)->Blue = 255;
- nines++;
- break;
- default:
- nonPrimes++;
- i--;
- }
- i++;
- if (i==640) {
- i=0;
- j++;
- }
- }
- AnImage.WriteToFile("copied1dots3.bmp");
- cout << "Non primes= " << nonPrimes << endl;
- cout << "Ones =" << ones;
- cout << " Threes =" << threes;
- cout << " Sevens =" << sevens;
- cout << " Nines =" << nines << endl;
- cout << " xxcount3 " << xxcount3 << endl;
- cout << " allNums " << allNums << endl;
- cout << " ones2 " << ones2 << endl;
- cout << " Threes2 =" << threes2;
- cout << " Sevens2 =" << sevens2;
- cout << " Nines2 =" << nines2 << endl;
- cout << "Non primes2 = " << nonPrimes2 << endl;
- cout << "allLines = " << allLines << endl;
- cout << "Sum of primes = " << ones2+threes2+sevens2+nines2 << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement