ringpattern.h 697 B

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