How to use drawLines method in fMBT

Best Python code snippet using fMBT_python

Wall-E.py

Source:Wall-E.py Github

copy

Full Screen

2from OpenGL.GLUT import *3import numpy as np4import math56def drawLines(x1, y1, x2, y2):7 glBegin(GL_LINES)8 glVertex(x1, y1)9 glVertex(x2, y2)10 glEnd()111213def drawDashLine(x,y,step):14 drawLines(x,y,x+step,y)15 drawLines(x+2*step,y,x+3*step,y)16 drawLines(x + 4 * step, y, x + 5 * step, y)17 drawLines(x + 6 * step, y, x + 7 * step, y)181920def drawCircle(r=0.025, xc=0, yc=0,l=0,h=2,outline=True):21 glBegin(GL_POLYGON)22 for theta in np.arange(l*math.pi, h*math.pi, 0.001):23 x = xc + r * math.cos(theta)24 y = yc + r * math.sin(theta)25 glVertex(x, y)26 glEnd()27 if outline == True:28 glColor3f(0, 0, 0)29 glBegin(GL_LINE_LOOP)30 for theta in np.arange(l * math.pi, h * math.pi, 0.001):31 x = xc + r * math.cos(theta)32 y = yc + r * math.sin(theta)33 glVertex(x, y)34 glEnd()3536def drawRect(x1=0.125, y1=0.25, x2=-0.125, y2=0.25, x3=-0.125, y3=-0.15, x4=0.125, y4=-0.15, outline=True):37 glBegin(GL_POLYGON)38 glVertex(x1,y1)39 glVertex(x2,y2)40 glVertex(x3,y3)41 glVertex(x4,y4)42 glEnd()43 if outline == True:44 glColor3f(0, 0, 0)45 glBegin(GL_LINE_LOOP)46 glVertex(x1, y1)47 glVertex(x2, y2)48 glVertex(x3, y3)49 glVertex(x4, y4)50 glEnd()515253def drawEyes():54 glColor3f(1,1,1)55 drawCircle(0.07,0.215,0.3)56 glColor3f(0.7134, 0.7809, 0.82)57 drawCircle(0.085, 0.19,0.35)58 glColor3f(0.7134, 0.7809, 0.82)59 drawCircle(0.05,0.27,0.41)60 glColor3f(0.4234, 0.592, 0.73)61 drawCircle(0.07,0.23,0.38,0,2)62 glColor3f(0,0,0)63 drawCircle(0.035,0.23,0.38,0,2)64 glColor3f(0.44, 0.44, 0.44)65 drawCircle(0.0125,0.225,0.375,0,20,False)66 glColor3f(0.28,0.401,0.5)67 drawCircle(0.0085,0.18,0.295,0,20,False)68 drawCircle(0.0085, 0.129, 0.36, 0, 20, False)697071def drawHand():72 glColor3f(0.5846, 0.6571, 0.74)73 drawRect(0.1, 0.02, -0.1, 0.02, -0.1, -0.02, 0.1, -0.02)74 glColor3f(0.5846, 0.6571, 0.74)75 drawRect(0.06, 0.08, -0.1, 0.08, -0.1, 0.015, 0.06, 0.015)76 glColor3f(0.5846, 0.6571, 0.74)77 drawRect(0.13, 0.05, 0.06, 0.08, 0.06, 0.015, 0.13, 0.015)78 glColor3f(0.5846, 0.6571, 0.74)79 drawRect(0.06, -0.002, -0.1, -0.002, -0.1, -0.067, 0.06, -0.067)80 glColor3f(0.5846, 0.6571, 0.74)81 glTranslate(0, -0.082, 0)82 drawRect(0.13, 0.08, 0.06, 0.08, 0.06, 0.015, 0.13, 0.045)83 glColor3f(0.5846, 0.6571, 0.74)84 glTranslate(0,0.082,0)85 drawRect(-0.08, 0.04, -0.06, 0.04, -0.06, -0.03, -0.08, -0.03)868788def drawBody():89 glColor3f(0.82, 0.6155, 0.0984)90 drawRect(0.425, 0.5, -0.425, 0.5, -0.425, -0.2, 0.425, -0.2)91 glColor3f(0.82, 0.6155, 0.0984)92 drawRect(0.45,0.5,-0.45,0.5,-0.45,0.3,0.45,0.3)93 glColor3f(0.5846, 0.6571, 0.74)94 drawRect(0.425, 0.5, -0.425, 0.5, -0.425, 0.3, 0.425, 0.3)95 glColor3f(0.3996, 0.4698, 0.54)96 drawRect(0.425, 0.5, -0.425, 0.5, -0.425, 0.45, 0.425, 0.45)97 glColor3f(0.3996, 0.4698, 0.54)98 drawRect(0.22, 0.447, 0.2, 0.447, 0.2, 0.307, 0.22, 0.307, False)99 glColor3f(0.3996, 0.4698, 0.54)100 drawRect(-0.22, 0.447, -0.2, 0.447, -0.2, 0.307, -0.22, 0.307, False)101 glColor3f(0.5846, 0.6571, 0.74)102 drawRect(0.2, 0.5, -0.2, 0.5, -0.2, 0.3, 0.2, 0.3)103 drawLines(0, 0.5, 0, 0.3)104 glColor3f(0.5086, 0.78, 0.2184)105 drawRect(0.17, 0.46, 0.07, 0.46, 0.07, 0.34, 0.17, 0.34)106 glColor3f(0.91, 0.7121, 0.1183)107 drawRect(0.39, 0.29, -0.39, 0.29, -0.39, -0.15, 0.39, -0.15, False)108 glColor3f(0.82, 0.6155, 0.0984)109 drawRect(-0.04, 0.29, -0.3, 0.29, -0.3, -0.04, -0.04, -0.04, False)110 glColor3f(1, 1, 1)111 drawLines(-0.408, -0.1, -0.408, -0.06)112 drawLines(-0.408, -0.04, -0.408, 0.425)113 glColor3f(0.51, 0.3213, 0.204)114 drawRect(0.1, 0.6, -0.1, 0.6, -0.1, 0.5, 0.1, 0.5)115 glColor3f(1, 1, 1)116 drawLines(0.07, 0.58, -0.07, 0.58)117 glColor3f(0.51, 0.3213, 0.204)118 drawRect(0.07, 0.7, -0.07, 0.7, -0.07, 0.6, 0.07, 0.6)119 glColor3f(1, 1, 1)120 drawLines(-0.05, 0.62, -0.05, 0.68)121 glColor3f(0.51, 0.3213, 0.204)122 drawRect(0.04, 0.8, -0.04, 0.8, -0.04, 0.7, 0.04, 0.7)123 glColor3f(0.51, 0.3213, 0.204)124 drawRect(0.15, 0.82, -0.15, 0.82, -0.15, 0.72, 0.15, 0.72)125 glColor3f(0.51, 0.3213, 0.204)126 drawRect(0.15, 0.76, -0.15, 0.76, -0.15, 0.72, 0.15, 0.72)127 glColor3f(0.77,0.2433,0.2156)128 drawCircle(0.02,-0.15,0.35,0,2,False)129 glColor3f(0,0,0)130 drawDashLine(-0.17,0.46,0.02)131 drawDashLine(-0.17, 0.43, 0.02)132 drawDashLine(-0.17, 0.4, 0.02)133134135def drawWheel():136 glColor3f(0.3, 0.3, 0.3)137 drawRect()138 glColor3f(1, 1, 1)139 drawLines(-0.125, 0.2, 0.03, 0.2)140 drawLines(0.045, 0.2, 0.085, 0.2)141 drawLines(0.125, 0.15, -0.08, 0.15)142 drawLines(0.085, 0.1, -0.125, 0.1)143 drawLines(-0.125, 0.05, 0.03, 0.05)144 drawLines(0.045, 0.05, 0.085, 0.05)145 drawLines(0.125, 0, -0.08, 0)146 drawLines(0.085, -0.05, -0.125, -0.05)147 drawLines(-0.125, -0.1, 0.03, -0.1)148 drawLines(0.045, -0.1, 0.085, -0.1)149150151def drawGround():152 glColor3f(0.408, 0.494, 0.518)153 glLineWidth(4)154 drawLines(1,0,0.9,0)155 drawLines(0.85, 0, 0.8, 0)156 drawLines(0.75, 0, -0.75, 0)157 drawLines(-0.85, 0, -0.8, 0)158 drawLines(-1, 0, -0.9, 0)159 drawLines(-0.82,-0.08,-0.4,-0.08)160 drawLines(-0.36,-0.08,0.82,-0.08)161 drawLines(-0.7,-0.16,0.2,-0.16)162 drawLines(0.24,-0.16,0.68,-0.16)163164165def drawName():166 glColor3f(0.028, 0.2212, 0.35)167 glLineWidth(5)168 drawLines(0,0,0.1,0)169 drawLines(0,0,0,0.1)170 drawLines(0.05,0,0.05,0.1)171 drawLines(0.1,0,0.1,0.1)172 drawLines(0.15,-0.01,0.15,0.1)173 drawLines(0.15,0.09,0.2,0.09)174 drawLines(0.2,-0.01,0.2,0.1)175 drawLines(0.15,0.05,0.2,0.05)176 drawLines(0.24,0,0.3,0)177 drawLines(0.25,0,0.25,0.1)178 drawLines(0.32, 0, 0.39, 0)179 drawLines(0.33, 0, 0.33, 0.1)180 drawLines(0.4,0.05,0.44,0.05)181 glColor3f(0.77,0.2433,0.2156)182 drawCircle(0.095,0.56,0.04,0,2,False)183 glColor3f(1,1,1)184 drawLines(0.53,0,0.53,0.08)185 drawLines(0.53,-0.01,0.59,-0.01)186 drawLines(0.53,0.04,0.59,0.04)187 drawLines(0.53,0.09,0.59,0.09)188189def draw():190 glClearColor(1, 1, 1, 1)191 glClear(GL_COLOR_BUFFER_BIT)192 glLoadIdentity()193 glTranslate(0,-0.4,0)194 glColor3f(0.9025, 0.9278, 0.95)195 drawCircle(1.2, 0, 0, 0, 2, False)196 glLoadIdentity()197 glTranslate(0, -0.7, 1)198 drawGround()199 glLoadIdentity()200 glTranslate(0.55, -0.544, 1)201 drawWheel()202 glLoadIdentity()203 glTranslate(-0.55, -0.544, 1)204 drawWheel()205 glLoadIdentity()206 glTranslate(0, -0.25, 0)207 drawBody()208 glLoadIdentity()209 glTranslate(-0.37,0.05,0)210 glScale(1,1.25,1)211 drawHand()212 glLoadIdentity()213 glRotate(180,0,1,0)214 glTranslate(-0.37,0.05,0)215 glScale(1,1.25,1)216 drawHand()217 glLoadIdentity()218 glRotate(180, 0, 1, 0)219 glTranslate(-0.35,0.18,0)220 drawEyes()221 glLoadIdentity()222 glRotate(360,0,1,0)223 glTranslate(-0.35,0.18,0)224 drawEyes()225 glLoadIdentity()226 glColor3f(0.028, 0.2212, 0.35)227 glTranslate(-0.25,-0.1,0)228 glLineWidth(5)229 drawLines(0,0,0.1,0.1)230 glTranslate(0.05,0,0)231 drawLines(0,0,0.05,0.05)232 glLoadIdentity()233 glScale(0.5,0.5,1)234 glTranslate(0.09,-0.69,0)235 drawName()236 glFlush()237238239glutInit()240glutInitDisplayMode(GLUT_RGBA | GLUT_SINGLE)241glutInitWindowSize(700, 700)242glutCreateWindow(b'WALL-E')243glutDisplayFunc(draw) # Initialize our window. ...

Full Screen

Full Screen

project3animate.py

Source:project3animate.py Github

copy

Full Screen

1import numpy as np2from matplotlib import pyplot as plt3from matplotlib import animation4###############################################################################5#plants6class branch:7 def __init__(self,ang=0,start=[0.0,0.0]):8 self.start=np.array(start).tolist()9 self.end=np.array(start).tolist()10 self.ang=ang11 #print(self.start)*0.7512 self.x=[self.start[0]]13 self.y=[self.start[1]]14 self.a=np.asarray(self.start)15 self.b=np.asarray(self.end)16 self.dist=117 self.angrot=np.pi/418 def cmdf(self):19 xc=np.cos(self.ang)20 yc=np.sin(self.ang)21 xn=self.dist*xc22 yn=self.dist*yc23 arr=self.start24 self.start=[arr[0]+xn,arr[1]+yn]25 self.x.append(self.start[0])26 self.y.append(self.start[1])27 def cmdminus(self):28 self.ang=self.ang-self.angrot29 def cmdplus(self):30 self.ang=self.ang+self.angrot31 def endreturn(self):32 return self.start33 def angreturn(self):34 return self.ang35 # def kochD(self):36 # xc=np.cos(self.ang2)37 # yc=np.sin(self.ang2)38 # xn=self.distend*xc39 # yn=self.distend*yc40 # arr=self.start41 # v=[arr[0]+xn,arr[1]+yn]42 # return v43def func1(line,lines,drawlines):44 line.cmdf()45 return lines,drawlines46def func0(line,lines,drawlines):47 line.cmdplus()48 return lines,drawlines49def minusfunc(line,lines,drawlines):50 line.cmdf()51 return lines,drawlines52def savefunc(line,lines,drawlines):53 start=line.endreturn()54 ang=line.angreturn()55 lines.append(branch(ang,start))56 line=lines[-1]57 line.cmdplus()58 return lines,drawlines59def removefunc(line,lines,drawlines):60 drawlines.append(line)61 lines.remove(line)62 line=lines[-1]63 line.cmdminus()64 return lines,drawlines65def setup():66 lines=[]67 scurrent="0"68 lines.append(branch(np.pi/2,[0,0]))69 return scurrent,lines70def generation(scurrent):71 snext=""72 read={"1":"11","0":"1[0]0","[":"[","]":"]"}73 for i in scurrent:74 snext+=read.get(i)75 return snext76def read(scurrent,lines):77 funcs={"1":func1,"0":func0,"[":savefunc,"]":removefunc}78 countdict={"1":"0","0":"0","[":"1","]":"-1"}79 drawlines=[]80 count=081 for i in scurrent:82 line=lines[count]83 #print(i)84 lines,drawlines=funcs[i](line,lines,drawlines)85 if (i == "[" or i=="]"):86 count+=int(countdict.get(i))87 #print(count)88 #print(line.x)89 #print(len(lines))90 return drawlines91def draw(drawlines):92 datax=[]93 datay=[]94 for line in drawlines:95 #print(line.x)96 #print(line.y)97 for j in line.x:98 datax.append(j)99 for k in line.y:100 datay.append(k)101 return datax,datay102def Lsystem(iterate):103 drawlines=[]104 scurrent,lines=setup()105 for i in range(0,iterate):106 snext=generation(scurrent)107 scurrent=snext108 #print(scurrent)109 drawlines=read(scurrent,lines)110 drawlines=lines+drawlines111 datax,datay=draw(drawlines)112 #plt.axis([-50,10,-1,200])113 return datax,datay114#Lsystem()115# First set up the figure, the axis, and the plot element we want to animate116fig = plt.figure()117ax = plt.axes(xlim=(-500,500), ylim=(-1, 1000))118line, = ax.plot([], [],'ro',lw=2)119# initialization function: plot the background of each frame120def init():121 line.set_data([], [])122 return line,123# animation function. This is called sequentially124def animate(i):125 if i < 11:126 datax,datay=Lsystem(i)127 line.set_data(datax,datay)128 if i>=11:129 datax,datay=Lsystem(21-i)130 line.set_data(datax,datay)131 return line,132# call the animator. blit=True means only re-draw the parts that have changed.133anim = animation.FuncAnimation(fig, animate, init_func=init,134 frames=22, interval=200, blit=False,repeat=True)135 #pause136anim.event_source.stop()137#unpause138anim.event_source.start()...

Full Screen

Full Screen

project3animate2.py

Source:project3animate2.py Github

copy

Full Screen

1import numpy as np2from matplotlib import pyplot as plt3from matplotlib import animation4class branch:5 def __init__(self,ang=0,start=[0.0,0.0]):6 self.start=np.array(start).tolist()7 self.end=np.array(start).tolist()8 self.ang=ang9 #print(self.start)*0.7510 self.x=[self.start[0]]11 self.y=[self.start[1]]12 self.a=np.asarray(self.start)13 self.b=np.asarray(self.end)14 self.dist=515 self.angrot=np.pi/1216 def cmdf(self):17 xc=np.cos(self.ang)18 yc=np.sin(self.ang)19 xn=self.dist*xc20 yn=self.dist*yc21 arr=self.start22 self.start=[arr[0]+xn,arr[1]+yn]23 self.x.append(self.start[0])24 self.y.append(self.start[1])25 def cmdminus(self):26 self.ang=self.ang-self.angrot27 def cmdplus(self):28 self.ang=self.ang+self.angrot29 def endreturn(self):30 return self.start31 def angreturn(self):32 return self.ang33 # def kochD(self):34 # xc=np.cos(self.ang2)35 # yc=np.sin(self.ang2)36 # xn=self.distend*xc37 # yn=self.distend*yc38 # arr=self.start39 # v=[arr[0]+xn,arr[1]+yn]40 # return v41def ffunc(line,lines,drawlines):42 line.cmdf()43 return lines,drawlines44def plusfunc(line,lines,drawlines):45 line.cmdplus()46 return lines,drawlines47def minusfunc(line,lines,drawlines):48 line.cmdminus()49 return lines,drawlines50def savefunc(line,lines,drawlines):51 start=line.endreturn()52 ang=line.angreturn()53 lines.append(branch(ang,start))54 return lines,drawlines55def removefunc(line,lines,drawlines):56 drawlines.append(line)57 lines.remove(line)58 return lines,drawlines59def setup():60 lines=[]61 scurrent="F"62 lines.append(branch(np.pi/2,[0,0]))63 return scurrent,lines64def generation(scurrent):65 snext=""66 read={"F":"FF+[+F-F-F]-[-F+F+F]","+":"+","-":"-","[":"[","]":"]"}67 for i in scurrent:68 snext+=read.get(i)69 return snext70def read(scurrent,lines):71 funcs={"F":ffunc,"+":plusfunc,"-":minusfunc,"[":savefunc,"]":removefunc}72 countdict={"F":"0","+":"0","-":"0","[":"1","]":"-1"}73 drawlines=[]74 count=075 for i in scurrent:76 line=lines[count]77 #print(i)78 lines,drawlines=funcs[i](line,lines,drawlines)79 if (i == "[" or i=="]"):80 count+=int(countdict.get(i))81 #print(count)82 #print(line.x)83 #print(len(lines))84 return drawlines85def draw(drawlines):86 datax=[]87 datay=[]88 for line in drawlines:89 #print(line.x)90 #print(line.y)91 for j in line.x:92 datax.append(j)93 for k in line.y:94 datay.append(k)95 return datax,datay96def Lsystem(iterate):97 drawlines=[]98 scurrent,lines=setup()99 for i in range(0,iterate):100 snext=generation(scurrent)101 scurrent=snext102 #print(scurrent)103 drawlines=read(scurrent,lines)104 drawlines=lines+drawlines105 datax,datay=draw(drawlines)106 #plt.axis([-50,10,-1,200])107 return datax,datay108#Lsystem()109# First set up the figure, the axis, and the plot element we want to animate110fig = plt.figure()111ax = plt.axes(xlim=(-100,100), ylim=(-1, 400))112line, = ax.plot([], [],'ro',lw=1)113# initialization function: plot the background of each frame114def init():115 line.set_data([], [])116 return line,117# animation function. This is called sequentially118def animate(i):119 if i < 5:120 datax,datay=Lsystem(i)121 line.set_data(datax,datay)122 if i>=5:123 datax,datay=Lsystem(7-i)124 line.set_data(datax,datay)125 return line,126# call the animator. blit=True means only re-draw the parts that have changed.127anim = animation.FuncAnimation(fig, animate, init_func=init,128 frames=5, interval=200, blit=False,repeat=False)129 #pause130anim.event_source.stop()131#unpause132anim.event_source.start()...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fMBT automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful