Skip to content

Commit 6508cac

Browse files
committed
fix rendering
1 parent d63bfe2 commit 6508cac

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

IsingWindow.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,15 @@ IsingWidget::IsingWidget (unsigned M, unsigned N, double J,
7979
setFixedWidth(M);
8080
setFixedHeight(N);
8181

82+
render_timer = new QTimer(this);
83+
connect(render_timer, SIGNAL (timeout()), this, SLOT (update()) );
84+
render_timer->start(100);
85+
8286
}
8387

8488
IsingWidget::~IsingWidget () {
8589
delete imc;
90+
delete render_timer;
8691
}
8792

8893
void IsingWidget::paintEvent (QPaintEvent *e) {
@@ -93,12 +98,6 @@ void IsingWidget::paintEvent (QPaintEvent *e) {
9398
unsigned PenSize = 1;
9499
unsigned offset = PenSize ? PenSize : 1;
95100

96-
// std::cout << imc->Energy() << std::endl;
97-
98-
// std::cout << "Energy: " << imc->Energy()
99-
// << " Magnetization: " << imc->Magnetization()
100-
// << std::endl;
101-
102101
QPen WhitePen(Qt::white, PenSize, Qt::SolidLine),
103102
BlackPen(Qt::black, PenSize, Qt::SolidLine);
104103
for (unsigned i = 0; i < imc->XSize(); i++) {
@@ -123,13 +122,10 @@ void IsingWidget::simulationThread(unsigned num) {
123122
for (unsigned i = 0; i < num; i++) {
124123
imc->Step();
125124
}
126-
// emit paintEvent(0);
127-
update();
128125
}
129126
}
130127

131128
void IsingWidget::ToggleSimulation(bool sstate) {
132-
std::cout << "state of simulation before changing: " << running << std::endl;
133129
if (sstate) { startSimulation(); }
134130
else { stopSimulation(); }
135131
}

IsingWindow.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <QString>
1111
#include <QGridLayout>
1212
#include <QPushButton>
13+
#include <QTimer>
1314
#include <thread>
1415

1516
#include "IsingMC.hpp"
@@ -66,6 +67,7 @@ class IsingWidget : public QWidget {
6667
IsingMC *imc;
6768
bool running;
6869
unsigned iterations;
70+
QTimer *render_timer;
6971

7072
};
7173

main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
int main(int argc, char *argv[]) {
66

7-
unsigned NX = 500;
8-
unsigned NY = 500;
7+
unsigned NX = 100;
8+
unsigned NY = 100;
99

1010
QApplication app(argc, argv);
1111
IsingWindow iw(NX, NY, 1.14, 0.5);

0 commit comments

Comments
 (0)