(self, painter)
| 185 | print(time() - t) |
| 186 | |
| 187 | def animate(self, painter): |
| 188 | for p in self.points: |
| 189 | # 检测点的范围 |
| 190 | value = abs(getDistance(self.target, p)) |
| 191 | if value < 4000: |
| 192 | # 其实就是修改颜色透明度 |
| 193 | p.lineColor.setAlphaF(0.3) |
| 194 | p.circleColor.setAlphaF(0.6) |
| 195 | elif value < 20000: |
| 196 | p.lineColor.setAlphaF(0.1) |
| 197 | p.circleColor.setAlphaF(0.3) |
| 198 | elif value < 40000: |
| 199 | p.lineColor.setAlphaF(0.02) |
| 200 | p.circleColor.setAlphaF(0.1) |
| 201 | else: |
| 202 | p.lineColor.setAlphaF(0) |
| 203 | p.circleColor.setAlphaF(0) |
| 204 | |
| 205 | # 画线条 |
| 206 | if p.lineColor.alpha(): |
| 207 | for pc in p.closest: |
| 208 | if not pc: |
| 209 | continue |
| 210 | path = QPainterPath() |
| 211 | path.moveTo(p.x, p.y) |
| 212 | path.lineTo(pc.x, pc.y) |
| 213 | painter.save() |
| 214 | painter.setPen(p.lineColor) |
| 215 | painter.drawPath(path) |
| 216 | painter.restore() |
| 217 | |
| 218 | # 画圆 |
| 219 | painter.save() |
| 220 | painter.setPen(Qt.NoPen) |
| 221 | painter.setBrush(p.circleColor) |
| 222 | painter.drawRoundedRect( |
| 223 | QRectF(p.x - p.radius, p.y - p.radius, 2 * p.radius, 2 * p.radius), |
| 224 | p.radius, |
| 225 | p.radius, |
| 226 | ) |
| 227 | painter.restore() |
| 228 | |
| 229 | # 开启动画 |
| 230 | p.initAnimation() |
| 231 | |
| 232 | |
| 233 | if __name__ == "__main__": |
no test coverage detected