Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 

64 Zeilen
1.7 KiB

  1. //
  2. // Lol Engine — GIF encoding sample
  3. //
  4. // Copyright © 2016—2020 Sam Hocevar <sam@hocevar.net>
  5. //
  6. // Lol Engine is free software. It comes without any warranty, to
  7. // the extent permitted by applicable law. You can redistribute it
  8. // and/or modify it under the terms of the Do What the Fuck You Want
  9. // to Public License, Version 2, as published by the WTFPL Task Force.
  10. // See http://www.wtfpl.net/ for more details.
  11. //
  12. #if HAVE_CONFIG_H
  13. # include "config.h"
  14. #endif
  15. #include <lol/engine.h>
  16. #include <lol/msg>
  17. #include <lol/vector>
  18. #include <lol/noise>
  19. #include <lol/image/movie.h>
  20. int main(int, char **)
  21. {
  22. lol::ivec2 size(256, 256);
  23. lol::movie movie(size);
  24. if (!movie.open_file("16_movie.gif"))
  25. return EXIT_FAILURE;
  26. // Use 4D Perlin noise
  27. lol::perlin_noise<4> noise;
  28. for (int i = 0; i < 256; ++i)
  29. {
  30. lol::image im(size);
  31. lol::array2d<lol::u8vec3> &data = im.lock2d<lol::PixelFormat::RGB_8>();
  32. for (int y = 0; y < size.y; ++y)
  33. for (int x = 0; x < size.x; ++x)
  34. {
  35. float alpha = lol::F_TAU * i / 256;
  36. float beta = lol::F_TAU * i / 256;
  37. lol::vec4 p(2.f * x / (float)size.x + cos(alpha),
  38. 2.f * x / (float)size.x + sin(alpha),
  39. 2.f * y / (float)size.y + cos(beta),
  40. 2.f * y / (float)size.y + sin(beta));
  41. data[x][y].r = 128 * (noise.eval(p) + 1 + lol::rand(0.1f));
  42. data[x][y].g = 128 * (noise.eval(p.zyxw) + 1 + lol::rand(0.1f));
  43. data[x][y].b = 128 * (noise.eval(p.ywxz) + 1 + lol::rand(0.1f));
  44. }
  45. im.unlock2d(data);
  46. if (!movie.push_image(im))
  47. break;
  48. }
  49. movie.close();
  50. return 0;
  51. }