Programming and Graphics

(Kiana) #1

208 Introduction to C++ Programming and Graphics


/*---------------------------------
Animation of a rotating polygon
using VOGLE
---------------------------------*/

#include<iostream>
#include<cmath>
#include "VOGLE/voglec++.h"
using namespace std;

int main()
{
//--- Window plotting limits:

float xmin=0.0; float xmax=1.0; // plotting limits
float ymin=0.0; float ymax=1.0;
float xmarg = 0.2*(xmax-xmin); // plotting margins
float ymarg = 0.2*(ymax-ymin);

//--- Polygon variables:

const intn=5;//number of vertices
float points[n][2]; // plotting array
float omega = 0.1; // angular velocity
float t=0; // time
float Dt = 0.01; // time step
float xcrot = 0.5; // rotation center
float ycrot = 0.5; // rotation center

//--- Initial polygon vertices:

float x[n] ={0.80, 0.90, 0.90, 0.80, 0.80};
float y[n] ={0.50, 0.50, 0.88, 0.88, 0.50};

//--- Prepare the graphics:

prefposition (500,100); // window position
prefsize (300, 300); // window size
char device[]="X11"; // initialize on the screen
vinit(device);

//--- Define the plotting units

ortho2 (xmin-xmarg, xmax+xmarg, ymin-ymarg, ymax+ymarg);

//--- Polygon plotting option:

bool fill = true; // fill the polygon
polyfill (fill);
Free download pdf