gradientpattern.h 767 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * DoRayMe - a quick and dirty Raytracer
  3. * Gradient Pattern header
  4. *
  5. * Created by Manoël Trapier
  6. * Copyright (c) 2020 986-Studio.
  7. *
  8. */
  9. #ifndef DORAYME_GRADIENTPATTERN_H
  10. #define DORAYME_GRADIENTPATTERN_H
  11. #include <pattern.h>
  12. #include <stdio.h>
  13. class GradientPattern : public Pattern
  14. {
  15. public:
  16. GradientPattern(Colour a, Colour b) : Pattern(a, b) { };
  17. Colour patternAt(Tuple point)
  18. {
  19. Tuple distance = this->b - this->a;
  20. double fraction = point.x - floor(point.x);
  21. Tuple ret = this->a + distance * fraction;
  22. return Colour(ret.x, ret.y, ret.z);
  23. }
  24. void dumpMe(FILE *fp) {
  25. fprintf(fp, "\"Type\": \"Gradient\",\n");
  26. Pattern::dumpMe(fp);
  27. }
  28. };
  29. #endif /* DORAYME_GRADIENTPATTERN_H */