同步操作将从 飞行器智能感知与控制/python_turtle 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#include <stdio.h>#include <stdlib.h>#include <QThread>#include <QtGui>#include <QDebug>#include "mainwindow.h"////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////MainWindow::MainWindow(QWidget *parent): QWidget(parent){// create background image as canvascanvasWidth = 800;canvasHeight = 600;m_img = new QImage(canvasWidth, canvasHeight,QImage::Format_RGB888);m_img->fill(QColor(0xff, 0xff, 0xff));setGeometry(20, 35, canvasWidth+20, canvasHeight+20);// set window propertiessetBackgroundRole(QPalette::Base);setAutoFillBackground(true);// set focus to selfsetFocus();// start timerstartTimer(20);// create boids & set default width & heightfor(int i=0; i<150; i++) {Boid b(canvasWidth/2.0, canvasHeight/2.0);b.width = canvasWidth;b.height = canvasHeight;flock.addBoid(b);}}void MainWindow::timerEvent(QTimerEvent *event){Q_UNUSED(event);static int step_i = 0;// run flock new time step calculationflock.run();// draw flockQPainter painter;m_img->fill(QColor(0xff, 0xff, 0xff));painter.begin(m_img);painter.setRenderHint(QPainter::Antialiasing, true);// draw each boidfor(auto &b : flock.getBoids()) {painter.setPen(QColor(255, 0, 0));painter.drawRect(b.position.x-2, b.position.y-2, 4, 4);}painter.end();// save imagesif( 0 ) {char img_name[256];sprintf(img_name, "img_%06d.jpg", step_i++);m_img->save(QString::fromLocal8Bit(img_name));}// update to mainwindowthis->update();}void MainWindow::keyPressEvent(QKeyEvent *event){QPainter painter;// 'o' - random draw rectanglesif( event->key() == Qt::Key_O ) {painter.begin(m_img);painter.setRenderHint(QPainter::Antialiasing, true);double x1, y1, x2, y2, w, h;for(int i=0; i<1000; i++) {painter.setPen(QColor(rand()%255, rand()%255, rand()%255, rand()%255));x1 = rand() % 800; y1 = rand() % 600;x2 = rand() % 800; y2 = rand() % 600;w = x2 - x1;h = y2 - y1;painter.drawRect(x1, y1, w, h);}painter.end();}// 'c' - clean canvasif( event->key() == Qt::Key_C ) {m_img->fill(QColor(0xff, 0xff, 0xff));}// 'q' - quit the programif( event->key() == Qt::Key_Q ) {this->close();}this->update();}void MainWindow::mousePressEvent(QMouseEvent *event){Boid b(event->x(), event->y());b.width = canvasWidth;b.height = canvasHeight;flock.addBoid(b);}void MainWindow::mouseMoveEvent(QMouseEvent *event){Q_UNUSED(event);}void MainWindow::paintEvent(QPaintEvent *event){Q_UNUSED(event);QPainter painter(this);// draw offline image to screenpainter.drawImage(QPoint(0, 0), *m_img);}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。