Best Python code snippet using ATX
circuit.py
Source:circuit.py
...49 print ("Reta Principal:")50 r.printVertices()51 # C152 # Curva pos reta principal53 rotate = t.get_rotation(90, 'y')54 scale = t.get_scale([5, 0.05, 5, 1])55 translate = t.get_translation(r.vertices[2].coordinates[:3]) #Movimentando o triangulo para o fim da reta56 c = obj.UnitTriangle()57 c.apply_transformation(scale)58 c.apply_transformation(rotate)59 c.apply_transformation(translate)60 c.apply_material(asfalto_material)61 objects.append(c)62 # C263 rotate = t.get_rotation(-90, 'y')64 scale = t.get_scale([5, 0.05, 5, 1])65 translate = t.get_translation(c.vertices[1].coordinates[:3])66 c = obj.UnitTriangle()67 c.apply_transformation(scale)68 c.apply_transformation(rotate)69 c.apply_transformation(translate)70 #c12.printVertices()71 c.apply_material(asfalto_material)72 objects.append(c)73 74 # C375 rotate = t.get_rotation(90, 'y')76 scale = t.get_scale([5, 0.05, 5, 1])77 translate = t.get_translation(c.vertices[2].coordinates[:3])78 c = obj.UnitTriangle()79 c.apply_transformation(scale)80 c.apply_transformation(rotate)81 c.apply_transformation(translate)82 c.apply_material(asfalto_material)83 objects.append(c)84 # Reta pos principal85 scale = t.get_scale([5, 0.05, 10, 1])86 translate = t.get_translation(c.vertices[0].coordinates[:3])87 r = obj.UnitSquare()88 r.apply_transformation(scale)89 r.apply_transformation(translate)90 #r2.printVertices()91 r.apply_material(asfalto_material)92 objects.append(r)93 # Curva apos reta: 94 rotate = t.get_rotation(-90, 'y')95 scale = t.get_scale([5, 0.05, 5, 1])96 translate = t.get_translation(r.vertices[2].coordinates[:3]) #Movimentando o triangulo para o fim da reta97 c = obj.UnitTriangle()98 c.apply_transformation(scale)99 c.apply_transformation(rotate)100 c.apply_transformation(translate)101 c.apply_material(asfalto_material)102 objects.append(c)103 rotate = t.get_rotation(90, 'y')104 scale = t.get_scale([5, 0.05, 5, 1])105 translate = t.get_translation(c.vertices[2].coordinates[:3])106 c = obj.UnitTriangle()107 c.apply_transformation(scale)108 c.apply_transformation(rotate)109 c.apply_transformation(translate)110 c.apply_material(asfalto_material)111 objects.append(c)112 # Reta do lado oposto:113 scale = t.get_scale([5, 0.05, 5, 1])114 translate = t.get_translation(c.vertices[0].coordinates[:3])115 r = obj.UnitSquare()116 r.apply_transformation(scale)117 r.apply_transformation(translate)118 #r3.printVertices()119 r.apply_material(asfalto_material)120 objects.append(r)121 # Curva setor 03122 scale = t.get_scale([5, 0.05, 5, 1])123 translate = t.get_translation(r.vertices[1].coordinates[:3]) 124 c = obj.UnitTriangle()125 c.apply_transformation(scale)126 c.apply_transformation(translate)127 128 print ("Curva Setor 3")129 c.printVertices()130 c.apply_material(asfalto_material)131 objects.append(c)132 scale = t.get_scale([20, 0.05, 5, 1])133 translate = t.get_translation(c.vertices[0].coordinates[:3] - [20, 0, 0])134 r = obj.UnitSquare()135 r.apply_transformation(scale)136 r.apply_transformation(translate)137 r.apply_material(asfalto_material)138 objects.append(r)139 # Curva setor 04:140 rotate = t.get_rotation(-90, 'y')141 scale = t.get_scale([5, 0.05, 5, 1])142 translate = t.get_translation(r.vertices[0].coordinates[:3]) 143 c = obj.UnitTriangle()144 c.apply_transformation(scale)145 c.apply_transformation(rotate)146 c.apply_transformation(translate)147 #c.printVertices()148 c.apply_material(asfalto_material)149 objects.append(c)150 scale = t.get_scale([5, 0.05, 5, 1])151 translate = t.get_translation(c.vertices[1].coordinates[:3] - [0, 0, 5])152 r = obj.UnitSquare()153 r.apply_transformation(scale)154 r.apply_transformation(translate)155 #r.printVertices()156 r.apply_material(asfalto_material)157 objects.append(r)158 rotate = t.get_rotation(180, 'y')159 scale = t.get_scale([5, 0.05, 5, 1])160 translate = t.get_translation(r.vertices[3].coordinates[:3]) 161 c = obj.UnitTriangle()162 c.apply_transformation(scale)163 c.apply_transformation(rotate)164 c.apply_transformation(translate)165 #c.printVertices()166 c.apply_material(asfalto_material)167 objects.append(c)168 scale = t.get_scale([8, 0.05, 5, 1])169 translate = t.get_translation(c.vertices[1].coordinates[:3])170 r = obj.UnitSquare()171 r.apply_transformation(scale)172 r.apply_transformation(translate)173 #r.printVertices()174 r.apply_material(asfalto_material)175 objects.append(r)176 scale = t.get_scale([5, 0.05, 5, 1])177 translate = t.get_translation(r.vertices[3].coordinates[:3]) 178 c = obj.UnitTriangle()179 c.apply_transformation(scale)180 #c.apply_transformation(rotate)181 c.apply_transformation(translate)182 #c.printVertices()183 c.apply_material(asfalto_material)184 objects.append(c)185 scale = t.get_scale([5, 0.05, 5, 1])186 translate = t.get_translation(c.vertices[0].coordinates[:3] - [0, 0, 5])187 r = obj.UnitSquare()188 r.apply_transformation(scale)189 r.apply_transformation(translate)190 #r.printVertices()191 r.apply_material(asfalto_material)192 objects.append(r)193 rotate = t.get_rotation(90, 'y')194 scale = t.get_scale([5, 0.05, 5, 1])195 translate = t.get_translation(r.vertices[0].coordinates[:3]) 196 c = obj.UnitTriangle()197 c.apply_transformation(scale)198 c.apply_transformation(rotate)199 c.apply_transformation(translate)200 #c.printVertices()201 c.apply_material(asfalto_material)202 objects.append(c)203 scale = t.get_scale([10, 0.05, 5, 1])204 translate = t.get_translation(c.vertices[2].coordinates[:3] - [10, 0, 0])205 r = obj.UnitSquare()206 r.apply_transformation(scale)207 r.apply_transformation(translate)208 #r.printVertices()209 r.apply_material(asfalto_material)210 objects.append(r)211 # -- PRIMEIRA DIAGONAL DO CIRCUITO: -- #212 rotate = t.get_rotation(180, 'y')213 scale = t.get_scale([5, 0.05, 5, 1])214 translate = t.get_translation(r.vertices[1].coordinates[:3]) 215 d = obj.UnitTriangle()216 d.apply_transformation(scale)217 d.apply_transformation(rotate)218 d.apply_transformation(translate)219 #d11.printVertices()220 d.apply_material(asfalto_material)221 objects.append(d)222 translate = t.get_translation(d.vertices[2].coordinates[:3]) 223 d = obj.UnitTriangle()224 d.apply_transformation(scale)225 d.apply_transformation(translate)226 #d12.printVertices()227 d.apply_material(asfalto_material)228 objects.append(d)229 rotate = t.get_rotation(180, 'y')230 translate = t.get_translation(d.vertices[1].coordinates[:3]) 231 d = obj.UnitTriangle()232 d.apply_transformation(scale)233 d.apply_transformation(rotate)234 d.apply_transformation(translate)235 #d.printVertices()236 d.apply_material(asfalto_material)237 objects.append(d)238 translate = t.get_translation(d.vertices[2].coordinates[:3]) 239 d = obj.UnitTriangle()240 d.apply_transformation(scale)241 d.apply_transformation(translate)242 #d.printVertices()243 d.apply_material(asfalto_material)244 objects.append(d)245 rotate = t.get_rotation(180, 'y')246 translate = t.get_translation(d.vertices[1].coordinates[:3]) 247 d = obj.UnitTriangle()248 d.apply_transformation(scale)249 d.apply_transformation(rotate)250 d.apply_transformation(translate)251 #d.printVertices()252 d.apply_material(asfalto_material)253 objects.append(d)254 translate = t.get_translation(d.vertices[2].coordinates[:3]) 255 d = obj.UnitTriangle()256 d.apply_transformation(scale)257 d.apply_transformation(translate)258 #d.printVertices()259 d.apply_material(asfalto_material)260 objects.append(d)261 rotate = t.get_rotation(180, 'y')262 translate = t.get_translation(d.vertices[1].coordinates[:3]) 263 d = obj.UnitTriangle()264 d.apply_transformation(scale)265 d.apply_transformation(rotate)266 d.apply_transformation(translate)267 #d.printVertices()268 d.apply_material(asfalto_material)269 objects.append(d)270 translate = t.get_translation(d.vertices[2].coordinates[:3]) 271 d = obj.UnitTriangle()272 d.apply_transformation(scale)273 d.apply_transformation(translate)274 #d.printVertices()275 d.apply_material(asfalto_material)276 objects.append(d)277 # INFLEXAO DA DIAGONAL278 scale = t.get_scale([5, 0.05, 5, 1])279 translate = t.get_translation(d.vertices[0].coordinates[:3] - [5 ,0, 0])280 r = obj.UnitSquare()281 r.apply_transformation(scale)282 r.apply_transformation(translate)283 #r.printVertices()284 r.apply_material(asfalto_material)285 objects.append(r)286 # Iniciando a outra Diagonal287 rotate = t.get_rotation(-90, 'y')288 translate = t.get_translation(r.vertices[0].coordinates[:3]) 289 d = obj.UnitTriangle()290 d.apply_transformation(scale)291 d.apply_transformation(rotate)292 d.apply_transformation(translate)293 #d.printVertices()294 d.apply_material(asfalto_material)295 objects.append(d)296 rotate = t.get_rotation(90, 'y')297 translate = t.get_translation(d.vertices[1].coordinates[:3]) 298 d = obj.UnitTriangle()299 d.apply_transformation(scale)300 d.apply_transformation(rotate)301 d.apply_transformation(translate)302 #d.printVertices()303 d.apply_material(asfalto_material)304 objects.append(d)305 306 rotate = t.get_rotation(-90, 'y')307 translate = t.get_translation(d.vertices[2].coordinates[:3]) 308 d = obj.UnitTriangle()309 d.apply_transformation(scale)310 d.apply_transformation(rotate)311 d.apply_transformation(translate)312 #d.printVertices()313 d.apply_material(asfalto_material)314 objects.append(d)315 rotate = t.get_rotation(90, 'y')316 translate = t.get_translation(d.vertices[1].coordinates[:3]) 317 d = obj.UnitTriangle()318 d.apply_transformation(scale)319 d.apply_transformation(rotate)320 d.apply_transformation(translate)321 #d.printVertices()322 d.apply_material(asfalto_material)323 objects.append(d)324 rotate = t.get_rotation(-90, 'y')325 translate = t.get_translation(d.vertices[2].coordinates[:3]) 326 d = obj.UnitTriangle()327 d.apply_transformation(scale)328 d.apply_transformation(rotate)329 d.apply_transformation(translate)330 #d.printVertices()331 d.apply_material(asfalto_material)332 objects.append(d)333 rotate = t.get_rotation(90, 'y')334 translate = t.get_translation(d.vertices[1].coordinates[:3]) 335 d = obj.UnitTriangle()336 d.apply_transformation(scale)337 d.apply_transformation(rotate)338 d.apply_transformation(translate)339 #d.printVertices()340 d.apply_material(asfalto_material)341 objects.append(d)342 rotate = t.get_rotation(-90, 'y')343 translate = t.get_translation(d.vertices[2].coordinates[:3]) 344 d = obj.UnitTriangle()345 d.apply_transformation(scale)346 d.apply_transformation(rotate)347 d.apply_transformation(translate)348 #d.printVertices()349 d.apply_material(asfalto_material)350 objects.append(d)351 rotate = t.get_rotation(90, 'y')352 translate = t.get_translation(d.vertices[1].coordinates[:3]) 353 d = obj.UnitTriangle()354 d.apply_transformation(scale)355 d.apply_transformation(rotate)356 d.apply_transformation(translate)357 #d.printVertices()358 d.apply_material(asfalto_material)359 objects.append(d)360 # Termino361 scale = t.get_scale([5, 0.05, 5, 1])362 translate = t.get_translation(d.vertices[2].coordinates[:3] - [5 ,0, 0])363 r = obj.UnitSquare()364 r.apply_transformation(scale)365 r.apply_transformation(translate)366 #r.printVertices()367 r.apply_material(asfalto_material)368 objects.append(r)369 rotate = t.get_rotation(180, 'y')370 scale = t.get_scale([5, 0.05, 5, 1])371 translate = t.get_translation(r.vertices[1].coordinates[:3]) 372 c = obj.UnitTriangle()373 c.apply_transformation(scale)374 c.apply_transformation(rotate)375 c.apply_transformation(translate)376 c.apply_material(asfalto_material)377 objects.append(c)378 scale = t.get_scale([5, 0.05, 10, 1])379 translate = t.get_translation(c.vertices[2].coordinates[:3])380 r = obj.UnitSquare()381 r.apply_transformation(scale)382 r.apply_transformation(translate)383 r.apply_material(asfalto_material)384 objects.append(r)385 rotate = t.get_rotation(-90, 'y')386 scale = t.get_scale([5, 0.05, 5, 1])387 translate = t.get_translation(r.vertices[2].coordinates[:3]) 388 c = obj.UnitTriangle()389 c.apply_transformation(scale)390 c.apply_transformation(rotate)391 c.apply_transformation(translate)392 c.apply_material(asfalto_material)393 objects.append(c)394 translate = t.get_translation(c.vertices[0].coordinates[:3])395 r = obj.UnitSquare()396 r.apply_transformation(scale)397 r.apply_transformation(translate)398 r.apply_material(asfalto_material)399 objects.append(r)400 rotate = t.get_rotation(90, 'y')401 translate = t.get_translation(r.vertices[2].coordinates[:3]) 402 c = obj.UnitTriangle()403 c.apply_transformation(scale)404 c.apply_transformation(rotate)405 c.apply_transformation(translate)406 c.apply_material(asfalto_material)407 objects.append(c)408 translate = t.get_translation(c.vertices[0].coordinates[:3])409 r = obj.UnitSquare()410 r.apply_transformation(scale)411 r.apply_transformation(translate)412 r.apply_material(asfalto_material)413 objects.append(r)414 translate = t.get_translation(r.vertices[1].coordinates[:3]) 415 c = obj.UnitTriangle()416 c.apply_transformation(scale)417 c.apply_transformation(translate)418 c.apply_material(asfalto_material)419 objects.append(c)420 scale = t.get_scale([15, 0.05, 5, 1])421 translate = t.get_translation(c.vertices[0].coordinates[:3] - [15,0,0])422 r = obj.UnitSquare()423 r.apply_transformation(scale)424 r.apply_transformation(translate)425 r.apply_material(asfalto_material)426 objects.append(r)427 scale = t.get_scale([5, 0.05, 5, 1])428 rotate = t.get_rotation(-90, 'y')429 translate = t.get_translation(r.vertices[0].coordinates[:3]) 430 c = obj.UnitTriangle()431 c.apply_transformation(scale)432 c.apply_transformation(rotate)433 c.apply_transformation(translate)434 c.apply_material(asfalto_material)435 objects.append(c)436 #Ultima reta antes da ultima curva437 scale = t.get_scale([5, 0.05, 30, 1])438 translate = t.get_translation(c.vertices[1].coordinates[:3] - [0,0,30])439 r = obj.UnitSquare()440 r.apply_transformation(scale)441 r.apply_transformation(translate)442 r.apply_material(asfalto_material)443 objects.append(r)444 print("Ultima reta antes da ultima curva: ")445 r.printVertices()446 447 scale = t.get_scale([5, 0.05, 5, 1])448 rotate = t.get_rotation(180, 'y')449 translate = t.get_translation(r.vertices[3].coordinates[:3]) 450 c = obj.UnitTriangle()451 c.apply_transformation(scale)452 c.apply_transformation(rotate)453 c.apply_transformation(translate)454 c.apply_material(asfalto_material)455 objects.append(c)456 # Reta que liga a saida da curva com a pista principal457 scale = t.get_scale([22, 0.05, 5, 1])458 translate = t.get_translation(c.vertices[1].coordinates[:3])459 r = obj.UnitSquare()460 r.apply_transformation(scale)461 r.apply_transformation(translate)462 r.apply_material(asfalto_material)463 objects.append(r)464 print("Reta que liga a saida da curva com a pista principal")465 r.printVertices()466 # LINHA CHEGADA467 scale = t.get_scale([1.25, 0.06, 1.25, 1])468 translate = t.get_translation(r.vertices[3].coordinates[:3])469 r = obj.UnitSquare()470 r.apply_transformation(scale)471 r.apply_transformation(translate)472 r.apply_material(lc1_material)473 objects.append(r)474 475 translate = t.get_translation(r.vertices[1].coordinates[:3])476 r = obj.UnitSquare()477 r.apply_transformation(scale)478 r.apply_transformation(translate)479 r.apply_material(lc2_material)480 objects.append(r)481 482 translate = t.get_translation(r.vertices[1].coordinates[:3])483 r = obj.UnitSquare()484 r.apply_transformation(scale)485 r.apply_transformation(translate)486 r.apply_material(lc1_material)487 objects.append(r)488 489 translate = t.get_translation(r.vertices[1].coordinates[:3])490 r = obj.UnitSquare()491 r.apply_transformation(scale)492 r.apply_transformation(translate)493 r.apply_material(lc2_material)494 objects.append(r)495 496 '''497 ## Linha de Chegada:498 translate = t.get_translation(r.vertices[3].coordinates[:3])499 r = obj.UnitSquare()500 r.apply_transformation(scale)501 r.apply_transformation(translate)502 r.apply_material(lc2_material)503 objects.append(r)504 translate = t.get_translation(r.vertices[0].coordinates[:3] - [0,0,1.25])505 r = obj.UnitSquare()506 r.apply_transformation(scale)507 r.apply_transformation(translate)508 r.apply_material(lc1_material)509 objects.append(r)510 511 r = obj.UnitSquare()512 r.apply_transformation(scale)513 r.apply_transformation(translate)514 r.apply_material(lc2_material)515 objects.append(r)516 517 r = obj.UnitSquare()518 r.apply_transformation(scale)519 r.apply_transformation(translate)520 r.apply_material(lc1_material)521 objects.append(r)522 '''523 # -- Arquibancadas (GrandStand):524 # Arquibancada reta principal:525 scale = t.get_scale([40, 10, 10, 1])526 translate = t.get_translation([39,0.05,36])527 gs = obj.UnitGrandstand([140/255, 23/255, 23/255]) #Cor das arquibancadas [1,1,1]528 gs.apply_transformation(scale)529 gs.apply_transformation(translate)530 print("Arquibancada Reta Principal:")531 gs.printVertices()532 objects.append(gs)533 # Cobertura Arquibancada reta principal:534 scale = t.get_scale([40, 2, 10, 1])535 translate = t.get_translation(gs.vertices[0].coordinates[:3] + [0,10,0])536 cobertura = obj.UnitSquare()537 cobertura.apply_transformation(scale)538 cobertura.apply_transformation(translate)539 print("Cobertura:")540 cobertura.printVertices()541 objects.append(cobertura)542 # Arquibancada reta antes principal:543 rotate = t.get_rotation(90, 'y')544 gs = obj.UnitGrandstand([207/255, 181/255, 59/255]) #Cor das arquibancadas [1,1,1]545 gs.apply_transformation(rotate)546 #gs.printVertices()547 translate = t.get_translation([0,0,1])548 gs.apply_transformation(translate)549 #gs.printVertices()550 551 scale = t.get_scale([10, 10, 30, 1])552 gs.apply_transformation(scale)553 554 translate = t.get_translation([11,0,55])555 gs.apply_transformation(translate)556 #gs.printVertices()557 objects.append(gs) ...
rotation.py
Source:rotation.py
1from pathlib import Path2import cv23import numpy as np4from matplotlib import pyplot as plt5def get_rotation(6 img: np.ndarray, pt1: np.ndarray, pt2: np.ndarray, rows: int, cols: int7) -> np.ndarray:8 """9 Get image rotation10 :param img: np.array11 :param pt1: 3x2 list12 :param pt2: 3x2 list13 :param rows: columns image shape14 :param cols: rows image shape15 :return: np.array16 """17 matrix = cv2.getAffineTransform(pt1, pt2)18 return cv2.warpAffine(img, matrix, (rows, cols))19if __name__ == "__main__":20 # read original image21 image = cv2.imread(22 str(Path(__file__).resolve().parent.parent / "image_data" / "lena.jpg")23 )24 # turn image in gray scale value25 gray_img = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)26 # get image shape27 img_rows, img_cols = gray_img.shape28 # set different points to rotate image29 pts1 = np.array([[50, 50], [200, 50], [50, 200]], np.float32)30 pts2 = np.array([[10, 100], [200, 50], [100, 250]], np.float32)31 pts3 = np.array([[50, 50], [150, 50], [120, 200]], np.float32)32 pts4 = np.array([[10, 100], [80, 50], [180, 250]], np.float32)33 # add all rotated images in a list34 images = [35 gray_img,36 get_rotation(gray_img, pts1, pts2, img_rows, img_cols),37 get_rotation(gray_img, pts2, pts3, img_rows, img_cols),38 get_rotation(gray_img, pts2, pts4, img_rows, img_cols),39 ]40 # plot different image rotations41 fig = plt.figure(1)42 titles = ["Original", "Rotation 1", "Rotation 2", "Rotation 3"]43 for i, image in enumerate(images):44 plt.subplot(2, 2, i + 1), plt.imshow(image, "gray")45 plt.title(titles[i])46 plt.axis("off")47 plt.subplots_adjust(left=0.0, bottom=0.05, right=1.0, top=0.95)...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!