gradientpattern.h 633 B

123456789101112131415161718192021222324252627282930
  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. class GradientPattern : public Pattern
  13. {
  14. public:
  15. GradientPattern(Colour a, Colour b) : Pattern(a, b) { };
  16. Colour patternAt(Tuple point)
  17. {
  18. Tuple distance = this->b - this->a;
  19. double fraction = point.x - floor(point.x);
  20. Tuple ret = this->a + distance * fraction;
  21. return Colour(ret.x, ret.y, ret.z);
  22. }
  23. };
  24. #endif /* DORAYME_GRADIENTPATTERN_H */