makeColorsPicker.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { makeDiv,
  2. makeInput,
  3. setInput } from '/domUtilities.js';
  4. import { makeFundamentalWheel } from '/wheelComponents/makeFundamentalWheel.js';
  5. function makeColorsPicker() {
  6. let colors = ['#000000',
  7. '#000000',
  8. '#000000',
  9. '#000000',
  10. '#000000',
  11. '#000000',
  12. '#000000',
  13. '#000000',
  14. '#000000',
  15. '#000000',
  16. '#000000',
  17. '#000000'];
  18. const div = makeDiv();
  19. const wheel = makeFundamentalWheel(section => {
  20. setInput(colorInput, colors[section]);
  21. });
  22. wheel.setFilter(colors);
  23. const colorInput = makeInput('color: ', colors[wheel.getFundamental()], value => {
  24. colors[wheel.getFundamental()] = value;
  25. wheel.setFilter(colors);
  26. });
  27. const setAllButton = makeInput('set all', undefined, () => {
  28. const color = colorInput.getElementsByTagName('input')[0].value;
  29. set(colors.map(() => color));
  30. });
  31. div.append(wheel.canvas,
  32. colorInput,
  33. setAllButton);
  34. const set = newColors => {
  35. colors = newColors.slice();
  36. wheel.setFilter(colors);
  37. setInput(colorInput, colors[wheel.getFundamental()]);
  38. };
  39. const get = () => {
  40. return colors.slice();
  41. };
  42. return {div, set, get};
  43. }
  44. export { makeColorsPicker }