Advertisement
UgoDonini

WordNoWarNuovaVersione_19_03_2022

Mar 19th, 2022 (edited)
1,107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.94 KB | None | 0 0
  1. # WORD NO WAR
  2. # NUOVA VERSIONE 19/03/2022
  3. # PER ATTIVARE IL CODICE CLICK SULLA FRECCETTA NERA A SINISTRA NELLA FINESTRA SUCCESSIVA
  4. # potete cambiare questi valori per cambiare il colore
  5. #schema del colore: (Blu,Verde,Rosso)
  6. # I VALORI DEI COLORI SI TROVANO IN : https://www.rapidtables.org/it/web/color/RGB_Color.html
  7. # ATTENZIONE: QUI I COLORI SONO IN RGB (ROSSO, VERDE, BLU)
  8. # QUANDO SI COPIANO I VALORI NEL CODICE QUI SOTTO BISOGNA RICORDARSI CHE QUI LO SCHEMA è: BLU, VERDE, ROSSO
  9.  
  10.  
  11.  
  12. ######################## CAMBIANDO QUESTI VALORI SI OTTENGONO RISULTATI DIVERSI #####################################################
  13. ######################## 更改这些值的结果不同 #########################################################################################
  14. COLORE_1=(255,255,153) # (BLU, VERDE, ROSSO) # (蓝色、绿色、红色)
  15. COLORE_2=(0,255,0) # (BLU, VERDE, ROSSO) # (蓝色、绿色、红色)
  16. verso=-1 # con questo valore a -1 le macchie salgono anzichè scendere ### 当这个值为-1时,斑点会上升而不是下降。 ###
  17. ######################################################################################################################################
  18.  
  19.  
  20. if verso > 1:
  21.     verso=1
  22. elif verso <-1:
  23.     verso=-1
  24.  
  25.  
  26. import os
  27. S=os.system
  28. S('clear')
  29. # NON SON RIUSCITO A FARE FUNZIONARE : cv.destroyAllWindows()
  30. from google.colab import output
  31. import random
  32. import cv2 as cv
  33. import pandas as pd
  34. from google.colab.patches import cv2_imshow
  35. import requests
  36. import time
  37. import numpy as np
  38. DIR=os.listdir
  39. p=print
  40. vedi_G=cv2_imshow
  41. v=vedi_G # sul pc usare v=cv.imshow
  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. def azione(im_test,refresh=0.5, loop1=1):
  55.     y_max,x_max=im_test.shape[:2]
  56.     for i in range (loop1):
  57.         ############S('clear')
  58.         im_da_vedere=im_test.copy()
  59.         #output.clear()
  60.         #############################v(im_da_vedere)
  61.         #cv.waitKey()
  62.         time.sleep(refresh)
  63.         del(im_da_vedere)
  64.         S('clear')
  65.         cv.destroyAllWindows()
  66.         ####################cv.pollKey() # da usare sul pc
  67.        
  68.         ################time.sleep(0.3)
  69.         y=random.randint(100, (y_max-100))
  70.  
  71.         x=random.randint(100, (x_max-100))
  72.  
  73.         #p(y,x)
  74.  
  75.        
  76.  
  77.        
  78.         for j in range(loop2):
  79.             dx=random.randint(1,30)
  80.             dy=random.randint(1,80)*verso
  81.             if verso<0:
  82.                 Y=random.randint(y+dy,y)
  83.             else:
  84.                 Y=random.randint(y, y+dy)
  85.  
  86.             X=random.randint(x, x+dx)
  87.            
  88.             if X<0:
  89.                 X=2
  90.             if Y<0:
  91.                 Y=2
  92.  
  93.             try:
  94.                 im_test[Y,X]=COLORE_1
  95.                 #v(im_test)
  96.                 #time.sleep(.3)
  97.                 #cv.destroyAllWindows()
  98.             except:
  99.                 p('err1')
  100.  
  101.  
  102.         for j in range(loop2):
  103.             dx=random.randint(1,15)
  104.             dy=random.randint(1,120)*verso
  105.  
  106.             if verso<0:
  107.                 Y2=random.randint(Y+dy,Y)
  108.             else:
  109.                 Y2=random.randint(Y, Y+dy)
  110.  
  111.             X2=random.randint(X, X+dx)
  112.            
  113.             if X2<0:
  114.                 X2=2
  115.             if Y2<0:
  116.                 Y2=2
  117.  
  118.             if Y2>y_max:
  119.                 Y2=y_max-1
  120.  
  121.             X2=random.randint(X, X+dx)
  122.             if X2>x_max:
  123.                 X2=x_max-1
  124.  
  125.            
  126.             try:
  127.                 im_test[Y2,X2]=COLORE_2
  128.                 #v(im_test)
  129.                 #time.sleep(.3)
  130.                 #cv.destroyAllWindows()
  131.             except:
  132.                 p('err2')
  133.  
  134.     return im_test
  135.  
  136.  
  137.  
  138. # carico immagine PUTIN
  139. # definisco url con immagine
  140.  
  141. image_url='https://imagizer.imageshack.com/img922/6258/HS0BOM.jpg'
  142. # definisco la fullpat dove voglio salvare l'immagine
  143. fl_dest_fullpat='test/Putin_06.jpg'
  144. import requests
  145. # METODO NOTEVOLE
  146. # USO IL MIO REPOSITORY DDI IMMAGINI imageshack
  147. # COPIO IL LINK DIRECT: IN QUESTO CASO: https://imagizer.imageshack.com/img922/6258/HS0BOM.jpg
  148. # LO UTILIZZO QUI IN QUESTO MODO CON requests
  149. # salvo il file sul mio hd
  150. # carico il file sul mio script
  151. # FATTO
  152. # da fare: TROVARE UN MODO DIRETTO SENZA PASSARE DA SALVATAGGIO SU DISCO
  153. # carico immagine da url
  154. ###image_url='https://imagizer.imageshack.com/img922/6258/HS0BOM.jpg'
  155. # URL of the image to be downloaded is defined as image_url
  156. r = requests.get(image_url) # create HTTP response object
  157. # send a HTTP request to the server and save
  158. # the HTTP response in a response object called r
  159. # salvo immagine recuperata da url in fl_dest_fullpat
  160. with open(fl_dest_fullpat,'wb') as f: # scrittura binaria
  161.     # Saving received content as a png file in
  162.     # binary format
  163.     # write the contents of the response (r.content)
  164.     # to a new file in binary mode.
  165.     f.write(r.content)
  166.  # Ora ho l'immagine nel mio hard disk
  167.  # la posso caricare normalmente con cv.imread
  168. Immagine=cv.imread(fl_dest_fullpat)
  169. #FATTO
  170. #PERFETTO
  171.  
  172.  
  173. # quasi buono
  174. # TEST PUTIN
  175. # parametri per i cicli e per il random
  176. IM_PUTIN=Immagine.copy()
  177. y_max,x_max=(IM_PUTIN.shape[:2])
  178. p(y_max,x_max)
  179. y_max,x_max=(IM_PUTIN.shape[:2])
  180. IM_PUTIN_ELAB=IM_PUTIN[10:y_max-200,100:x_max-800]# ridimensionato
  181. #vedi_G(IM_PUTIN_ELAB)
  182.  
  183. #v(IM_PUTIN_ELAB)
  184. ############# obsoleto ########### im_test=IM_PUTIN_ELAB.copy()
  185. #IM_PUTIN.shapeim_test=IM_PUTIN_ELAB_01.copy()
  186.  
  187. ############# ZELENSKY ########################
  188. # ZELENSKY
  189. fl_dest_fullpat_zelensky='test/zelensky.jpg'
  190. image_url='https://imagizer.imageshack.com/img922/1461/JG7HGY.png'
  191. # URL of the image to be downloaded is defined as image_url
  192. r = requests.get(image_url) # create HTTP response object
  193. # send a HTTP request to the server and save
  194. # the HTTP response in a response object called r
  195. # salvo immagine recuperata da url in fl_dest_fullpat
  196. with open(fl_dest_fullpat_zelensky,'wb') as f: # scrittura binaria
  197.     # Saving received content as a png file in
  198.     # binary format
  199.     # write the contents of the response (r.content)
  200.     # to a new file in binary mode.
  201.     f.write(r.content)
  202.  # Ora ho l'immagine nel mio hard disk
  203.  # la posso caricare normalmente con cv.imread
  204. Immagine=cv.imread(fl_dest_fullpat_zelensky)
  205. ymax=Immagine.shape[0]
  206. xmax=Immagine.shape[1]
  207. rid_x=xmax//4
  208. rid_y=ymax//10
  209. IM_ZELENSKY=Immagine[rid_y:ymax-rid_y,rid_x+rid_x//3:xmax-rid_x+rid_x//4]
  210. IM_ZELENSKY_ELAB=IM_ZELENSKY[10:-56,27:-27]
  211.  
  212. ###############################################
  213.  
  214.  
  215. loop_tot=int(input("Numero di cicli desiderati (non esagerare COMINCIA CON 10): .... "))
  216. intervallo=float(input("Numero di secondi di intervallo (5-100): .... "))
  217. im_1=IM_PUTIN_ELAB
  218. im_2=IM_ZELENSKY_ELAB
  219.  
  220. for k in range(loop_tot):
  221.     #######################S('clear')
  222.     im_1=azione(im_1,intervallo)
  223.     im_2=azione(im_2,intervallo)
  224.     im_tot=np.concatenate([im_1,im_2],axis=1)
  225.     output.clear()
  226.     v(im_tot)
  227.     time.sleep(intervallo)
  228.  
  229.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement