Best Python code snippet using yandex-tank
ledPanel.py
Source:ledPanel.py
...110 latch()111 GPIO.output(oe_pin, 0)112 time.sleep(delay)113 114def fill_rectangle(x1, y1, x2, y2, color):115 for x in range(x1, x2):116 for y in range(y1, y2):117 screen[y][x] = color118 119 120def set_pixel(x, y, color):121 screen[y][x] = color122 123#fill_rectangle(0, 0, 12, 12, 1)124#fill_rectangle(20, 4, 30, 15, 2)125#fill_rectangle(15, 0, 19, 7, 7)126##################################################################127#first digit128anothercounter = 0129trigger = 0130while True: 131 with open("led_alarms.txt") as f:132 alarmlist = f.readlines()133 with open("led_sleepquality.txt") as f:134 sleepqlist = f.readlines()135 currentdate = time.strftime("%Y-%m-%d")136 currenttime = time.strftime("%I:%M %p")137 currentdateandtime = time.strftime("%m/%d/%Y %I:%M %p")138 #changes color of alarm if alarm goes off139 for alarms in alarmlist:140 print currentdateandtime, alarms141 if currentdateandtime.strip() == alarms.strip():142 anothercounter = anothercounter + 1143 trigger = 1144 if trigger:145 if anothercounter%1 == 0:146 colortochange = (colortochange + 1) % 4147 if colortochange == 0:148 colortochange = 1149 if "2014" in currentdate:150 listofcurrentsleepquality = []151 for listofsleepquality in sleepqlist:152 if currentdate in listofsleepquality:153 sleepquality = listofsleepquality.split(" ")154 if "09" in sleepquality[1]:155 if "rem" in sleepquality[2]:156 hr1 = good157 elif "light" in sleepquality[2]:158 hr1 = okay159 else:160 hr1 = bad161 if "10" in sleepquality[1]:162 if "rem" in sleepquality[2]:163 hr2 = good164 elif "light" in sleepquality[2]:165 hr2 = okay166 else:167 hr2 = bad 168 if "11" in sleepquality[1]:169 if "rem" in sleepquality[2]:170 hr3 = good171 elif "light" in sleepquality[2]:172 hr3 = okay173 else:174 hr3 = bad175 if "12" in sleepquality[1]:176 if "rem" in sleepquality[2]:177 hr4 = good178 elif "light" in sleepquality[2]:179 hr4 = okay180 else:181 hr4 = bad182 if "13" in sleepquality[1]:183 if "rem" in sleepquality[2]:184 hr5 = good185 elif "light" in sleepquality[2]:186 hr5 = okay187 else:188 hr5 = bad 189 if "14" in sleepquality[1]:190 if "rem" in sleepquality[2]:191 hr6 = good192 elif "light" in sleepquality[2]:193 hr6 = okay194 else:195 hr6 = bad196 if "15" in sleepquality[1]:197 if "rem" in sleepquality[2]:198 hr7 = good199 elif "light" in sleepquality[2]:200 hr7 = okay201 else:202 hr7 = bad203 if "16" in sleepquality[2]:204 if "rem" in sleepquality:205 hr8 = good206 elif "light" in sleepquality[2]:207 hr8 = okay208 else:209 hr8 = bad 210 if "17" in sleepquality[1]:211 if "rem" in sleepquality[2]:212 hr9 = good213 elif "light" in sleepquality[2]:214 hr9 = okay215 else:216 hr9 = bad217 if "18" in sleepquality[1]:218 if "rem" in sleepquality[2]:219 hr10 = good220 elif "light" in sleepquality[2]:221 hr10 = okay222 else:223 hr10 = bad224 if "19" in sleepquality[1]:225 if "rem" in sleepquality[2]:226 hr11 = good227 elif "light" in sleepquality[2]:228 hr11 = okay229 else:230 hr11 = bad 231 if "20" in sleepquality[1]:232 if "rem" in sleepquality[2]:233 hr12 = good234 elif "light" in sleepquality[2]:235 hr12 = okay236 else:237 hr12 = bad238 hour = time.strftime("%I")239 minute = time.strftime("%M")240 if hour < 10:241 hrLeft = 0242 hrRight = int(hour[1])243 else:244 hrLeft = int(hour[0])245 hrRight = int(hour[1])246 247 minLeft = int(minute[0])248 minRight = int(minute[1])249 250 print hrLeft, hrRight, minLeft, minRight 251 if(hrLeft == 1):252 fill_rectangle(25, 13, 31, 15, 0) # top -253 fill_rectangle(25, 9, 31, 11, 0) # mid -254 fill_rectangle(29, 9, 31, 15, 0) # left top |255 fill_rectangle(29, 5, 31, 11, 0) # bottom left |256 fill_rectangle(25, 5, 31, 7, 0) # bottom -257 fill_rectangle(25, 5, 27, 11, colortochange) # bottom right |258 fill_rectangle(25, 9, 27, 15, colortochange) # right top |259 elif(hrLeft == 0):260 fill_rectangle(25, 9, 31, 11, 0) # mid -261 fill_rectangle(25, 13, 31, 15, colortochange) # top -262 fill_rectangle(25, 9, 27, 15, colortochange) # right top |263 fill_rectangle(29, 9, 31, 15, colortochange) # left top |264 fill_rectangle(25, 5, 27, 11, colortochange) # bottom right |265 fill_rectangle(29, 5, 31, 11, colortochange) # bottom left |266 fill_rectangle(25, 5, 31, 7, colortochange) # bottom -267 268#fill_rectangle(27, 5, 29, 15, 1) #1269#fill_rectangle(25, 13, 31, 15, 1) # top -270#fill_rectangle(25, 9, 27, 15, 1) # right top |271#fill_rectangle(25, 9, 31, 11, 1) # mid -272#fill_rectangle(29, 9, 31, 15, 1) # left top |273#fill_rectangle(25, 5, 27, 11, 1) # bottom right |274#fill_rectangle(29, 5, 31, 11, 1) # bottom left |275#fill_rectangle(25, 5, 31, 7, 1) # bottom -276##################################################################277 if(hrRight == 1):278 fill_rectangle(18, 13, 24, 15, 0) # top - 279 fill_rectangle(18, 9, 24, 11, 0) # mid -280 fill_rectangle(22, 9, 24, 15, 0) # top left |281 fill_rectangle(22, 5, 24, 11, 0) # bottom left |282 fill_rectangle(18, 5, 24, 7, 0) # bottom -283 284 fill_rectangle(18, 9, 20, 15, colortochange) # top right |285 fill_rectangle(18, 5, 20, 11, colortochange) # bottom right |286 elif(hrRight == 2): 287 fill_rectangle(22, 9, 24, 15, 0) # top left |288 fill_rectangle(18, 5, 20, 11, 0) # bottom right |289 290 fill_rectangle(18, 13, 24, 15, colortochange) # top -291 fill_rectangle(18, 9, 20, 15, colortochange) # top right |292 fill_rectangle(18, 9, 24, 11, colortochange) # mid -293 fill_rectangle(22, 5, 24, 11, colortochange) # bottom left |294 fill_rectangle(18, 5, 24, 7, colortochange) # bottom -295 elif(hrRight == 3):296 fill_rectangle(22, 9, 24, 15, 0) # top left |297 fill_rectangle(22, 5, 24, 11, 0) # bottom left |298 299 fill_rectangle(18, 13, 24, 15, colortochange) # top -300 fill_rectangle(18, 9, 20, 15, colortochange) # right top |301 fill_rectangle(18, 9, 24, 11, colortochange) # mid -302 fill_rectangle(18, 5, 20, 11, colortochange) # bottom right |303 fill_rectangle(18, 5, 24, 7, colortochange) # bottom -304 elif(hrRight == 4): 305 fill_rectangle(18, 13, 24, 15, 0) # top -306 fill_rectangle(22, 5, 24, 11, 0) # bottom left |307 fill_rectangle(18, 5, 24, 7, 0) # bottom -308 309 fill_rectangle(18, 9, 20, 15, colortochange) # right top |310 fill_rectangle(18, 9, 24, 11, colortochange) # mid -311 fill_rectangle(22, 9, 24, 15, colortochange) # top left |312 fill_rectangle(18, 5, 20, 11, colortochange) # bottom right |313 elif(hrRight == 5): 314 fill_rectangle(22, 5, 24, 11, 0) # bottom left |315 fill_rectangle(18, 9, 20, 15, 0) # right top |316 317 fill_rectangle(18, 13, 24, 15, colortochange) # top -318 fill_rectangle(18, 9, 24, 11, colortochange) # mid -319 fill_rectangle(22, 9, 24, 15, colortochange) # top left |320 fill_rectangle(18, 5, 20, 11, colortochange) # bottom right |321 fill_rectangle(18, 5, 24, 7, colortochange) # bottom - 322 elif(hrRight == 6):323 fill_rectangle(22, 9, 24, 15, 0) # top left |324 325 fill_rectangle(18, 13, 24, 15, colortochange) # top -326 fill_rectangle(18, 9, 20, 15, colortochange) # right top |327 fill_rectangle(18, 9, 24, 11, colortochange) # mid -328 fill_rectangle(18, 5, 20, 11, colortochange) # bottom right |329 fill_rectangle(22, 5, 24, 11, colortochange) # bottom left |330 fill_rectangle(18, 5, 24, 7, colortochange) # bottom -331 elif(hrRight == 7):332 fill_rectangle(18, 9, 24, 11, 0) # mid -333 fill_rectangle(22, 9, 24, 15, 0) # top left |334 fill_rectangle(22, 5, 24, 11, 0) # bottom left |335 fill_rectangle(18, 5, 24, 7, 0) # bottom -336 337 fill_rectangle(18, 13, 24, 15, colortochange) # top -338 fill_rectangle(18, 9, 20, 15, colortochange) # right top 339 fill_rectangle(18, 5, 20, 11, colortochange) # bottom right |340 elif(hrRight == 8):341 fill_rectangle(18, 13, 24, 15, colortochange) # top -342 fill_rectangle(18, 9, 20, 15, colortochange) # right top |343 fill_rectangle(18, 9, 24, 11, colortochange) # mid -344 fill_rectangle(22, 9, 24, 15, colortochange) # top left |345 fill_rectangle(18, 5, 20, 11, colortochange) # bottom right |346 fill_rectangle(22, 5, 24, 11, colortochange) # bottom left |347 fill_rectangle(18, 5, 24, 7, colortochange) # bottom -348 elif(hrRight == 9):349 fill_rectangle(22, 5, 24, 11, 0) # bottom left |350 351 fill_rectangle(18, 13, 24, 15, colortochange) # top -352 fill_rectangle(18, 9, 20, 15, colortochange) # right top |353 fill_rectangle(18, 9, 24, 11, colortochange) # mid -354 fill_rectangle(22, 9, 24, 15, colortochange) # top left |355 fill_rectangle(18, 5, 20, 11, colortochange) # bottom right |356 fill_rectangle(18, 5, 24, 7, colortochange) # bottom -357 elif(hrRight == 0):358 fill_rectangle(18, 9, 24, 11, 0) # mid -359 360 fill_rectangle(18, 13, 24, 15, colortochange) # top -361 fill_rectangle(18, 9, 20, 15, colortochange) # right top |362 fill_rectangle(22, 9, 24, 15, colortochange) # top left |363 fill_rectangle(18, 5, 20, 11, colortochange) # bottom right |364 fill_rectangle(22, 5, 24, 11, colortochange) # bottom left |365 fill_rectangle(18, 5, 24, 7, colortochange) # bottom -366 367#2 x y x y368#fill_rectangle(18, 13, 24, 15, colortochange) # top -369#fill_rectangle(18, 9, 20, 15, colortochange) # right top |370#fill_rectangle(18, 9, 24, 11, colortochange) # mid -371#fill_rectangle(22, 9, 24, 15, colortochange) # top left |372#fill_rectangle(18, 5, 20, 11, colortochange) # bottom right |373#fill_rectangle(22, 5, 24, 11, colortochange) # bottom left |374#fill_rectangle(18, 5, 24, 7, colortochange) # bottom -375#dots376 fill_rectangle(15, 11, 17, 13, colortochange)377 fill_rectangle(15, 7, 17, 9, colortochange)378###################################################################379 if(minLeft == 1):380 fill_rectangle(8, 13, 14, 15, 0) # top -381 fill_rectangle(8, 9, 14, 11, 0) # mid -382 fill_rectangle(12, 9, 14, 15, 0) # left top |383 fill_rectangle(12, 5, 14, 11, 0) # bottom left |384 fill_rectangle(8, 5, 14, 7, 0) #bottom -385 386 fill_rectangle(8, 9, 10, 15, colortochange) # right top |387 fill_rectangle(8, 5, 10, 11, colortochange) # bottom right |388 elif(minLeft == 2):389 fill_rectangle(12, 9, 14, 15, 0) # left top |390 fill_rectangle(8, 5, 10, 11, 0) # bottom right |391 392 fill_rectangle(8, 13, 14, 15, colortochange) # top -393 fill_rectangle(8, 9, 10, 15, colortochange) # right top |394 fill_rectangle(8, 9, 14, 11, colortochange) # mid -395 fill_rectangle(12, 5, 14, 11, colortochange) # bottom left |396 fill_rectangle(8, 5, 14, 7, colortochange) #bottom -397 elif(minLeft == 3):398 fill_rectangle(12, 5, 14, 11, 0) # bottom left |399 fill_rectangle(12, 9, 14, 15, 0) # left top |400 401 fill_rectangle(8, 13, 14, 15, colortochange) # top -402 fill_rectangle(8, 9, 10, 15, colortochange) # right top |403 fill_rectangle(8, 9, 14, 11, colortochange) # mid -404 fill_rectangle(8, 5, 10, 11, colortochange) # bottom right |405 fill_rectangle(8, 5, 14, 7, colortochange) #bottom -406 elif(minLeft == 4):407 fill_rectangle(8, 13, 14, 15, 0) # top -408 fill_rectangle(12, 5, 14, 11, 0) # bottom left |409 fill_rectangle(8, 5, 14, 7, 0) #bottom - 410 411 fill_rectangle(8, 9, 10, 15, colortochange) # right top |412 fill_rectangle(8, 9, 14, 11, colortochange) # mid -413 fill_rectangle(12, 9, 14, 15, colortochange) # left top |414 fill_rectangle(8, 5, 10, 11, colortochange) # bottom right |415 elif(minLeft == 5):416 fill_rectangle(12, 5, 14, 11, 0) # bottom left |417 fill_rectangle(8, 9, 10, 15, 0) # right top |418 419 fill_rectangle(8, 13, 14, 15, colortochange) # top -420 fill_rectangle(8, 9, 14, 11, colortochange) # mid -421 fill_rectangle(12, 9, 14, 15, colortochange) # left top |422 fill_rectangle(8, 5, 10, 11, colortochange) # bottom right |423 fill_rectangle(8, 5, 14, 7, colortochange) #bottom -424 elif(minLeft == 6):425 fill_rectangle(8, 9, 10, 15, 0) # right top |426 427 fill_rectangle(8, 13, 14, 15, colortochange) # top -428 fill_rectangle(8, 9, 14, 11, colortochange) # mid -429 fill_rectangle(12, 9, 14, 15, colortochange) # left top |430 fill_rectangle(8, 5, 10, 11, colortochange) # bottom right |431 fill_rectangle(12, 5, 14, 11, colortochange) # bottom left |432 fill_rectangle(8, 5, 14, 7, colortochange) #bottom -433 elif(minLeft == 7):434 fill_rectangle(12, 9, 14, 15, 0) # left top |435 fill_rectangle(12, 5, 14, 11, 0) # bottom left |436 fill_rectangle(8, 5, 14, 7, 0) #bottom -437 438 fill_rectangle(8, 5, 10, 11, colortochange) # bottom right |439 fill_rectangle(8, 13, 14, 15, colortochange) # top -440 fill_rectangle(8, 9, 10, 15, colortochange) # right top |441 fill_rectangle(8, 9, 14, 11, colortochange) # mid -442 elif(minLeft == 8):443 fill_rectangle(8, 13, 14, 15, colortochange) # top -444 fill_rectangle(8, 9, 10, 15, colortochange) # right top |445 fill_rectangle(8, 9, 14, 11, colortochange) # mid -446 fill_rectangle(12, 9, 14, 15, colortochange) # left top |447 fill_rectangle(8, 5, 10, 11, colortochange) # bottom right |448 fill_rectangle(12, 5, 14, 11, colortochange) # bottom left |449 fill_rectangle(8, 5, 14, 7, colortochange) #bottom -450 elif(minLeft == 9):451 fill_rectangle(12, 5, 14, 11, 0) # bottom left |452 453 fill_rectangle(8, 13, 14, 15, colortochange) # top -454 fill_rectangle(8, 9, 10, 15, colortochange) # right top |455 fill_rectangle(8, 9, 14, 11, colortochange) # mid -456 fill_rectangle(12, 9, 14, 15, colortochange) # left top |457 fill_rectangle(8, 5, 10, 11, colortochange) # bottom right |458 fill_rectangle(8, 5, 14, 7, colortochange) #bottom -459 elif(minLeft == 0):460 fill_rectangle(8, 9, 14, 11, 0) # mid -461 462 fill_rectangle(8, 13, 14, 15, colortochange) # top -463 fill_rectangle(8, 9, 10, 15, colortochange) # right top |464 fill_rectangle(12, 9, 14, 15, colortochange) # left top |465 fill_rectangle(8, 5, 10, 11, colortochange) # bottom right |466 fill_rectangle(12, 5, 14, 11, colortochange) # bottom left |467 fill_rectangle(8, 5, 14, 7, colortochange) #bottom -468 469#3 x y x y470#fill_rectangle(8, 13, 14, 15, colortochange) # top -471#fill_rectangle(8, 9, 10, 15, colortochange) # right top |472#fill_rectangle(8, 9, 14, 11, colortochange) # mid -473#fill_rectangle(12, 9, 14, 15, colortochange) # left top |474#fill_rectangle(8, 5, 10, 11, colortochange) # bottom right |475#fill_rectangle(12, 5, 14, 11, colortochange) # bottom left |476#fill_rectangle(8, 5, 14, 7, colortochange) #bottom -477####################################################################478 if(minRight == 1):479 fill_rectangle(1, 13, 7, 15, 0) # top480 481 fill_rectangle(1, 9, 7, 11, 0) # mid482 fill_rectangle(5, 9, 7, 15, 0) # top left | 483 fill_rectangle(5, 5, 7, 11, 0) # bottom left |484 fill_rectangle(1, 5, 7, 7, 0) # bottom -485 486 fill_rectangle(1, 9, 3, 15, colortochange) # top right |487 fill_rectangle(1, 5, 3, 11, colortochange) # bottom right |488 elif(minRight == 2):489 fill_rectangle(5, 9, 7, 15, 0) # top left | 490 fill_rectangle(1, 5, 3, 11, 0) # bottom right |491 492 fill_rectangle(1, 13, 7, 15, colortochange) # top493 fill_rectangle(1, 9, 3, 15, colortochange) # top right |494 fill_rectangle(1, 9, 7, 11, colortochange) # mid495 fill_rectangle(5, 5, 7, 11, colortochange) # bottom left |496 fill_rectangle(1, 5, 7, 7, colortochange) # bottom -497 elif(minRight == 3):498 fill_rectangle(5, 9, 7, 15, 0) # top left | 499 fill_rectangle(5, 5, 7, 11, 0) # bottom left |500 501 fill_rectangle(1, 13, 7, 15, colortochange) # top502 fill_rectangle(1, 9, 3, 15, colortochange) # top right |503 fill_rectangle(1, 9, 7, 11, colortochange) # mid504 fill_rectangle(1, 5, 3, 11, colortochange) # bottom right | 505 fill_rectangle(1, 5, 7, 7, colortochange) # bottom -506 elif(minRight == 4):507 fill_rectangle(1, 13, 7, 15, 0) # top508 fill_rectangle(5, 5, 7, 11, 0) # bottom left |509 fill_rectangle(1, 5, 7, 7, 0) # bottom -510 511 fill_rectangle(1, 9, 3, 15, colortochange) # top right |512 fill_rectangle(1, 9, 7, 11, colortochange) # mid513 fill_rectangle(5, 9, 7, 15, colortochange) # top left | 514 fill_rectangle(1, 5, 3, 11, colortochange) # bottom right |515 elif(minRight == 5):516 fill_rectangle(1, 9, 3, 15, 0) # top right |517 fill_rectangle(5, 5, 7, 11, 0) # bottom left |518 519 fill_rectangle(1, 13, 7, 15, colortochange) # top520 fill_rectangle(1, 9, 7, 11, colortochange) # mid521 fill_rectangle(5, 9, 7, 15, colortochange) # top left | 522 fill_rectangle(1, 5, 3, 11, colortochange) # bottom right |523 fill_rectangle(1, 5, 7, 7, colortochange) # bottom -524 elif(minRight == 6):525 fill_rectangle(1, 9, 3, 15, 0) # top right |526 fill_rectangle(1, 13, 7, 15, colortochange) # top527 fill_rectangle(1, 9, 7, 11, colortochange) # mid528 fill_rectangle(5, 9, 7, 15, colortochange) # top left | 529 fill_rectangle(1, 5, 3, 11, colortochange) # bottom right |530 fill_rectangle(5, 5, 7, 11, colortochange) # bottom left |531 fill_rectangle(1, 5, 7, 7, colortochange) # bottom -532 elif(minRight == 7):533 fill_rectangle(1, 9, 7, 11, 0) # mid534 fill_rectangle(5, 9, 7, 15, 0) # top left |535 fill_rectangle(5, 5, 7, 11, 0) # bottom left |536 fill_rectangle(1, 5, 7, 7, 0) # bottom -537 538 fill_rectangle(1, 13, 7, 15, colortochange) # top539 fill_rectangle(1, 9, 3, 15, colortochange) # top right |540 fill_rectangle(1, 5, 3, 11, colortochange) # bottom right |541 elif(minRight == 8):542 fill_rectangle(1, 13, 7, 15, colortochange) # top543 fill_rectangle(1, 9, 3, 15, colortochange) # top right |544 fill_rectangle(1, 9, 7, 11, colortochange) # mid545 fill_rectangle(5, 9, 7, 15, colortochange) # top left | 546 fill_rectangle(1, 5, 3, 11, colortochange) # bottom right |547 fill_rectangle(5, 5, 7, 11, colortochange) # bottom left |548 fill_rectangle(1, 5, 7, 7, colortochange) # bottom - 549 elif(minRight == 9):550 fill_rectangle(5, 5, 7, 11, 0) # bottom left |551 552 fill_rectangle(1, 13, 7, 15, colortochange) # top553 fill_rectangle(1, 9, 3, 15, colortochange) # top right |554 fill_rectangle(1, 9, 7, 11, colortochange) # mid555 fill_rectangle(5, 9, 7, 15, colortochange) # top left | 556 fill_rectangle(1, 5, 3, 11, colortochange) # bottom right |557 fill_rectangle(1, 5, 7, 7, colortochange) # bottom -558 elif(minRight == 0):559 fill_rectangle(1, 9, 7, 11, 0) # mid560 561 fill_rectangle(1, 13, 7, 15, colortochange) # top562 fill_rectangle(1, 9, 3, 15, colortochange) # top right |563 fill_rectangle(5, 9, 7, 15, colortochange) # top left | 564 fill_rectangle(1, 5, 3, 11, colortochange) # bottom right |565 fill_rectangle(5, 5, 7, 11, colortochange) # bottom left |566 fill_rectangle(1, 5, 7, 7, colortochange) # bottom -567 568#4 x y x y569#fill_rectangle(1, 13, 7, 15, colortochange) # top570#fill_rectangle(1, 9, 3, 15, colortochange) # top right |571#fill_rectangle(1, 9, 7, 11, colortochange) # mid572#fill_rectangle(5, 9, 7, 15, 3)# top left | 573#fill_rectangle(1, 5, 3, 11, colortochange) # bottom right |574#fill_rectangle(5, 5, 7, 11, colortochange) # bottom left |575#fill_rectangle(1, 5, 7, 7, colortochange) # bottom -576################################################################577 fill_rectangle(20, 0, 32, 1, hr1)578 fill_rectangle(20, 0, 31, 1, hr2)579 fill_rectangle(20, 0, 30, 1, hr3)580 fill_rectangle(20, 0, 29, 1, hr4)581 fill_rectangle(20, 0, 28, 1, hr5)582 fill_rectangle(20, 0, 27, 1, hr6)583 fill_rectangle(20, 0, 26, 1, hr7)584 fill_rectangle(20, 0, 25, 1, hr8)585 fill_rectangle(20, 0, 24, 1, hr9)586 fill_rectangle(20, 0, 23, 1, hr10)587 fill_rectangle(20, 0, 22, 1, hr11)588 fill_rectangle(20, 0, 21, 1, hr12)589 590 counter = 0591 while counter != 30: 592 refresh()...
fill_board.py
Source:fill_board.py
...4 for row in board:5 for cell in row:6 print markers[cell],7 print8def fill_rectangle(board, left, top, width, height, block):9 if width <= 0 or height <= 0:10 return block11 if height % 2 == 1:12 for x in xrange(left, left + width, 2):13 board[top][x] = board[top][x + 1] = block14 block += 115 top += 116 height -= 117 for y in xrange(top, top + height, 2):18 for x in xrange(left, left + width):19 board[y][x] = board[y + 1][x] = block20 block += 121 # print_board(board)22 # print '-' * 2023 return block24def fill_board(x1, y1, x2, y2):25 assert 0 <= x1 <= 7 and 0 <= y1 <= 7 and 0 <= x2 <= 7 and 0 <= y2 <= 726 if (x1 + y1) % 2 == (x2 + y2) % 2:27 return False28 n = 829 board = [[0] * n for _ in xrange(n)]30 block = 131 board[y1][x1] = board[y2][x2] = block32 block += 133 left = min(x1, x2)34 right = max(x1, x2)35 top = min(y1, y2)36 bottom = max(y1, y2)37 width = right - left + 138 height = bottom - top + 139 print (left, top), '-', (right, bottom)40 print width, 'x', height41 if (x1 == left and y1 == top) or (x2 == left and y2 == top):42 offset = (1, 0)43 else:44 offset = (0, 1)45 if height % 2 == 1:46 block = fill_rectangle(board, left, top + offset[0], 1, height - 1, block)47 block = fill_rectangle(board, right, top + offset[1], 1, height - 1, block)48 block = fill_rectangle(board, left + 1, top, width - 2, height, block)49 block = fill_rectangle(board, left, 0, width, top, block)50 block = fill_rectangle(board, left, bottom + 1, width, n - bottom - 1, block)51 block = fill_rectangle(board, 0, 0, left, n, block)52 block = fill_rectangle(board, right + 1, 0, n - right - 1, n, block)53 else:54 block = fill_rectangle(board, left + offset[0], top, width - 1, 1, block)55 block = fill_rectangle(board, left + offset[1], bottom, width - 1, 1, block)56 block = fill_rectangle(board, left, top + 1, width, height - 2, block)57 block = fill_rectangle(board, 0, 0, n, top, block)58 block = fill_rectangle(board, 0, bottom + 1, n, n - bottom - 1, block)59 block = fill_rectangle(board, 0, top, left, height, block)60 block = fill_rectangle(board, right + 1, top, n - right - 1, height, block)61 return board62def demo():63 x1 = random.randint(0, 7)64 y1 = random.randint(0, 7)65 x2 = random.randint(0, 7)66 y2 = random.randint(0, 7)67 print (x1, y1), (x2, y2)68 board = fill_board(x1, y1, x2, y2)69 if board:70 print_board(board)71 else:...
main.py
Source:main.py
...15 if color in ['B', 'W', 'R', 'G']:16 self.image[y][x] = Pixel(color)17 else:18 raise ValueError('ÐведÑн непÑавилÑнÑй ÑвеÑ')19 def fill_rectangle(self, color: str, x1: int, y1: int, x2: int, y2: int):20 for self.x in range(x1 - 1, x2):21 for self.y in range(y1 - 1, y2):22 self.set_color(color, self.x, self.y)23 def __str__(self):24 img = ''25 for y in range(len(self.image)):26 for x in range(len(self.image[y])):27 img += self.image[y][x].color28 img += '\n'29 return img30img = Image(5, 7)31print(img)32img.fill_rectangle(color="B", x1=3, y1=3, x2=5, y2=7)33print(img)34img.fill_rectangle(color="W", x1=4, y1=5, x2=5, y2=7)35print(img)36img.fill_rectangle(color="W", x1=4, y1=5, x2=5, y2=7)37print(img)38img.fill_rectangle(color="W", x1=4, y1=5, x2=5, y2=7)39print(img)40img.fill_rectangle(color="W", x1=4, y1=5, x2=5, y2=7)41print(img)42img.fill_rectangle(color="W", x1=4, y1=5, x2=5, y2=7)43print(img)44img.fill_rectangle(color="W", x1=4, y1=5, x2=5, y2=7)...
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!!