id='PESAS' matriz='sí' evaluar='una-sola-vez' columnas='6' filas='20' expresión='X=0 //coordenada x;Y=1 //coordenada y;W=2 //ancho;TIPO=3 //tipo de pesa, &squot;1&squot; &squot;x&squot;;LADO=4 //posición de la pesa;VISIBLE=5 //determina si la pesa es visible o no;;//constantes para denotar el lado donde se encuentra una pesa;L_CEN=-1 //en el centro;L_IZQ= 0 //lado izquierdo;L_DER= 1 //lado derecho' tipo='matriz' info='Matriz para guardar la información de las pesas' 
id='initPesas()' algoritmo='sí' expresión='0' local='i;cond' inicio='i=0' hacer='cond=i<PESAS.filas/2;PESAS[i,X]=balanza.x;PESAS[i,Y]=balanza.y -((cond)?pesaUno.y:pesaX.y);PESAS[i,W]=(cond)?pesaUno.w:pesaX.w;PESAS[i,TIPO]=(cond)?&squot;1&squot;:&squot;x&squot;;PESAS[i,LADO]=L_CEN;PESAS[i,VISIBLE]=1;;i=i+1' mientras='i<PESAS.filas' tipo='función' info='Inicia los valores de las pesas' 
id='radianes(x)' algoritmo='no' expresión='pi*x/180' tipo='función' info='Convierte de grados a radianes' 
id='grados(x)' algoritmo='no' expresión='x*180/pi' tipo='función' info='Convierte de radianes a grados' 
id='selecciona(x,y)' algoritmo='sí' expresión='cual' local='cual;px;py;pw;ph;cond' inicio='i=0;cond=0' hacer='pw=PESAS[i,W];ph=pw;px=PESAS[i,X]-pw/2;py=PESAS[i,Y]-ph/2;;cond=(PESAS[i,VISIBLE])&&(px<=x)&&(x<=(px+pw))&&(py<=y)&&(y<=(py+ph));cual=(cond)?i:-1;(cond)?obtenerDesface(cual):NULL;;i=i+1' mientras='(cond==0)&&(i<PESAS.filas)' tipo='función' info='Encuenta el indice de la una pesa seleccionada con el mouse' 
id='obtenerDesface(cual)' algoritmo='sí' expresión='0' hacer='pesas_offset_x=PESAS[cual,X]-E1.mouse_x;pesas_offset_y=PESAS[cual,Y]+E1.mouse_y' tipo='función' info='Obtiene el desface entre la posición del click y la posicion de la pesa' 
id='arrastraPesa(cual)' algoritmo='sí' expresión='0' hacer='PESAS[cual,X]= E1.mouse_x+pesas_offset_x;PESAS[cual,Y]=-E1.mouse_y+pesas_offset_y' tipo='función' info='Cambia las coordenadas de la pesa ' 
id='colocaPesa(cual)' algoritmo='sí' expresión='0' hacer='PESAS[cual,LADO]=obtenerLado(cual);acomodaPesas()' tipo='función' info='Coloca una pesa en su lugar' 
id='obtenerLado(cual)' algoritmo='sí' expresión='lado' local='lado' inicio='lado=L_CEN' hacer='lado=((platoIzq.x-plato.w/2 < PESAS[cual,X])&&(PESAS[cual,X] < platoIzq.x+plato.w/2))?L_IZQ:lado;lado=((platoDer.x-plato.w/2 < PESAS[cual,X])&&(PESAS[cual,X] < platoDer.x+plato.w/2))?L_DER:lado;' tipo='función' info='Determina en que lado se soltó la pesa' 
id='acomodaPesas()' algoritmo='sí' expresión='0' local='i' inicio='i=0;numUnoIzq=0;numXIzq=0;numUnoDer=0;numXDer=0' hacer='(PESAS[i,LADO]==L_CEN)?acomodaCentro(i):NULL;(PESAS[i,LADO]==L_IZQ)?acomodaIzquierda(i):NULL;(PESAS[i,LADO]==L_DER)?acomodaDerecha(i):NULL;;i=i+1' mientras='i<PESAS.filas' tipo='función' info='Acomoda las pesas usando funciones auxiliares para cada posición' 
id='acomodaCentro(cual)' algoritmo='sí' expresión='0' hacer='PESAS[cual,X]=balanza.x;PESAS[cual,Y]=balanza.y -((i<PESAS.filas/2)?pesaUno.y:pesaX.y)' tipo='función' info='Acomoda las pesas al centro' 
id='acomodaIzquierda(cual)' algoritmo='sí' expresión='0' local='tipoUno' hacer='offsetUno=27*escalaImg;offsetX=39*escalaImg;platoIzq.y=balanza.y+a*sen(alfa)-plato.h;;tipoUno=(PESAS[cual,TIPO]==&squot;1&squot;);;PESAS[cual,X]=(tipoUno)?platoIzq.x +offsetUno +(numUnoIzq%2)*PESAS[cual,W]:platoIzq.x -offsetX +(numXIzq%2)*PESAS[cual,W];PESAS[cual,Y]=(tipoUno)?platoIzq.y -PESAS[cual,W]/2 -ent(numUnoIzq/2)*PESAS[cual,W]:platoIzq.y -PESAS[cual,W]/2 -ent(numXIzq/2)*PESAS[cual,W];;numUnoIzq=numUnoIzq+(tipoUno);numXIzq=numXIzq+(!tipoUno)' tipo='función' info='Acomoda las pesas a la izquierda' 
id='acomodaDerecha(cual)' algoritmo='sí' expresión='0' local='tipoUno' hacer='offsetUno=27*escalaImg;offsetX=39*escalaImg;platoDer.y=balanza.y-a*sen(alfa)-plato.h;;tipoUno=(PESAS[cual,TIPO]==&squot;1&squot;);;PESAS[cual,X]=(tipoUno)?platoDer.x +offsetUno +(numUnoDer%2)*PESAS[cual,W]:platoDer.x -offsetX +(numXDer%2)*PESAS[cual,W];PESAS[cual,Y]=(tipoUno)?platoDer.y -PESAS[cual,W]/2 -ent(numUnoDer/2)*PESAS[cual,W]:platoDer.y -PESAS[cual,W]/2 -ent(numXDer/2)*PESAS[cual,W];;numUnoDer=numUnoDer+(tipoUno);numXDer=numXDer+(!tipoUno)' tipo='función' info='Acomoda las pesas a la derecha' 
id='calculaAlfa()' algoritmo='sí' expresión='0' inicio='ang=0;lim=8.5' hacer='pesoIzq=numUnoIzq +numXIzq*valX;pesoDer=numUnoDer +numXDer*valX;ang=(pesoIzq>pesoDer)?((pesoIzq!=0)?(lim-pesoDer/pesoIzq*lim):lim):ang;ang=(pesoIzq<pesoDer)?((pesoDer!=0)?(-lim+pesoIzq/pesoDer*lim):-lim):ang;;oriAlfa=grados(alfa);gradosAlfa=oriAlfa;newAlfa=ang;dirAlfa=esIgual(oriAlfa,newAlfa)?0:((oriAlfa<newAlfa)?1:-1);' tipo='función' info='Calcula el ángulo del brazo de la balanza' 
id='animaBalanza()' algoritmo='sí' expresión='0' local='cond' hacer='gradosAlfa=gradosAlfa +dirAlfa*incrAlfa;;cond=(dirAlfa>0)?(gradosAlfa>newAlfa):((dirAlfa<0)?(gradosAlfa<newAlfa):1);alfa=(cond)?radianes(newAlfa):radianes(gradosAlfa);animar=(cond)?0:animar;;acomodaPesas()' tipo='función' info='Anima la balanza' 
id='obtenerEcuacion()' algoritmo='sí' expresión='str' local='str;strIzq;strXIzq;strUnoIzq;strDer;strXDer;strUnoDer;operador' inicio='str=&squot;&squot;' hacer='strXIzq=(numXIzq==0)?&squot;&squot;:((numXIzq==1)?&squot;x&squot;:numXIzq+&squot;x&squot;);strUnoIzq=(numUnoIzq==0)?&squot;&squot;:numUnoIzq;strXDer=(numXDer==0)?&squot;&squot;:((numXDer==1)?&squot;x&squot;:numXDer+&squot;x&squot;);strUnoDer=(numUnoDer==0)?&squot;&squot;:numUnoDer;;strIzq=((strXIzq==&squot;&squot;)&&(strUnoIzq==&squot;&squot;))?&squot;0&squot;:strIzq;strIzq=((strXIzq!=&squot;&squot;)&&(strUnoIzq==&squot;&squot;))?strXIzq:strIzq;strIzq=((strXIzq==&squot;&squot;)&&(strUnoIzq!=&squot;&squot;))?strUnoIzq:strIzq;strIzq=((strXIzq!=&squot;&squot;)&&(strUnoIzq!=&squot;&squot;))?strXIzq+&squot; + &squot;+strUnoIzq:strIzq;;strDer=((strXDer==&squot;&squot;)&&(strUnoDer==&squot;&squot;))?&squot;0&squot;:strDer;strDer=((strXDer!=&squot;&squot;)&&(strUnoDer==&squot;&squot;))?strXDer:strDer;strDer=((strXDer==&squot;&squot;)&&(strUnoDer!=&squot;&squot;))?strUnoDer:strDer;strDer=((strXDer!=&squot;&squot;)&&(strUnoDer!=&squot;&squot;))?strXDer+&squot; + &squot;+strUnoDer:strDer;;BALANCEADA=((numXIzq*valX +numUnoIzq)==(numXDer*valX +numUnoDer));operador=(BALANCEADA)?&squot; = &squot;:&squot; ≠ &squot;;;str=strIzq + operador + strDer' tipo='función' info='Construye una cadena que corresponde a la ecuacion representada en la balanza' 
id='coloca(cuantos,tipo,lado)' algoritmo='sí' expresión='0' local='i;cont;cond' inicio='i=0;cont=0' hacer='cond=(PESAS[i,TIPO]==tipo)&&(PESAS[i,LADO]==L_CEN)&&(cont<cuantos);PESAS[i,LADO]=(cond)?lado:PESAS[i,LADO];cont=cont +cond;;i=i+1' mientras='i<PESAS.filas' tipo='función' info='Coloca un número de objetos de cierto tipo (&squot;1&squot; o &squot;x&squot;) en algún lado de la balanza' 
id='escondeLibres(tipo)' algoritmo='sí' expresión='0' local='i' inicio='i=0' hacer='PESAS[i,VISIBLE]=((PESAS[i,TIPO]==tipo)&&(PESAS[i,LADO]==L_CEN))?0:PESAS[i,VISIBLE];i=i+1' mientras='i<PESAS.filas' tipo='función' info='Esconde las pesas libreas de un tipo' 
id='iniciar(escalaInicial)' algoritmo='sí' expresión='0' inicio='animar=0' hacer='escalaImg=escalaInicial;;//posición del centro de la balanza;balanza.x=E1._w/2;balanza.y=400;;incrAlfa=0.2;;cual=-1;lado=-1;;brazo.w=130*escalaImg;a=brazo.w;;pesaUno.w=(17+3)*escalaImg;pesaX.w=(32+3)*escalaImg;pesaUno.y=120*escalaImg;pesaX.y=70*escalaImg;;plato.w=118*escalaImg;plato.h=36*escalaImg;;valX=2' tipo='función' info='Inicia la escena' 
id='reset()' algoritmo='sí' expresión='0' hacer='alfa=radianes(0) // va de 8 a -8;platoIzq.x=balanza.x-a*cos(alfa);platoDer.x=balanza.x+a*cos(alfa);seleccionado=-1;;initPesas()' tipo='función' info='Reinicia los valores de la escena'