Помощь в написании студенческих работ
Антистрессовый сервис

Опис інтерфейсу користувача

РефератПомощь в написанииУзнать стоимостьмоей работы

Body (float size, float mass, short type, QPointF position, QPointF speed, bool physics, Body *parent = NULL); P. drawText (QPoint (0, ui→centralWidget→height () — 1), QString (QString:number (forceMod)+" x")); P. fillRect (QRect (0, 0, ui→centralWidget→width (), ui→centralWidget→height ()), Qt: black); NewBody = new Body (0.5, mercuryMass, 3, QPointF (393, 300), QPointF (0, -0.39), true… Читать ещё >

Опис інтерфейсу користувача (реферат, курсовая, диплом, контрольная)

До складових частин користувацького інтерфейсу, окрім графічного вікна, входять спеціальні функції, реалізовані методом сигналів та слотів.

На момент запуску програми перед користувачем три клавіші: «+», «-» та «Stop». програмний інтерфейс сонячний Перші дві відповідають за регулювання швидкості, остання — таймера.

Головне вікно програми.

Рис. 3 — Головне вікно програми

Наряду з функціональнами елементами у інтерфейсі присутні і інформативні.

Це строки у лівому верхньому на нижньому кутках. У першій міститься число кадрів на секунду, що дозволяє оцінити швидкодію програми, а другій — стан швидкості для регуляції.

Висновки

Працюючи над даним проектом я поглибив власні знання у області техніки та логіки написання коду, отримав досвід роботи у середовищі Qt. Досягнення позитивного результату стало можливим завдяки освоєнню основ алгоритмізації і роботи з ПЗ загалом.

Інтегруючи різноаспектні знання, я вирішив поставлену переді мною задачу — побудувати модель Сонячної системи.

Завдяки роботі над програмою я освоїв нові методи, ідеї та принципи роботи з алгоритмами.

Список використаних джерел

  • 1. Страуструп Б. Язык программирования С++[Текст] / В. А. Липатьев. — М.: ИНФРА-М, 2007. — 369 с.
  • 2. https://wiki.qt.io/How_to_create_a_library_with_Qt_and_use_it_in_an_application/ru
  • 3. http://doc.qt.io/qt-4.8/timers.html
  • 4. https://forum.qt.io/topic/23 441/solved-adding-image-to-a-layout

Додаток

// Body.h.

#ifndef BODY_H.

#define BODY_H.

#include.

#include.

class Body.

{.

public:

Body (float size, float mass, short type, QPointF position, QPointF speed, bool physics, Body *parent = NULL);

float size;

float mass;

short type;

QPointF position;

QPointF speed;

bool physics;

Body *parent;

QVector trace;

void calculateSpeed (QList bodies, float gConstant, float deltaTime);

};

#endif // BODY_H.

// Body.cpp.

#include «body.h» .

#include.

Body:Body (float size, float mass, short type, QPointF position, QPointF speed, bool physics, Body *parent) {.

this->size = size;

this->mass = mass;

this->type = type;

this->position = position;

this->speed = speed;

this->physics = physics;

this->parent = parent;

}.

void Body: calculateSpeed (QList bodies, float gConstant, float deltaTime) {.

QPointF forceVector;

if (this->parent == NULL) {.

for (int j = 0; j < bodies. count (); j++) {.

Body *secondBody = bodies[j];

if (secondBody ≠ this && secondBody->parent == NULL) {.

float dist = sqrt (pow (this->position.x () — secondBody->position.x (), 2) + pow (this->position.y () — secondBody->position.y (), 2));

float force = gConstant * secondBody->mass * this->mass / pow (dist * 1 000 000 000, 2);

force /= this->mass;

float angle = atan2(this->position.y () — secondBody->position.y (), this->position.x () — secondBody->position.x ());

forceVector -= QPointF (cos (angle) * force, sin (angle) * force);

}.

}.

} else {.

if (parent->physics) {.

this->position += parent->speed;

}.

float dist = sqrt (pow (this->position.x () — parent->position.x (), 2) + pow (this->position.y () — parent->position.y (), 2));

float force = gConstant * parent->mass * this->mass / pow (dist * 1 000 000 000, 2);

force /= this->mass;

float angle = atan2(this->position.y () — parent->position.y (), this->position.x () — parent->position.x ());

forceVector -= QPointF (cos (angle) * force, sin (angle) * force);

}.

this->speed += forceVector / deltaTime;

}.

// MainWindow.h.

#ifndef MAINWINDOW_H.

#define MAINWINDOW_H.

#include.

#include «body.h» .

#include.

#include.

#include «newwindow.h» .

namespace Ui {.

class MainWindow;

}.

class MainWindow: public QMainWindow.

{.

Q_OBJECT.

public:

explicit MainWindow (QWidget *parent = 0);

~MainWindow ();

protected:

void paintEvent (QPaintEvent *) override;

private:

Ui:MainWindow *ui;

QList bodies;

private slots:

void physics ();

void timerStop ();

void forcePlus ();

void forceMinus ();

};

#endif // MAINWINDOW_H.

// MainWindow.cpp.

#include «mainwindow.h» .

#include «ui_mainwindow.h» .

#include.

#include.

#include.

#include.

// Константні масси.

const float sunMass = 1.989 * pow (10, 30);

const float earthMass = 2.122 * pow (10, 30);

const float moonMass = 7.34 * pow (10, 22);

const float marsMass = 1.877 * pow (10, 30);

const float phobosMass = 1.072 * pow (10, 16);

const float deimosMass = 1.48 * pow (10, 15);

const float venusMass = 4.867 * pow (10, 24);

const float mercuryMass = 3.285 * pow (10, 23);

// Гравітація.

const float gConstant = 6.67 408 * pow (10, -11);

float forceMod = 1;

bool a = false;

int times = 0;

int brand = 1/forceMod;

// Циклічні змінні.

QTimer *timer = new QTimer ();

unsigned short frameDelay = 15;

// ФПС.

QTime t;

float deltaTime = frameDelay;

// Зображення.

QList pictures;

void MainWindow: paintEvent (QPaintEvent *) {.

QPainter p;

p.begin (this);

p.fillRect (QRect (0, 0, ui->centralWidget->width (), ui->centralWidget->height ()), Qt: black);

for (int i = 0; i < bodies. count (); i++) {.

for (int j = 0; j trace. count () — 1; j++) {.

p.setPen (QColor (j, j, j));

p.drawLine (bodies[i]->trace[j], bodies[i]->trace[j + 1]);

}.

}.

for (int i = 0; i < bodies. count (); i++) {.

Body *currentBody = bodies[i];

QImage temp = pictures[currentBody->type]. scaled (QSize (pictures[currentBody->type].width ()*currentBody->size, pictures[currentBody->type]. height ()*currentBody->size));

p.drawImage (QPoint (currentBody->position.x () — temp. width () / 2,.

currentBody->position.y () — temp. height () / 2), temp);

}.

p.setPen (Qt:gray);

p.drawText (QPoint (0, 10), QString (QString:number (int (1000 / deltaTime))+" fps"));

p.drawText (QPoint (0, ui->centralWidget->height () — 1), QString (QString:number (forceMod)+" x"));

p.end ();

}.

void MainWindow: physics () {.

if (forceMod<1) {.

if (times%brand==0) {.

times = 0;

for (int i = 0; i < bodies. count (); i++) {.

if (bodies[i]->physics) {.

bodies[i]->calculateSpeed (bodies, gConstant, deltaTime);

}.

}.

for (int i = 0; i < bodies. count (); i++) {.

bodies[i]->trace.append (bodies[i]->position);

if (bodies[i]->trace.count () > 255) {.

bodies[i]->trace.removeFirst ();

}.

if (bodies[i]->physics) {.

bodies[i]->position += bodies[i]->speed;

}.

}.

}.

times++;

deltaTime = t. elapsed ();

t.restart ();

}.

else {.

for (int i = 0; i < forceMod; i++) {.

for (int i = 0; i < bodies. count (); i++) {.

if (bodies[i]->physics) {.

bodies[i]->calculateSpeed (bodies, gConstant, deltaTime);

}.

}.

for (int i = 0; i < bodies. count (); i++) {.

bodies[i]->trace.append (bodies[i]->position);

if (bodies[i]->trace.count () > 255) {.

bodies[i]->trace.removeFirst ();

}.

if (bodies[i]->physics) {.

bodies[i]->position += bodies[i]->speed;

}.

}.

deltaTime = t. elapsed ();

}.

t.restart ();

}.

update ();

}.

void MainWindow: timerStop () {.

if (a).

{.

a = false;

timer->start ();

ui->pushButton->setText («Stop»);

}.

else.

{.

a = true;

timer->stop ();

ui->pushButton->setText («Start»);

}.

}.

void MainWindow: forcePlus () {.

if (forceMod>=0.9) {.

forceMod++;

}.

else.

{.

forceMod *= 10;

brand = 1/forceMod;

}.

times = 0;

}.

void MainWindow: forceMinus () {.

times = 0;

if (forceMod>1) {.

forceMod—;

}.

else.

{.

forceMod /= 10;

brand = 1/forceMod;

}.

}.

MainWindow:MainWindow (QWidget *parent): QMainWindow (parent), ui (new Ui: MainWindow) {.

ui->setupUi (this);

connect (ui->pushButton, SIGNAL (released ()), this, SLOT (timerStop ()));

connect (ui->pushButton2, SIGNAL (released ()), this, SLOT (forceMinus ()));

connect (ui->pushButton3, SIGNAL (released ()), this, SLOT (forcePlus ()));

pictures.append (QImage («:/type0.png»));

pictures.append (QImage («:/type1.png»));

pictures.append (QImage («:/type2.png»));

pictures.append (QImage («:/type3.png»));

pictures.append (QImage («:/type4.png»));

pictures.append (QImage («:/type5.png»));

pictures.append (QImage («:/type6.png»));

pictures.append (QImage («:/type7.png»));

Body *newBody = new Body (3, sunMass, 0, QPointF (450, 300), QPointF (0, 0), false);

bodies.append (newBody);

newBody = new Body (1, earthMass, 1, QPointF (300, 300), QPointF (0, -0.25), true);

bodies.append (newBody);

newBody = new Body (1, moonMass, 2, QPointF (270, 300), QPointF (0, -0.55), true, bodies[1]);

bodies.append (newBody);

newBody = new Body (0.5, mercuryMass, 3, QPointF (393, 300), QPointF (0, -0.39), true, bodies[0]);

bodies.append (newBody);

newBody = new Body (0.8, venusMass, 4, QPointF (342, 300), QPointF (0, -0.28), true, bodies[0]);

bodies.append (newBody);

newBody = new Body (0.9, marsMass, 5, QPointF (223, 300), QPointF (0, -0.2), true, bodies[0]);

bodies.append (newBody);

newBody = new Body (0.2, deimosMass, 6, QPointF (210, 300), QPointF (0, -0.85), true, bodies[5]);

bodies.append (newBody);

newBody = new Body (0.4, phobosMass, 7, QPointF (205, 300), QPointF (0, -0.7), true, bodies[5]);

bodies.append (newBody);

// Підключення головного таймера до функції.

connect (timer, QTimer: timeout, this, physics);

timer->start (frameDelay);

t.start ();

}.

MainWindow:~MainWindow () {.

delete ui;

}.

// Main.cpp.

#include «mainwindow.h» .

#include.

int main (int argc, char *argv[]).

{.

QApplication a (argc, argv);

MainWindow w;

w.show ();

return a. exec ();

}.

Показать весь текст
Заполнить форму текущей работой