-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
54 lines (46 loc) · 1.17 KB
/
Copy pathmain.cpp
File metadata and controls
54 lines (46 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "matlab.hpp"
#include <cmath>
#include <vector>
#include <iostream>
int main()
{
using namespace matplot;
std::vector<float> x = linspace(-4 * acos(-1), 4 * acos(-1), 100);
std::vector<float> y1, y2;
for (float xi : x)
{
y1.push_back(sin(xi));
y2.push_back(cos(xi));
}
// === 创建一个窗口 ===
Figure *fig1 = figure();
auto axes1 = fig1->gca();
axes1->setTitle("Sine and Cosine Waves");
axes1->setXLabel("X");
axes1->setYLabel("Y");
axes1->grid(true);
plot(axes1, x, y1, "b-");
plot(axes1, x, y2, "r--");
// === 主渲染循环 ===
std::vector<Figure *> figures = {fig1};
bool anyOpen = true;
while (anyOpen)
{
anyOpen = false;
for (auto fig : figures)
{
if (fig && fig->window && !glfwWindowShouldClose(fig->window))
{
fig->render();
glfwSwapBuffers(fig->window);
anyOpen = true;
}
}
glfwPollEvents();
std::this_thread::sleep_for(std::chrono::milliseconds(16));
}
// === 清理 ===
delete fig1;
glfwTerminate();
return 0;
}