Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <math.h>
- #include <time.h>
- #include "class_complex.h"
- #define X_MIN -2
- #define X_MAX 2.1
- #define Y_MIN -1.6
- #define Y_MAX 2
- #define ZOOM 80
- #define ITERATIONS 50
- #define IMAGE_X (X_MAX - X_MIN) * ZOOM
- #define IMAGE_Y (Y_MAX - Y_MIN) * ZOOM
- using namespace std;
- int rand_int_a_b(int a, int b)
- {
- return rand()%(b-a) +a;
- }
- static int revertedScreen = 0;
- inline void setPixel(int x, int y, int r, int g, int b) {
- if(revertedScreen)
- x = 319-x, y = 239-y;
- if(is_cx) { /* Inverted color for CX since it is ugly and sharpen */
- unsigned short* p = (unsigned short*)(SCREEN_BASE_ADDRESS + (x << 1) + (y << 9) + (y << 7));
- *p = (((255-r) >> 3) << 11) | (((255-g) >> 2) << 5) | ((255-b) >> 3);
- }
- else {
- unsigned char* p = (unsigned char*)(SCREEN_BASE_ADDRESS + ((x >> 1) + (y << 7) + (y << 5)));
- char c = (r>>4)/3 + (g>>4)/3 + (b>>4)/3;
- *p = (x & 1) ? ((*p & 0xF0) | c) : ((*p & 0x0F) | (c << 4));
- }
- }
- void fillRect(int x1, int y1, int x2, int y2, int c) {
- for(; x1 < x2; ++x1)
- for(; y1 < y2; ++y1)
- setPixel(x1, y1, c, c, c);
- }
- int main()
- {
- srand(time(NULL));
- int R,G,B;
- int x, y, i;
- int re, im;
- bool reMustBeZero = false;
- bool imMustBeZero = false;
- while (true)
- {
- R = rand_int_a_b(5,30);
- G = rand_int_a_b(5,30);
- B = rand_int_a_b(5,30);
- re = reMustBeZero?0:rand_int_a_b(-25000,25000);
- im = imMustBeZero?0:rand_int_a_b(-25000,25000);
- complex C(((double)re/10000), ((double)im/10000));
- x = 0;
- i = 0;
- while (x < IMAGE_X)
- {
- y = 0;
- while (y < IMAGE_Y)
- {
- complex z((double)x / ZOOM + X_MIN,(double)y / ZOOM + Y_MIN);
- i = 0;
- do
- {
- z = z*z + C;
- i++;
- }
- while (z.norm() < 100 && i < ITERATIONS);
- if ((x>0 && x<=320) && (y>0 && y<=240))
- i==ITERATIONS?setPixel(x-1,y-1, 0, 0, 0):setPixel(x-1, y-1, (int)(R*i)%256,(int)(G*i)%256,(int)(B*i)%256);
- y++;
- }
- x++;
- }
- bool end = false;
- imMustBeZero = false;
- reMustBeZero = false;
- while (!end)
- {
- if (isKeyPressed(KEY_NSPIRE_RIGHT))
- {
- end = true;
- }
- else if (isKeyPressed(KEY_NSPIRE_ESC))
- {
- return 0;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement