ZenScript main repository
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DPath.java 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package org.openzen.drawablegui;
  7. /**
  8. *
  9. * @author Hoofdgebruiker
  10. */
  11. public interface DPath {
  12. public static DPath circle(float x, float y, float radius) {
  13. // see http://spencermortensen.com/articles/bezier-circle/
  14. return tracer -> {
  15. float c = radius * 0.551915024494f;
  16. tracer.moveTo(x, y + radius);
  17. tracer.bezierCubic(
  18. x + c, y + radius,
  19. x + radius, y + c,
  20. x + radius, y);
  21. tracer.bezierCubic(
  22. x + radius, y - c,
  23. x + c, y - radius,
  24. x, y - radius);
  25. tracer.bezierCubic(
  26. x - c, y - radius,
  27. x - radius, y - c,
  28. x - radius, y);
  29. tracer.bezierCubic(
  30. x - radius, y + c,
  31. x - c, y + radius,
  32. x, y + radius);
  33. };
  34. }
  35. public static DPath rectangle(float x, float y, float width, float height) {
  36. return tracer -> {
  37. tracer.moveTo(x, y);
  38. tracer.lineTo(x + width, y);
  39. tracer.lineTo(x + width, y + height);
  40. tracer.lineTo(x, y + height);
  41. tracer.close();
  42. };
  43. }
  44. public static DPath roundedRectangle(float x, float y, float width, float height, float radius) {
  45. return tracer -> {
  46. float c = radius - radius * 0.551915024494f;
  47. tracer.moveTo(x + width - radius, y + height);
  48. tracer.bezierCubic(
  49. x + width - c, y + height,
  50. x + width, y + height - c,
  51. x + width, y + height - radius);
  52. tracer.lineTo(x + width, y + radius);
  53. tracer.bezierCubic(
  54. x + width, y + c,
  55. x + width - c, y,
  56. x + width - radius, y);
  57. tracer.lineTo(x + radius, y);
  58. tracer.bezierCubic(
  59. x + c, y,
  60. x, y + c,
  61. x, y + radius);
  62. tracer.lineTo(x, y + height - radius);
  63. tracer.bezierCubic(
  64. x, y + height - c,
  65. x + c, y + height,
  66. x + radius, y + height);
  67. tracer.close();
  68. };
  69. }
  70. void trace(DPathTracer tracer);
  71. }