44"""
55Created on 2019年3月19日
66@author: Irony
7- @site: https://pyqt5.com https://github.com/892768447
7+ @site: https://pyqt.site , https://github.com/PyQt5
88@email: 892768447@qq.com
99@file: CircleLine
1010@description:
1414from random import random , randint
1515from time import time
1616
17- from PyQt5 .QtCore import QTimer , Qt
18- from PyQt5 .QtGui import QColor , QPainter , QPainterPath , QPen
19- from PyQt5 .QtWidgets import QWidget
20-
21-
22- __Author__ = 'Irony'
23- __Copyright__ = 'Copyright (c) 2019'
17+ try :
18+ from PyQt5 .QtCore import QTimer , Qt
19+ from PyQt5 .QtGui import QColor , QPainter , QPainterPath , QPen
20+ from PyQt5 .QtWidgets import QWidget , QApplication
21+ except ImportError :
22+ from PySide2 .QtCore import QTimer , Qt
23+ from PySide2 .QtGui import QColor , QPainter , QPainterPath , QPen
24+ from PySide2 .QtWidgets import QWidget , QApplication
2425
2526# 最小和最大半径、半径阈值和填充圆的百分比
2627radMin = 10
6061circleExpSp = 0.00004
6162circlePulse = False
6263
64+
6365# 生成随机整数 a<=x<=b
6466
6567
6668def randint (a , b ):
6769 return floor (random () * (b - a + 1 ) + a )
6870
71+
6972# 生成随机小数
7073
7174
7275def randRange (a , b ):
7376 return random () * (b - a ) + a
7477
78+
7579# 生成接近a的随机小数
7680
7781
@@ -88,7 +92,7 @@ def __init__(self, background, width, height):
8892 self .radius = hyperRange (radMin , radMax )
8993 self .filled = (False if randint (
9094 0 , 100 ) > concentricCircle else 'full' ) if self .radius < radThreshold else (
91- False if randint (0 , 100 ) > concentricCircle else 'concentric' )
95+ False if randint (0 , 100 ) > concentricCircle else 'concentric' )
9296 self .color = colors [randint (0 , len (colors ) - 1 )]
9397 self .borderColor = colors [randint (0 , len (colors ) - 1 )]
9498 self .opacity = 0.05
@@ -233,29 +237,29 @@ def renderPoints(self, painter, circles):
233237 # otherwise we connect them only if the dist is < linkDist
234238 if dist < self .linkDist :
235239 xi = (1 if circles [i ].x < circles [j ].x else -
236- 1 ) * abs (circles [i ].radius * deltax / dist )
240+ 1 ) * abs (circles [i ].radius * deltax / dist )
237241 yi = (1 if circles [i ].y < circles [j ].y else -
238- 1 ) * abs (circles [i ].radius * deltay / dist )
242+ 1 ) * abs (circles [i ].radius * deltay / dist )
239243 xj = (- 1 if circles [i ].x < circles [j ].x else 1 ) * \
240- abs (circles [j ].radius * deltax / dist )
244+ abs (circles [j ].radius * deltax / dist )
241245 yj = (- 1 if circles [i ].y < circles [j ].y else 1 ) * \
242- abs (circles [j ].radius * deltay / dist )
246+ abs (circles [j ].radius * deltay / dist )
243247 path = QPainterPath ()
244248 path .moveTo (circles [i ].x + xi , circles [i ].y + yi )
245249 path .lineTo (circles [j ].x + xj , circles [j ].y + yj )
246- # samecolor = circles[i].color == circles[j].color
250+ # samecolor = circles[i].color == circles[j].color
247251 c = QColor (circles [i ].borderColor )
248252 c .setAlphaF (min (circles [i ].opacity , circles [j ].opacity )
249253 * ((self .linkDist - dist ) / self .linkDist ))
250254 painter .setPen (QPen (c , (
251255 lineBorder * backgroundMlt if circles [i ].background else lineBorder ) * (
252- (self .linkDist - dist ) / self .linkDist )))
256+ (self .linkDist - dist ) / self .linkDist )))
253257 painter .drawPath (path )
254258
255259
256260if __name__ == '__main__' :
257261 import sys
258- from PyQt5 . QtWidgets import QApplication
262+
259263 app = QApplication (sys .argv )
260264 w = CircleLineWindow ()
261265 w .resize (800 , 600 )
0 commit comments