various_motion.cpp 988 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include "common/sketchbook.hpp"
  2. using quadratic_move = movement<float, motion::quadratic_curve>;
  3. float block = 0;
  4. auto diagonal_back_and_forth = melody(
  5. quadratic_move{500ms, 0,1},
  6. quadratic_move{500ms, 1,0}
  7. );
  8. float2 block2 = float2::zero();
  9. auto square_around = melody(
  10. quadratic_move{500ms, 0,1},
  11. quadratic_move{500ms, 0,1},
  12. quadratic_move{500ms, 1,0},
  13. quadratic_move{500ms, 1,0}
  14. );
  15. void start(Program& program)
  16. {
  17. program.draw_loop = [](auto frame, auto delta)
  18. {
  19. frame.begin_sketch()
  20. .rectangle(rect{ frame.size })
  21. .fill(0xffffff_rgb)
  22. ;
  23. frame.begin_sketch()
  24. .rectangle(rect{ frame.size/100, float2::one(10) + block*20 })
  25. .fill(0x0_rgb)
  26. ;
  27. frame.begin_sketch()
  28. .rectangle(rect{ frame.size/100, float2::one(10) + float2::j(30) + block2*20 })
  29. .fill(0x0_rgb)
  30. ;
  31. loop(block, diagonal_back_and_forth, delta);
  32. loop(std::forward_as_tuple(
  33. block2.x(),
  34. block2.y(),
  35. block2.x(),
  36. block2.y()
  37. ),
  38. square_around, delta
  39. );
  40. };
  41. }