C++ Programming: 1) Orbit 1 Using GraphX, write a simple program that will displ
ID: 3575277 • Letter: C
Question
C++ Programming:
1) Orbit 1 Using GraphX, write a simple program that will display an "orbiting" circle animation. The computational approach is straightforward: Given an angular measurement theta (in degrees) and a fixed radius value r, construct a simple loop that will continuously increment the angular value from 0 through 360 degrees and plot a filled-circle at the x,y coordinates given by the polar coordinates (theta, r). This should continue until some mouse event takes place to terminate the loop.
Your program should perform the following GraphX operations:
• Instantiate a GraphX object
• Change the units scale of the GraphX window to 400x400 by invoking the following GraphX method:
.scale(400,400)
•Set the plotting symbol to "solidcircle" using the .symbol method
•Set the symbolsize to 30 pixels
•Set the pencolor to some color other than black or white
•Implement a while loop that will continue running until the GraphX input is something other than "none"
•The loop should compute the x,y coordinates of the orbiting circle and plot it relative to the center of the window (e.g., x + 200, y + 200), then increase the value of the angle theta by 1 degree (mod 360) and repeat the process.
•In order to animate the orbiting circle, immediately after plotting the filled circle, set the drawing delay to .02 seconds and then .erase() the circle you just plotted. (The delay will cause the circle to show for a brief time before plotting the next circle). The effect should be the filled circle orbiting the window center.
[ Hint: the polar coordinate conversion must use the cmath functions cos and sin which require the angle in radians ]
This is GraphX.hpp (you can simply copy and paste it to C++ and make a cpp orbiting program which includes this hpp file):
Explanation / Answer
//main.cpp
#include <iostream>
#include "GraphX.hpp"
#include <cmath>
int main(){
int theta=0;
double radius=100;
double x,y;
GraphX graph;
graph.scale(400,400);
graph.symbol("solidcircle");
graph.symbolsize(30);
graph.pencolor("black");
//graph.pensize(12);
bool done = false;
while(!done)
{
string input =graph.input();
if (input == "rightbutton")
done = false;
if (input == "leftbutton")
done = true;
theta=theta%360;
theta++;
x=cos(theta)*radius+200;
y=sin(theta)*radius+200;
graph.setpos(x,y);
graph.plot();
graph.delay(0.02);
graph.erase();
}
return 0;
}
=========================================================================
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.