3
$\begingroup$

I have this image and would like to create an animated GIF with the head moving like it's completing a Rubik's Cube.

Here I leave you part of the code that I have.

Could you help me? Thank you.

enter image description here

 (* Cargar la imagen base *)
 imgBase = Import["OM2025.jpg"];

 (* Recortar el cuerpo del joven (ajustar según imagen original) *)
 imgCuerpo = ImageCrop[ImageTake[imgBase, {400, 700}]];

 (* Construcción del cubo Rubik 3x3x3 con colores fijos *)
 cubies = Flatten[
 Table[{{i, j, k}, 
 Switch[Mod[i + j + k, 6],
  0, Red,
  1, Blue,
  2, Yellow,
  3, Green,
  4, Orange,
  _, White]},
{i, -1, 1}, {j, -1, 1}, {k, -1, 1}], 2];

(* Dibuja un cubito individual *)
drawCubie[{x_, y_, z_}, color_] := {
EdgeForm[Black],
{color, Cuboid[{x, y, z}, {x + 1, y + 1, z + 1}]}
};
(* Armar todo el cubo Rubik en 3D *)
drawRubikCube[estado_] := Graphics3D[
   drawCubie @@@ estado,
   Boxed -> False,
   Lighting -> "Neutral",
   ViewPoint -> {2, -2, 2},
   ImageSize -> {300, 300}
   ];

(* Función para animar el giro de la capa superior *)
cubeFrame[t_] := Module[{ang, estado},
  ang = 2 Pi t;
  estado = cubies /. {pos_, col_} :> 
     If[pos[[3]] == 1,
      {RotationTransform[ang, {0, 0, 1}, {0, 0, 1}][pos], col},
      {pos, col}
     ];
  drawRubikCube[estado]
  ];

(* Animación: superponer el cubo sobre el cuerpo *)
Animate[
 ImageCompose[
  imgCuerpo,
  cubeFrame[t],
  {{0.5, 0.15}}  (* Posición relativa del cubo en la imagen *)
  ],
 {t, 0, 1}
 ]
$\endgroup$
1

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.