Aug-29-2018, 02:34 PM
I am trying to implement circular progress bar. code is below-
import numpy as np
import math
import matplotlib
import time
def update_bar(steps,lastPos,xc,yc):
percent = lastPos + 2
lastPos = max(1,lastPos)
theta = steps[lastPos:percent]
iX = 0.45*np.cos(theta) + xc
iY = 0.45*np.sin(theta) + yc
oX = 0.35*np.cos(theta) + xc
oY = 0.35*np.sin(theta) + yc
xx = np.matrix(np.zeros([len(theta)*2+1]))
yy = np.matrix(np.zeros([len(theta)*2+1]))
xx[:,0:len(iX)]=iX
xx[:,len(iX):(len(oX)+len(iX))] = oX[::-1]
xx[:,len(theta)*2] = iX[0]
yy[:,0:len(iY)]=iY
yy[:,len(iY):(len(oY)+len(iY))] = oY[::-1]
yy[:,len(theta)*2] = iY[0]
#
# xx = [iX[0], iX[1:len(iX)], oX[::-1], iX[0]]
# yy = [iY[0], iY[1:len(iY)], np.fliplr(oY), iY[0]]
color = [0.91, 0.47, 0.17]
matplotlib.patches( xx, yy)#, color, 'EdgeColor'= color)
def main():
# fig = matplotlib.pyplot.figure()
theta = np.arange(-math.pi,math.pi,0.01,dtype=float)
xc = 0.5
yc = 0.5
x = 0.45*np.cos(theta) + xc
y = 0.45*np.sin(theta) + yc
x1 = 0.35*np.cos(theta) + xc
y1 = 0.35*np.sin(theta) + yc
matplotlib.pyplot.axis('equal')
matplotlib.pyplot.hold(True)
matplotlib.pyplot.plot(x,y,'black',x1,y1,'black')
matplotlib.pyplot.yticks([0,0])
matplotlib.pyplot.xticks([0,0])
# matplotlib.pyplot.hold(False)
# matplotlib.pyplot.show()
steps = np.linspace(-1.5*math.pi, 0.5*math.pi, 100, dtype = float)
lastPos = 0;
for i in range(0,100):
time.sleep(0.001)
# if i>0:
# delete(h)
update_bar(steps,lastPos,xc,yc)
# h = text ( 0.5, 0.5, [str(i) '%'], 'HorizontalAlignment', 'center' );
lastPos = lastPos + 2
if lastPos == 100:
break
main()
please help me, it's not running
import numpy as np
import math
import matplotlib
import time
def update_bar(steps,lastPos,xc,yc):
percent = lastPos + 2
lastPos = max(1,lastPos)
theta = steps[lastPos:percent]
iX = 0.45*np.cos(theta) + xc
iY = 0.45*np.sin(theta) + yc
oX = 0.35*np.cos(theta) + xc
oY = 0.35*np.sin(theta) + yc
xx = np.matrix(np.zeros([len(theta)*2+1]))
yy = np.matrix(np.zeros([len(theta)*2+1]))
xx[:,0:len(iX)]=iX
xx[:,len(iX):(len(oX)+len(iX))] = oX[::-1]
xx[:,len(theta)*2] = iX[0]
yy[:,0:len(iY)]=iY
yy[:,len(iY):(len(oY)+len(iY))] = oY[::-1]
yy[:,len(theta)*2] = iY[0]
#
# xx = [iX[0], iX[1:len(iX)], oX[::-1], iX[0]]
# yy = [iY[0], iY[1:len(iY)], np.fliplr(oY), iY[0]]
color = [0.91, 0.47, 0.17]
matplotlib.patches( xx, yy)#, color, 'EdgeColor'= color)
def main():
# fig = matplotlib.pyplot.figure()
theta = np.arange(-math.pi,math.pi,0.01,dtype=float)
xc = 0.5
yc = 0.5
x = 0.45*np.cos(theta) + xc
y = 0.45*np.sin(theta) + yc
x1 = 0.35*np.cos(theta) + xc
y1 = 0.35*np.sin(theta) + yc
matplotlib.pyplot.axis('equal')
matplotlib.pyplot.hold(True)
matplotlib.pyplot.plot(x,y,'black',x1,y1,'black')
matplotlib.pyplot.yticks([0,0])
matplotlib.pyplot.xticks([0,0])
# matplotlib.pyplot.hold(False)
# matplotlib.pyplot.show()
steps = np.linspace(-1.5*math.pi, 0.5*math.pi, 100, dtype = float)
lastPos = 0;
for i in range(0,100):
time.sleep(0.001)
# if i>0:
# delete(h)
update_bar(steps,lastPos,xc,yc)
# h = text ( 0.5, 0.5, [str(i) '%'], 'HorizontalAlignment', 'center' );
lastPos = lastPos + 2
if lastPos == 100:
break
main()
please help me, it's not running