从车间PLC到云端BI:我们是如何用Python+MQTT搞定老旧设备数据采集与可视化的?
2026/6/12 14:03:58
将它复制到https://top.51goc.com/ide上面,就可以玩了
*用鼠标点击来玩
写的有点水,不知道有没有大神请教
double x1, y1, x2, y2, x3, y3; int circle_count = 0; double get_dist_sq(double x1, double y1, double x2, double y2) { return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); } int check_win() { if (circle_count < 3) return 0; int total = 0; int covered = 0; double step = 3.0; double px, py; for (px = -100; px <= 100; px += step) { for (py = -100; py <= 100; py += step) { if (get_dist_sq(px, py, 0, 0) > 100 * 100) continue; total++; if (get_dist_sq(px, py, x1, y1) <= 86.6 * 86.6) { covered++; continue; } if (get_dist_sq(px, py, x2, y2) <= 86.6 * 86.6) { covered++; continue; } if (get_dist_sq(px, py, x3, y3) <= 86.6 * 86.6) { covered++; } } } if (total > 0 && covered >= total * 0.99) return 1; return 0; } int main() { int i; double mx, my; p.up().cav(-1).picL(1, "pub_二册8-12/bj.jpg"); /*========================================== 如果你是用的老版本,文件名为"bj.jpb" ==========================================*/ p.pic(1, 800, 800).cav(0); p.hide().speed(10); p.o(100, 0); p.moveTo(0, 300); p.cav(1); p.font(4).text("三片圆挑战:用3个圆盖住大圆!", 1, 50, 0, 0, 300); p.text("三片圆挑战:用3个圆盖住大圆!", 16, 50, 0, 2, 302); p.cav(0); p.font(6).moveTo(0, 350); p.text("作者:luo_\t\t\t游戏名:三圆盖一圆", 0); for (i = 0;; i++) { if (mouseDown()) { if (circle_count >= 3) continue; mx = getMDX(); my = getMDY(); circle_count++; if (circle_count == 1) { x1 = mx; y1 = my; } else if (circle_count == 2) { x2 = mx; y2 = my; } else if (circle_count == 3) { x3 = mx; y3 = my; } p.moveTo(mx, my); p.oo(100 * (sqrt(3) / 2), 1); /*=========================================== 注:老版WebGoC中没有sqrt命令,建议改成86.6 ===========================================*/ wait(0.3); if (circle_count == 3) { if (check_win()) { p.moveTo(0, -50); p.font(6); p.cav(1); p.moveTo(0,-300); for(int i=0;i<16*5;i++) { p.text("恭喜!挑战成功!",i%16,50); wait(0.05); } p.text("恭喜!挑战成功!",1,50); break; } else { p.moveTo(0, -50); p.font(6); p.cav(1); p.button(1, "未成功,点击退出", 0, 50, 0, 0, -300); for (;;) { if (buttonMP(1)) { p.clss(); p.font(1); for (int i = 0; i < 100; i++) { p.alp(0.05); p.text("Bye!", 0, 100); wait(0.03); } return 0; } } } } } } return 0; }