Best Python code snippet using tempest_python
pcb_art.py
Source:pcb_art.py
1#!/usr/bin/env python2num_nets=83num_dots=3004max_width=10000005max_height=10000006filename="art.pcb"7via_diameter = 110008spacing = via_diameter/49report_collisions = True10max_percentage = 0.7011slots = int(max_width/via_diameter) * int(max_height/via_diameter)12if num_dots > slots*max_percentage:13 print 'too much dots! Max allowed is %d' % int(slots*max_percentage)14 exit()15#####################16def output_header(fp, max_width, max_height):17 fp.write(18'''19# release: pcb 2008020220# date: Mon Apr 26 18:25:23 201021# user: felipe (felipe,,,)22# host: simon23# To read pcb files, the pcb version (or the cvs source date) must be >= the file version24FileVersion[20070407]25PCB["" %d %d]26Grid[5000.000000 0 0 1]27Cursor[0 0 6.000000]28PolyArea[200000000.000000]29Thermal[0.500000]30DRC[1000 1000 1000 1000 1500 1000]31Flags("rubberband,nameonpcb,autodrc,orthomove")32Groups("1,2,3,s:4,5,6,c:s:c")33Styles["Signal,1000,4000,2000,1000:Power,2500,6000,3500,1000:Fat,4000,6000,3500,1000:Skinny,800,3600,2000,1000"]34''' % (max_width, max_height))35def output_dot(fp, dot_id, x,y):36 fp.write(37'''38Element["" "a_dot" "D%d" "" %d %d 7600 59000 1 150 ""]39(40 Pin[0 0 11000 3000 14000 4800 "1" "1" ""]41 )42''' % (dot_id, x, y))43def output_pair(fp, dot_id, x,y):44 fp.write(45'''46Element["" "a_pair" "P%d" "" %d %d 7600 59000 1 150 ""]47(48 Pin[0 0 11000 3000 14000 4800 "1" "1" ""]49 Pin[0 38800 11000 3000 14000 4800 "2" "2" ""]50 )51''' % (dot_id, x, y))52def output_layers(fp):53 fp.write(54'''55Layer(4 "component")56(57)58Layer(7 "silk")59(60)61''')62def output_netlist(fp, netlist):63 fp.write("\nNetList()\n(\n")64 for k in netlist.keys():65 fp.write('\tNet("net%d" "(unknown)")\n\t(\n' % (k))66 for el in netlist[k]:67 fp.write('\t\tConnect("D%d-1")\n' % (el))68 fp.write("\t)\n")69 fp.write(")\n")70import math71def hit(p, x,y):72 px,py = p73 d = math.sqrt((px-x)**2 + (py-y)**2)74 return d < via_diameter+spacing75points={}76def point_collision(x,y):77 global points78 x_key = int(x/via_diameter)79 y_key = int(y/via_diameter)80 key = x_key,y_key81 print x, y, key82 try:83 test = points[key]84 except KeyError:85 points[key]=[]86 for i in range(x_key-2,x_key+2):87 for j in range(y_key-2,y_key+2):88 try:89 for p in points[(i,j)]:90 if hit(p, x,y):91 if report_collisions:92 print "collision!"93 return True94 except KeyError:95 pass96 points[key].append((x,y))97 return False98#######################################99fp = open(filename, "w")100output_header(fp, max_width, max_height)101netlist = {}102for i in range(num_nets):103 netlist[i]=[]104from random import randint, random105def sort_square(w,h):106 x = randint(0, w-1)107 y = randint(0, h-1)108 return x,y109def sort_circle(xc,yc,radius):110 r = random() * radius111 alpha = random()*2*3.1415112 x = xc + r*math.cos(alpha)113 y = yc + r*math.sin(alpha)114 return x,y115def sort_circle_homogeneous(xc,yc,radius):116 x,y = sort_square(2*radius,2*radius)117 while radius < math.sqrt((x-xc)**2 + (y-yc)**2):118 x,y = sort_square(2*radius,2*radius)119 return x,y120for dot_id in range(num_dots):121 net = randint(0, num_nets-1)122 netlist[net].append(dot_id)123# x,y = sort_square(max_width, max_height)124# while point_collision(x,y):125# x,y = sort_square(max_width, max_height)126 xc, yc = max_width/2, max_height/2127 if xc < yc:128 radius = xc129 else:130 radius = yc131# x,y=sort_circle(xc, yc, radius)132# while point_collision(x,y):133# x,y=sort_circle(xc, yc, radius)134 x,y=sort_circle_homogeneous(xc, yc, radius)135 while point_collision(x,y):136 x,y=sort_circle_homogeneous(xc, yc, radius)137 output_dot(fp, dot_id, x, y)138output_layers(fp)139output_netlist(fp, netlist)...
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!!