1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
// Directives:
#include <iostream>
#include <cstdlib>
#include <graphics.h>
#include <cmath>
using namespace std;
// Named constants:
const int S = 500; // Width and height of graphics window
// Prototypes:
void draw_triangle(int x, int y, int d, double theta);
// Function definitions:
int main()
{
// 1. Initialize the graphics window:
initwindow(S, S, "Canis Major", 0, 0, true);
while(shift < 0.8*S)
{
shift = 30*t; // Calculations
clearviewport(); // Clear screen
swapbuffers(); // Swap buffers
}
// 2. Draw triangles:
draw_triangle(int(S*3/5), int(S*1/5), int(.056*S), double(M_PI/2));
draw_triangle(int(S*1/3), int(S*5/6), int(.048*S), double(M_PI/2));
draw_triangle(int(S*9/10), int(S*3/10), int(.04*S), double(M_PI/2));
draw_triangle(int(S*2/9), int(S*9/12), int(.032*S), double(M_PI/2));
draw_triangle(int(S*1/15), int(S*8/9), int(.024*S), double(M_PI/2));
// Draw upside-down triangles
draw_triangle(int(S*3/5), int(S*1/5), int(.056*S), double(-M_PI/2));
draw_triangle(int(S*1/3), int(S*5/6), int(.048*S), double(-M_PI/2));
draw_triangle(int(S*9/10), int(S*3/10), int(.04*S), double(-M_PI/2));
draw_triangle(int(S*2/9), int(S*9/12), int(.032*S), double(-M_PI/2));
draw_triangle(int(S*1/15), int(S*8/9), int(.024*S), double(-M_PI/2));
// 3. Finish:
delay(20000);
return EXIT_SUCCESS;
}
//------------------------------------------------------------------------------
void draw_triangle(int x, int y, int d, double theta)
{
int x1 = int(x + d * cos(theta));
int x2 = int(x + d * cos(theta - 2* M_PI / 3));
int x3 = int(x + d * cos(theta + 2* M_PI / 3));
int y1 = int(y - d * sin(theta));
int y2 = int(y - d * sin(theta - 2* M_PI / 3));
int y3 = int(y - d * sin(theta + 2* M_PI / 3));
line(x1, y1, x2, y2);
line(x2, y2, x3, y3);
line(x3, y3, x1, y1);
}
|