Created
September 17, 2020 17:09
-
-
Save gogvale/9ac1de45caa9fa4ff2e702182a694c6d to your computer and use it in GitHub Desktop.
Tarea 1 Sistemas Adaptativos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Tarea1.zip | |
import sys | |
from random import randrange | |
from math import sqrt | |
def explotar(posx = 400, posy = 400, radio = 400): | |
print(f"Coordenadas de la explosión ({posx},{posy}) Radio: {radio}") | |
def secuencia_explosiones(posx = 400, posy = 400, radio = 400): | |
for i in range(1,4): | |
posy = 420+i | |
explotar(posx,posy,radio) | |
def explosiones_al_azar(): | |
if len(sys.argv) == 1: | |
print("Pasar al menos una argumento") | |
else: | |
cant = int(sys.argv[1]) | |
for i in range (0,cant): | |
rposx = randrange(start=1, stop=400) | |
rposy = randrange(start=1, stop=400) | |
rradio = randrange(start=1, stop=399) | |
explotar(rposx, rposy, rradio) | |
def diferencia_vectores(a,b): | |
return sqrt( (a[0]-b[0])**2 + (a[1]-b[1])**2 + (a[2]-b[2])**2 ) | |
def explosion_colores(rgb): | |
red = [255,0,0] | |
green = [0,255,0] | |
blue = [0,0,255] | |
codigo_colores = {"Rojo":0,"Verde":1,"Azul":2} | |
distancia_red = diferencia_vectores(rgb,red) | |
distancia_green = diferencia_vectores(rgb,green) | |
distancia_blue = diferencia_vectores(rgb,blue) | |
menor_distancia = min([distancia_red,distancia_green,distancia_blue]) | |
if menor_distancia == distancia_red: | |
color = "Rojo" | |
elif menor_distancia == distancia_green: | |
color = "Verde" | |
else: | |
color = "Azul" | |
print( f"{rgb}\t{color}") | |
return codigo_colores[color] | |
if __name__ == "__main__": | |
print("a)") | |
explotar(200,200,300) | |
explotar(300,200,399) | |
explotar(100,400,40) | |
print("b)") | |
secuencia_explosiones() | |
print("c)") | |
explosiones_al_azar() | |
print("d)") | |
colores = [ | |
[153,51,255], | |
[121,236,221], | |
[209,236,121], | |
[240,164,76], | |
[240,98,76], | |
[76,93,240], | |
[50,239,94] | |
] | |
valores_centroides=[[],[],[]] | |
for i in colores: | |
valores_centroides[explosion_colores(i)].append(i) | |
print("") | |
for n, valores in enumerate(valores_centroides): | |
a = [0,0,0] | |
for j in valores: | |
a[0] += j[0] | |
a[1] += j[1] | |
a[2] += j[2] | |
print(f"centroide {n+1}: {list(map(lambda x: x/len(valores),a))}") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment