UgoDonini

WordNoWarPerPC

Mar 10th, 2022 (edited)
506
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.73 KB | None | 0 0
  1. # PER ATTIVARE IL CODICE CLICK SULLA FRECCETTA NERA A SINISTRA NELLA FINESTRA SUCCESSIVA
  2. # potete cambiare questi valori per cambiare il colore
  3. #schema del colore: (Blu,Verde,Rosso)
  4. # I VALORI DEI COLORI SI TROVANO IN : https://www.rapidtables.org/it/web/color/RGB_Color.html
  5. # ATTENZIONE: QUI I COLORI SONO IN RGB (ROSSO, VERDE, BLU)
  6. # QUANDO SI COPIANO I VALORI NEL CODICE QUI SOTTO BISOGNA RICORDARSI CHE QUI LO SCHEMA è: BLU, VERDE, ROSSO
  7.  
  8.  
  9.  
  10. ######################## CAMBIANDO QUESTI VALORI SI OTTENGONO RISULTATI DIVERSI #####################################################à
  11. COLORE_1=(0,0,255) # (BLU, VERDE, ROSSO)
  12. COLORE_2=(0,0,139) # (BLU, VERDE, ROSSO)
  13. verso=1 # con questo valore a -1 le macchie salgono anzichè scendere
  14. ######################################################################################################################################
  15.  
  16.  
  17. if verso > 1:
  18.     verso=1
  19. elif verso <-1:
  20.     verso=-1
  21.  
  22.  
  23. import os
  24. S=os.system
  25. S('CLS')
  26. # NON SON RIUSCITO A FARE FUNZIONARE : cv.destroyAllWindows()
  27. ###################from google.colab import output
  28. import random
  29. import cv2 as cv
  30. import pandas as pd
  31. ###################from google.colab.patches import cv2_imshow
  32. import requests
  33. import time
  34.  
  35. DIR=os.listdir
  36. p=print
  37. #####################vedi_G=cv2_imshow
  38. #v=vedi_G # sul pc usare v=cv.imshow
  39. v=cv.imshow
  40.  
  41.  
  42. DIR()
  43. os.makedirs('test',exist_ok='True')
  44.  
  45. DIR()
  46.  
  47.  
  48. dy=80
  49. dx=10
  50.  
  51. #loop1=100 # aumentando questo valore si aumentano le macchie rosse
  52. loop2=500
  53.  
  54. # definisco url con immagine
  55.  
  56. image_url='https://imagizer.imageshack.com/img922/6258/HS0BOM.jpg'
  57. # definisco la fullpat dove voglio salvare l'immagine
  58. fl_dest_fullpat='test/Putin_06.jpg'
  59. import requests
  60. # METODO NOTEVOLE
  61. # USO IL MIO REPOSITORY DDI IMMAGINI imageshack
  62. # COPIO IL LINK DIRECT: IN QUESTO CASO: https://imagizer.imageshack.com/img922/6258/HS0BOM.jpg
  63. # LO UTILIZZO QUI IN QUESTO MODO CON requests
  64. # salvo il file sul mio hd
  65. # carico il file sul mio script
  66. # FATTO
  67. # da fare: TROVARE UN MODO DIRETTO SENZA PASSARE DA SALVATAGGIO SU DISCO
  68. # carico immagine da url
  69. image_url='https://imagizer.imageshack.com/img922/6258/HS0BOM.jpg'
  70. # URL of the image to be downloaded is defined as image_url
  71. r = requests.get(image_url) # create HTTP response object
  72. # send a HTTP request to the server and save
  73. # the HTTP response in a response object called r
  74. # salvo immagine recuperata da url in fl_dest_fullpat
  75. with open(fl_dest_fullpat,'wb') as f: # scrittura binaria
  76.     # Saving received content as a png file in
  77.     # binary format
  78.     # write the contents of the response (r.content)
  79.     # to a new file in binary mode.
  80.     f.write(r.content)
  81.  # Ora ho l'immagine nel mio hard disk
  82.  # la posso caricare normalmente con cv.imread
  83. Immagine=cv.imread(fl_dest_fullpat)
  84. #FATTO
  85. #PERFETTO
  86.  
  87.  
  88. # quasi buono
  89. # TEST PUTIN
  90. # parametri per i cicli e per il random
  91. IM_PUTIN=Immagine.copy()
  92. y_max,x_max=(IM_PUTIN.shape[:2])
  93. p(y_max,x_max)
  94. y_max,x_max=(IM_PUTIN.shape[:2])
  95. IM_PUTIN_ELAB=IM_PUTIN[10:y_max-200,100:x_max-800]# ridimensionato
  96. #vedi_G(IM_PUTIN_ELAB)
  97.  
  98. #v(IM_PUTIN_ELAB)
  99. im_test=IM_PUTIN_ELAB.copy()
  100. #IM_PUTIN.shapeim_test=IM_PUTIN_ELAB_01.copy()
  101.  
  102. y_max,x_max=im_test.shape[:2]
  103.  
  104. def azione(refresh=0.3, loop1=10):
  105.     for i in range (loop1):
  106.         S('CLS')
  107.         im_da_vedere=im_test.copy()
  108.         #output.clear()
  109.         ################v(im_da_vedere)
  110.         v('PUTIN', im_da_vedere)
  111.         cv.pollKey()
  112.         #cv.waitKey()
  113.         time.sleep(refresh)
  114.         del(im_da_vedere)
  115.         S('CLS')
  116.         cv.destroyAllWindows()
  117.         ####################cv.pollKey() # da usare sul pc
  118.        
  119.         ################time.sleep(0.3)
  120.         y=random.randint(80, (y_max-130))
  121.  
  122.         x=random.randint(80, (x_max-130))
  123.  
  124.         #p(y,x)
  125.  
  126.        
  127.  
  128.        
  129.         for j in range(loop2):
  130.             dx=random.randint(1,16)
  131.             dy=random.randint(1,80)*verso
  132.             if verso<0:
  133.                 Y=random.randint(y+dy,y)
  134.             else:
  135.                 Y=random.randint(y, y+dy)
  136.  
  137.             X=random.randint(x, x+dx)
  138.            
  139.             if X<0:
  140.                 X=2
  141.             if Y<0:
  142.                 Y=2
  143.  
  144.             try:
  145.                 im_test[Y,X]=COLORE_1
  146.                 #v(im_test)
  147.                 #time.sleep(.3)
  148.                 #cv.destroyAllWindows()
  149.             except:
  150.                 p('err1')
  151.  
  152.  
  153.         for j in range(loop2):
  154.             dx=random.randint(1,7)
  155.             dy=random.randint(1,120)*verso
  156.  
  157.             if verso<0:
  158.                 Y2=random.randint(Y+dy,Y)
  159.             else:
  160.                 Y2=random.randint(Y, Y+dy)
  161.  
  162.             X2=random.randint(X, X+dx)
  163.            
  164.             if X2<0:
  165.                 X2=2
  166.             if Y2<0:
  167.                 Y2=2
  168.  
  169.             if Y2>y_max:
  170.                 Y2=y_max-1
  171.  
  172.             X2=random.randint(X, X+dx)
  173.             if X2>x_max:
  174.                 X2=x_max-1
  175.  
  176.            
  177.             try:
  178.                 im_test[Y2,X2]=COLORE_2
  179.                 #v(im_test)
  180.                 #time.sleep(.3)
  181.                 #cv.destroyAllWindows()
  182.             except:
  183.                 p('err2')
  184.  
  185. #output.clear()
  186. loop=int(input("Numero di cicli desiderati (non esagerare COMINCIA CON 10): .... "))
  187. intervallo=float(input("Numero di secondi di intervallo (.5-100): .... "))
  188. #output.clear()
  189. #######################S('clear')
  190.  
  191. #p('Vedi output nella cella successiva alla fine dello script')
  192. p('\n\n\n\t\t\tATTENZIONE: dopo lo start cerca l\'immagine con ALT-TAB \n\n')
  193. input('\nn\n\t\t\tPremi un tasto qualsiasi per continuare')
  194. time.sleep(.8)
  195.  
  196. azione(intervallo, loop)
  197. v('PUTIN. Premi un tasto per ciudere',im_test)
  198. cv.waitKey(0)
  199. cv.destroyAllWindows()
  200.  
  201. # DA FARE
  202. # TROVARE IL MODO DI MANTENERE L'OUTPUT IN FULL SCREEN
  203.  
  204.  
Add Comment
Please, Sign In to add comment