Caso de estudio

Activitats relatives al àmbit de Multimedia on el moiment siga una peça clau: bé siga per l'animación de imatgens i/o gràfics o per la sucesió d'imatgens fixes, siguen el principal encant.

  1. Castell de focs artificials.

  2. Antiestrés 2: divertiment que permet menejar, pintar y "destroçar" els continguts de la pantalla.

  3. Punts de sincronisme en la banda d'audio: QuickTime? pot extraure-los. Alternatives?

  4. Streaming, vídeo interactivo, ...

Per al castell

Se propone realizar un castillo de fuegos artificiales, con una limitación: los elementos visibles han de ser puntos, estos deberán exhibir colores y movimientos que recuerden el de los cohetes que componen una típica mascletà.

Figura 10-9. Captura de l'aproximació inicial.

La aproximación que se muestra aquí, es incremental con lo que se quiere:

Por una parte, las cosas comunes ... La situación de los objetos en la ventana y la de esta misma, se controla con el código de la pila y el de la tarjeta. Así como se ha dispuesto un botón para reiniciar la secuencia.

# stack ""
on preOpenStack
  set the decorations of this stack to zero
  set the location of this stack to screenLoc()
end preOpenStack

#card "castellDeFoc"
on openCard
  repeat  with numero = 1 to  the number of groups of this card
    set the location of  graphic  ("cuet" & numero) of group ("cuet" & numero) to the posicioInicial of \
        graphic  ("cuet" & numero) of group ("cuet" & numero)
    --260,460
    send "mostrat" to group ("cuet" & numero)
    --    ask "mostrar group" && ("cuet" & numero)
  end repeat
  send "encendreLaMetxa"
end openCard

on encendreLaMetxa
  repeat  with numero = 1 to  the number of groups of this card
    send "muevete" to group ("cuet" & numero) in \
        (the tempsInici  of graphic ("cuet" & numero) of \
         the group ("cuet" & numero)) milliseconds
  end repeat
end encendreLaMetxa

# on keyUp
# send "mouseUp" to me
# end keyUp

# button "Sr. pirotecnic, pot ..."
on mouseUp
  send "openCard" to this card
end mouseUp
     

Por otra, veamos una primera aproximación: el más sencillo de todas las "carcasas" ... Para guardar las propiedades de cada cohete se han empleado una serie de propiedades privadas del objeto que lo implementa, en este caso del objeto "graphic". El listado completo de propiedades del objeto graphic "cuet1" incluye:

Figura 10-10. Ventana de propiedades del objeto grahic "cuet1" donde se puede observar las propiedades que se utilizan y el valor de la primera de ellas.

#group "cuet1"
on mostrat
  repeat  with numero = 1 to \
                the numFills of graphic (the short name of me) of group (the short name of me)
    hide graphic (the short name of me & "_fill" & numero)
  end repeat
  show graphic (the short name of me)
end mostrat

on muevete
  send muevete to graphic (the short name of me) of group (the short name of me) in \
      (the tempsInici  of graphic (the short name of me) of\
        group (the short name of me) ) milliseconds
end muevete

#graphic "cuet1"
on muevete
  if the visible of me is not true then exit "muevete"
  
  # Si es pot, avant: puja amunt i quant aplegues dalt esclata
  if ( the second item of the location of me =  \
      (the second item of the posicioInicial of me - the altura of me) )
  then
    --    put "Plof"
    play "sons/" & the sonitEsclatar of me
    hide me
  else
    set the location of me to the first item of (the location of me), \
        the second item of (the location of me) - 1
    send "muevete" to me in 100 milliseconds
  end if
end muevete
     

Un paso más: añadamos la posibilidad de que al terminar la carcasa incial, aparezcan nuevos elementos ("hijos") ...

Para ello, será necesario cambiar los parámetros de comportamiento del graphic "cuet2", que como se han expuesto para el caso anterior, ahora son:

#group "cuet2"
on mostrat
  -- ask  (the tempsInici  of graphic (the short name of me) of\
  -- the group (the short name of me))
  # send "muevete" to me in \
      # (the tempsInici  of graphic (the short name of me) of
      # the group (the short name of me)) milliseconds
end mostrat

on muevete
  set the firstcolor of graphic (the short name of me) to\
        (the coloret of graphic (the short name of me))
  repeat  with numero = 1 to  \
                the numFills of graphic  (the short name of me) of\
                the group (the short name of me)
    hide graphic (the short name of me & "_fill" & numero)
    --    ask "ocultar " && (the short name of me & "_fill" & numero)
    set the firstcolor of graphic  (the short name of me & "_fill" & numero) to \
           (the coloret of graphic (the short name of me))
  end repeat
  show graphic (the short name of me)
  --  show graphic (the short name of me)
  send muevete to graphic (the short name of me) of the group (the short name of me)
end muevete

#graphic "cuet2"
on muevete
  if the visible of me is not true then exit "muevete"
  
  # Si es pot, avant: puja amunt i quant aplegues dalt esclata
  if ( the second item of the location of me =  \
      (the second item of the posicioInicial of me - the altura of me) )
  then
    --    put "Plof"
    play "sons/" & the sonitEsclatar of me
    hide me
    repeat  with numero = 1 to  the numFills of me
      --      ask "menejat" && (the short name of me & "_fill" & numero)
      send ("muevete" && the location of me) to \
          the graphic (the short name of me & "_fill" & numero) of\
           group (the short name of me)
    end repeat
  else
    set the location of me to the first item of (the location of me), \
        the second item of (the location of me) - 1
    send "muevete" to me in 100 milliseconds
  end if
end muevete

#graphic "cuet2_fill1"
on muevete  posX, posY
  --   ask posX && posY
  # Posicionat
  set the location of me to (posX + the first item of the posicioInicial of me), \
      (posY + the second item of the posicioInicial of me)
  show me
  send ("menejat" && posY) to me
end muevete

on menejat posY
  --  ask valorY && (valorY  + the altura of me)
  --   put "[" & posY &"," & (posY + the altura of me) &"]" && the location of me && "(" && \
      --the second item of the location of me && "=" &&  (posY + the altura of me)  && ")"
  if the visible of me is not true then exit "menejat"
  
  # Si es pot, avant: ves baixant i quant aplegues desapareix
  if ( the second item of the location of me =  (posY + the altura of me) )
  then
    hide me
  else
    set the location of me to the first item of (the location of me), \
        the second item of (the location of me) + 1
    send ("menejat" && posY) to me in 100 milliseconds
  end if
end menejat


#graphic "cuet2_fill2"
on muevete  posX, posY
  # Posicionat
  set the location of me to (posX + the first item of the posicioInicial of me), \
      (posY + the second item of the posicioInicial of me)
  show me
  send ("menejat" && posY) to me
end muevete

on menejat posY
  if the visible of me is not true then exit "menejat"
  
  # Si es pot, avant: ves baixant i quant aplegues desapareix
  if ( the second item of the location of me =  (posY + the altura of me) )
  then
    hide me
  else
    set the location of me to the first item of (the location of me), \
        the second item of (the location of me) + 1
    send ("menejat" && posY) to me in 100 milliseconds
  end if
end menejat
     

Sólo queda ir complicando un poco más el movimiento de cada uno de los "cohetes", esto se puede hacer aprovechando la estructura anterior y ...

#group "cuet3"
on mostrat
  --  ask  (the tempsInici  of graphic (the short name of me) of\
  --  the group (the short name of me))
  # send "muevete" to me in \
      # (the tempsInici  of graphic (the short name of me) of\
      #  the group (the short name of me)) milliseconds
end mostrat

on muevete
  set the firstcolor of graphic (the short name of me) to\
        (the coloret of graphic (the short name of me))
  repeat  with numero = 1 to  the numFills of\
               graphic  (the short name of me) of the group (the short name of me)
    hide graphic (the short name of me & "_fill" & numero)
    --    ask "ocultar " && (the short name of me & "_fill" & numero)
    set the firstcolor of graphic  (the short name of me & "_fill" & numero) to\
          (the coloret of graphic (the short name of me))
  end repeat
  show graphic (the short name of me)
  --  show graphic (the short name of me)
  send muevete to graphic (the short name of me) of the group (the short name of me)
end muevete

#graphic "cuet3"
on muevete
  if the visible of me is not true then exit "muevete"
  
  # Si es pot, avant: puja amunt i quant aplegues dalt esclata
  if ( the second item of the location of me =  \
      (the second item of the posicioInicial of me - the altura of me) )
  then
    --    put "Plof"
    play "sons/" & the sonitEsclatar of me
    hide me
    repeat  with numero = 1 to  the numFills of me
      --      ask "menejat" && (the short name of me & "_fill" & numero)
      send ("muevete" && the location of me) to \
          the graphic (the short name of me & "_fill" & numero) of group (the short name of me)
    end repeat
  else
    set the location of me to the first item of (the location of me), \
        the second item of (the location of me) - 1
    send "muevete" to me in 100 milliseconds
  end if
end muevete

#graphic "cuet3_fill1"
on muevete  posX, posY
  --   ask posX && posY
  # Posicionat
  set the location of me to (posX + the first item of the posicioInicial of me), \
      (posY + the second item of the posicioInicial of me)
  show me
  send ("menejat" && posY) to me
end muevete

on menejat posY
  --  ask valorY && (valorY  + the altura of me)
  --   put "[" & posY &"," & (posY + the altura of me) &"]" && the location of me && "(" && \
      --the second item of the location of me && "=" &&  (posY + the altura of me)  && ")"
  if the visible of me is not true then exit "menejat"
  
  # Si es pot, avant: ves baixant i quant aplegues desapareix
  if ( the second item of the location of me =  (posY + the altura of me) )
  then
    hide me
  else
    set the location of me to (the first item of (the location of me) + 1), \
        the second item of (the location of me) + 1
    send ("menejat" && posY) to me in 100 milliseconds
  end if
end menejat


#graphic "cuet3_fill2"
on muevete  posX, posY
  # Posicionat
  set the location of me to (posX + the first item of the posicioInicial of me), \
      (posY + the second item of the posicioInicial of me)
  show me
  send ("menejat" && posY) to me
end muevete

on menejat posY
  if the visible of me is not true then exit "menejat"
  
  # Si es pot, avant: ves baixant i quant aplegues desapareix
  if ( the second item of the location of me =  (posY + the altura of me) )
  then
    hide me
  else
    set the location of me to (the first item of (the location of me) -1), \
        the second item of (the location of me) + 1
    send ("menejat" && posY) to me in 100 milliseconds
  end if
end menejat