vector_salad 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +16 -0
  3. data/Gemfile +9 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +89 -0
  6. data/Rakefile +2 -0
  7. data/bin/vector_salad +72 -0
  8. data/examples/birthday.png +0 -0
  9. data/examples/birthday.rb +45 -0
  10. data/examples/birthday.svg +630 -0
  11. data/examples/boolean_operations.png +0 -0
  12. data/examples/boolean_operations.rb +23 -0
  13. data/examples/boolean_operations.svg +151 -0
  14. data/examples/bp_logo.png +0 -0
  15. data/examples/bp_logo.rb +18 -0
  16. data/examples/bp_logo.svg +25 -0
  17. data/examples/bunny_card.png +0 -0
  18. data/examples/bunny_card.rb +219 -0
  19. data/examples/bunny_card.svg +134 -0
  20. data/examples/chill.png +0 -0
  21. data/examples/chill.rb +16 -0
  22. data/examples/chill.svg +86 -0
  23. data/examples/circle_line_segments.png +0 -0
  24. data/examples/circle_line_segments.rb +11 -0
  25. data/examples/circle_line_segments.svg +28 -0
  26. data/examples/circles.png +0 -0
  27. data/examples/circles.rb +14 -0
  28. data/examples/circles.svg +11 -0
  29. data/examples/clip_operations.png +0 -0
  30. data/examples/clip_operations.rb +14 -0
  31. data/examples/clip_operations.svg +8 -0
  32. data/examples/cog_menu.png +0 -0
  33. data/examples/cog_menu.rb +32 -0
  34. data/examples/cog_menu.svg +37 -0
  35. data/examples/cubic_bezier_handles.png +0 -0
  36. data/examples/cubic_bezier_handles.rb +21 -0
  37. data/examples/cubic_bezier_handles.svg +14 -0
  38. data/examples/cubic_circle.png +0 -0
  39. data/examples/cubic_circle.rb +26 -0
  40. data/examples/cubic_circle.svg +29 -0
  41. data/examples/face.png +0 -0
  42. data/examples/face.rb +4 -0
  43. data/examples/face.svg +10 -0
  44. data/examples/flower.png +0 -0
  45. data/examples/flower.rb +23 -0
  46. data/examples/flower.svg +207 -0
  47. data/examples/fox.png +0 -0
  48. data/examples/fox.rb +110 -0
  49. data/examples/fox.svg +31 -0
  50. data/examples/fresh_vector_salad_gui.png +0 -0
  51. data/examples/galaxies.png +0 -0
  52. data/examples/galaxies.rb +60 -0
  53. data/examples/galaxies.svg +5806 -0
  54. data/examples/gold_stars.png +0 -0
  55. data/examples/gold_stars.rb +9 -0
  56. data/examples/gold_stars.svg +12 -0
  57. data/examples/paths.png +0 -0
  58. data/examples/paths.rb +87 -0
  59. data/examples/paths.svg +13 -0
  60. data/examples/pepsi_logo.png +0 -0
  61. data/examples/pepsi_logo.rb +21 -0
  62. data/examples/pepsi_logo.svg +10 -0
  63. data/examples/polygons.png +0 -0
  64. data/examples/polygons.rb +9 -0
  65. data/examples/polygons.svg +13 -0
  66. data/examples/quadratic_bezier_handle.png +0 -0
  67. data/examples/quadratic_bezier_handle.rb +18 -0
  68. data/examples/quadratic_bezier_handle.svg +13 -0
  69. data/examples/rects.png +0 -0
  70. data/examples/rects.rb +10 -0
  71. data/examples/rects.svg +11 -0
  72. data/examples/simple_path.png +0 -0
  73. data/examples/simple_path.rb +29 -0
  74. data/examples/simple_path.svg +8 -0
  75. data/examples/space.png +0 -0
  76. data/examples/space.rb +171 -0
  77. data/examples/space.svg +46453 -0
  78. data/examples/spiro_nodes.png +0 -0
  79. data/examples/spiro_nodes.rb +20 -0
  80. data/examples/spiro_nodes.svg +13 -0
  81. data/examples/squares.png +0 -0
  82. data/examples/squares.rb +14 -0
  83. data/examples/squares.svg +11 -0
  84. data/examples/stars.png +0 -0
  85. data/examples/stars.rb +3 -0
  86. data/examples/stars.svg +30006 -0
  87. data/examples/transforms.png +0 -0
  88. data/examples/transforms.rb +58 -0
  89. data/examples/transforms.svg +121 -0
  90. data/examples/triangles.png +0 -0
  91. data/examples/triangles.rb +8 -0
  92. data/examples/triangles.svg +9 -0
  93. data/lib/contracts_contracts.rb +32 -0
  94. data/lib/vector_salad.rb +5 -0
  95. data/lib/vector_salad/canvas.rb +27 -0
  96. data/lib/vector_salad/dsl.rb +41 -0
  97. data/lib/vector_salad/export_with_magic.rb +29 -0
  98. data/lib/vector_salad/exporters/base_exporter.rb +92 -0
  99. data/lib/vector_salad/exporters/svg_exporter.rb +174 -0
  100. data/lib/vector_salad/interpolate.rb +57 -0
  101. data/lib/vector_salad/magic.rb +17 -0
  102. data/lib/vector_salad/mixins/at.rb +28 -0
  103. data/lib/vector_salad/shape_proxy.rb +14 -0
  104. data/lib/vector_salad/standard_shapes/basic_shape.rb +29 -0
  105. data/lib/vector_salad/standard_shapes/circle.rb +64 -0
  106. data/lib/vector_salad/standard_shapes/clip.rb +51 -0
  107. data/lib/vector_salad/standard_shapes/custom.rb +28 -0
  108. data/lib/vector_salad/standard_shapes/difference.rb +28 -0
  109. data/lib/vector_salad/standard_shapes/exclusion.rb +28 -0
  110. data/lib/vector_salad/standard_shapes/flip.rb +24 -0
  111. data/lib/vector_salad/standard_shapes/hexagon.rb +15 -0
  112. data/lib/vector_salad/standard_shapes/intersection.rb +28 -0
  113. data/lib/vector_salad/standard_shapes/iso_tri.rb +39 -0
  114. data/lib/vector_salad/standard_shapes/jitter.rb +33 -0
  115. data/lib/vector_salad/standard_shapes/move.rb +24 -0
  116. data/lib/vector_salad/standard_shapes/multi_path.rb +82 -0
  117. data/lib/vector_salad/standard_shapes/n.rb +112 -0
  118. data/lib/vector_salad/standard_shapes/oval.rb +51 -0
  119. data/lib/vector_salad/standard_shapes/path.rb +249 -0
  120. data/lib/vector_salad/standard_shapes/pentagon.rb +15 -0
  121. data/lib/vector_salad/standard_shapes/polygon.rb +37 -0
  122. data/lib/vector_salad/standard_shapes/rect.rb +34 -0
  123. data/lib/vector_salad/standard_shapes/rotate.rb +24 -0
  124. data/lib/vector_salad/standard_shapes/scale.rb +34 -0
  125. data/lib/vector_salad/standard_shapes/square.rb +34 -0
  126. data/lib/vector_salad/standard_shapes/transform.rb +20 -0
  127. data/lib/vector_salad/standard_shapes/triangle.rb +15 -0
  128. data/lib/vector_salad/standard_shapes/union.rb +28 -0
  129. data/lib/vector_salad/version.rb +3 -0
  130. data/vector_salad.gemspec +34 -0
  131. metadata +262 -0
Binary file
@@ -0,0 +1,9 @@
1
+ rect(390, 200, fill: 'beige') # background
2
+
3
+ (1..5).each do |n| # repeat 5 times
4
+ # make a star from the union of two triangles
5
+ union(fill: 'gold', stroke_width: 3, stroke: 'black') do
6
+ triangle(25)
7
+ triangle(25).flip(:x)
8
+ end.move(n * 65, 100) # move stars at intervals horizontally
9
+ end
@@ -0,0 +1,12 @@
1
+ <svg version="1.1"
2
+ xmlns="http://www.w3.org/2000/svg"
3
+ width="390"
4
+ height="200">
5
+
6
+ <rect x="0" y="0" width="390" height="200" fill="beige"/>
7
+ <path d=" M 65.0 125.0 L 57.78312110900879 112.5 L 43.349365234375 112.5 L 50.566243171691895 100.0 L 43.349365234375 87.5 L 57.78312110900879 87.5 L 65.0 75.0 L 72.21687889099121 87.50000095367432 L 86.650634765625 87.50000095367432 L 79.4337568283081 100.0 L 86.650634765625 112.49999904632568 L 72.21687889099121 112.49999904632568 Z" fill="gold" stroke-width="3" stroke="black"/>
8
+ <path d=" M 130.0 125.0 L 122.78312110900879 112.5 L 108.349365234375 112.5 L 115.5662431716919 100.0 L 108.349365234375 87.5 L 122.78312110900879 87.5 L 130.0 75.0 L 137.2168788909912 87.50000095367432 L 151.650634765625 87.50000095367432 L 144.4337568283081 100.0 L 151.650634765625 112.49999904632568 L 137.2168788909912 112.49999904632568 Z" fill="gold" stroke-width="3" stroke="black"/>
9
+ <path d=" M 195.0 125.0 L 187.7831211090088 112.5 L 173.349365234375 112.5 L 180.5662431716919 100.0 L 173.349365234375 87.5 L 187.7831211090088 87.5 L 195.0 75.0 L 202.2168788909912 87.50000095367432 L 216.650634765625 87.50000095367432 L 209.4337568283081 100.0 L 216.650634765625 112.49999904632568 L 202.2168788909912 112.49999904632568 Z" fill="gold" stroke-width="3" stroke="black"/>
10
+ <path d=" M 260.0 125.0 L 252.7831211090088 112.5 L 238.349365234375 112.5 L 245.5662431716919 100.0 L 238.349365234375 87.5 L 252.7831211090088 87.5 L 260.0 75.0 L 267.2168788909912 87.50000095367432 L 281.650634765625 87.50000095367432 L 274.4337568283081 100.0 L 281.650634765625 112.49999904632568 L 267.2168788909912 112.49999904632568 Z" fill="gold" stroke-width="3" stroke="black"/>
11
+ <path d=" M 325.0 125.0 L 317.7831211090088 112.5 L 303.349365234375 112.5 L 310.5662431716919 100.0 L 303.349365234375 87.5 L 317.7831211090088 87.5 L 325.0 75.0 L 332.2168788909912 87.50000095367432 L 346.650634765625 87.50000095367432 L 339.4337568283081 100.0 L 346.650634765625 112.49999904632568 L 332.2168788909912 112.49999904632568 Z" fill="gold" stroke-width="3" stroke="black"/>
12
+ </svg>
Binary file
data/examples/paths.rb ADDED
@@ -0,0 +1,87 @@
1
+ # A simple triangle using arrays as nodes
2
+ path([0,0], [100,10], [70,100])
3
+
4
+ # A house, including quadratic node and options
5
+ path(
6
+ N.n(150,50),
7
+ N.n(200,20),
8
+ N.n(250,50),
9
+ N.n(250,150),
10
+ N.n(210,150),
11
+ N.n(210,100),
12
+ N.q(200,90),
13
+ N.n(190,100),
14
+ N.n(190,150),
15
+ N.n(150,150),
16
+ fill: 'red',
17
+ stroke: 'black',
18
+ stroke_width: 2
19
+ )
20
+
21
+ # A wave using mirror nodes
22
+ path(
23
+ N.n(300,100),
24
+ N.q(380,0),
25
+ N.n(400,100),
26
+ N.m,
27
+ N.n(500,100),
28
+ N.n(500,200),
29
+ N.n(300,200),
30
+ fill: 'blue'
31
+ )
32
+
33
+ # A candle flame with mirrored cubic nodes
34
+ # Tricky using cubic nodes but still possible by hand
35
+ path(
36
+ N.n(105, 200), # tip
37
+ N.c(95, 220), # right inner top curve
38
+ N.c(95, 240),
39
+ N.n(110, 255), # right bulge
40
+ N.m,
41
+ N.c(120, 300), # right outer base curve
42
+ N.n(90, 300), # bottom
43
+ N.m,
44
+ N.c(55, 275),
45
+ N.n(65, 250), # left bulge
46
+ N.m,
47
+ N.c(80, 220), # left outer tip curve
48
+ N.n(105, 200),
49
+ fill: :yellow,
50
+ stroke: :orange,
51
+ stroke_width: 5,
52
+ stroke_linejoin: :miter,
53
+ stroke_miterlimit: 10
54
+ )
55
+
56
+ # A smooth Spiro curve, very beautiful
57
+ path(
58
+ N.n(100, 370),
59
+ N.s(200, 420),
60
+ N.s(250, 400),
61
+ N.s(300, 440),
62
+ N.n(400, 300),
63
+ fill: 'purple'
64
+ )
65
+
66
+ # Another smooth Spiro, easily forming an egg
67
+ path(
68
+ N.s(100, 450),
69
+ N.s(50, 500),
70
+ N.s(100, 600),
71
+ N.s(150, 500),
72
+ fill: 'turquoise'
73
+ )
74
+
75
+ # An open Spiro path, showing :left and :right nodes
76
+ path(
77
+ N.n(200, 500),
78
+ N.r(300, 500),
79
+ N.g(350, 500),
80
+ N.s(350, 580),
81
+ N.l(250, 650),
82
+ N.n(250, 700),
83
+ closed: false,
84
+ fill: 'none',
85
+ stroke: 'green',
86
+ stroke_width: 6
87
+ )
@@ -0,0 +1,13 @@
1
+ <svg version="1.1"
2
+ xmlns="http://www.w3.org/2000/svg"
3
+ width="500"
4
+ height="700.0">
5
+
6
+ <path d="M 0 0 L 100 10 L 70 100 Z"/>
7
+ <path d="M 150 50 L 200 20 L 250 50 L 250 150 L 210 150 L 210 100 Q 200 90, 190 100 L 190 150 L 150 150 Z" fill="red" stroke="black" stroke-width="2"/>
8
+ <path d="M 300 100 Q 380 0, 400 100 Q 420 200, 500 100 L 500 200 L 300 200 Z" fill="blue"/>
9
+ <path d="M 105 200 C 95 220, 95 240, 110 255 C 125 270, 120 300, 90 300 C 60 300, 55 275, 65 250 C 75 225, 80 220, 105 200 Z" fill="yellow" stroke="orange" stroke-width="5" stroke-linejoin="miter" stroke-miterlimit="10"/>
10
+ <path d="M 100.0 370.0 C 104.66240025627245 390.80364055942914, 119.0594473373335 409.2088158546345, 138.1283631256129 418.7432737487742 C 157.19727891389232 428.2777316429139, 180.55964739869322 428.7522641306395, 200.0 420.0 C 208.31014455965678 416.2586799919964, 215.8300253947433 410.9825576723767, 223.8919403523991 406.732674706905 C 231.953855310055 402.48279174143346, 240.92064793752195 399.2117461511311, 250.0 400.0 C 255.45423203767444 400.47352711589275, 260.7215052240687 402.40946505079023, 265.4447686086849 405.17779632609387 C 270.1680319933011 407.94612760139745, 274.3715355225831 411.5320615320023, 278.2129422796331 415.43289082552053 C 285.89575579373314 423.2345494125566, 292.1937005506367 432.32190198630013, 300.0 440.0 C 317.8789076748777 457.5852856268289, 343.6309105843935 466.84573729699446, 368.6145167366008 464.67386394540455 C 393.5981228888081 462.50199059381464, 417.3658391899783 448.9366936632542, 431.9420324124711 428.5300231517642 C 446.51822563496364 408.12335264027433, 451.64181474187086 381.24082199952636, 445.59349834941554 356.9032896874635 C 439.5451819569602 332.56575737540055, 422.433294298312 311.2091443540206, 400.0 300.0 L 100.0 370.0 Z" fill="purple"/>
11
+ <path d="M 100.0 450.0 C 93.66557493738986 449.99999999994026, 87.3749203221214 451.6884539824017, 81.74276917876306 454.58738729867355 C 76.1106180354047 457.4863206149454, 71.12749576903826 461.57492423932905, 66.94282582585038 466.3302873527415 C 58.57348593947468 475.84101357956627, 53.48517962804135 487.81996361025233, 50.0 500.0 C 44.04747114220032 520.8029501594925, 42.546475521310896 543.6749482031747, 50.743229095165375 563.7001464791163 C 54.841605882092296 573.7127456170866, 61.354898283968026 582.8170293955553, 69.93136040392191 589.4119616385964 C 78.5078225238758 596.0068938816374, 89.18108906657855 600.0000000000756, 100.0 600.0 C 110.81891093336367 599.9999999999243, 121.4921774759533 596.0068938813818, 130.0686395958021 589.4119616382989 C 138.6451017156509 582.817029395216, 145.158394117432 573.7127456167656, 149.25677090431978 563.7001464788416 C 157.45352447809435 543.6749482029936, 155.95252885736153 520.8029501594963, 150.0 500.0 C 146.51482037216712 487.81996361008026, 141.42651406097835 475.84101357914153, 133.05717417459903 466.33028735217596 C 128.87250423140938 461.5749242386932, 123.88938196498037 457.4863206142762, 118.25723082152406 454.5873872980768 C 112.62507967806775 451.6884539818774, 106.3344250626641 449.99999999960005, 100.0 450.0 Z" fill="turquoise"/>
12
+ <path d="M 200.0 500.0 L 300.0 500.0 C 308.34258636740196 500.0, 316.68287945150706 499.76988387775174, 325.0182751279732 499.4235802330838 C 333.35367080443893 499.07727658841566, 341.7487071321922 498.76918185453, 350.0 500.0 C 359.88060364964514 501.4738570615556, 369.58954362870753 505.4476445088784, 376.69561977697293 512.4692016648326 C 383.80169592523833 519.4907588207868, 387.9802016563458 529.4331471109792, 387.8030321026812 539.4215000316831 C 387.625862549044 549.4098529525121, 383.1772627392383 559.1413639162881, 376.1580590294321 566.2497647492471 C 369.13885531962586 573.3581655822061, 359.7631983491393 577.8837436078933, 350.0 580.0 C 338.30696707545854 582.5345644720517, 326.19481694843904 581.8220294939678, 314.23429918295756 582.1335592983189 C 302.27378141747585 582.4450891026703, 290.0802188064798 583.9649977745896, 279.35855920167853 589.2750873553947 C 268.636899598464 594.58517693362, 259.8688570007988 603.7487901004351, 255.17525487152412 614.7542948606924 C 250.48165274225198 625.7597996209475, 250.00000000160594 638.0354257921183, 250.0 650.0 L 250.0 700.0" fill="none" stroke="green" stroke-width="6"/>
13
+ </svg>
Binary file
@@ -0,0 +1,21 @@
1
+ square(500, fill: '#01205C') # background
2
+
3
+ circle(200, at: [250, 250], fill: 'white') # white circle
4
+
5
+ intersection(fill: '#FC002C') do # red circle
6
+ circle(190, at: [250, 250])
7
+ circle((190 * 1.6).round, at: [30, 60])
8
+ end
9
+
10
+ difference(fill: '#0B60BB') do # blue circle
11
+ circle(190, at: [250, 250])
12
+ path(
13
+ N.n(0, 0),
14
+ N.n(420, 0),
15
+ N.n(380, 110),
16
+ N.s(370, 270),
17
+ N.s(220, 335),
18
+ N.n(100, 365),
19
+ N.n(0, 365)
20
+ )
21
+ end
@@ -0,0 +1,10 @@
1
+ <svg version="1.1"
2
+ xmlns="http://www.w3.org/2000/svg"
3
+ width="500"
4
+ height="500">
5
+
6
+ <rect x="0" y="0" width="500" height="500" fill="#01205C"/>
7
+ <circle cx="250" cy="250" r="200" fill="white"/>
8
+ <path d=" M 93.23725605010986 357.346718788147 L 92.6783218383789 356.5358600616455 L 90.93836879730225 353.9201498031616 L 89.24190139770508 351.27602767944336 L 87.58938407897949 348.6042184829712 L 85.98126792907715 345.90545177459717 L 84.41799354553223 343.1804656982422 L 82.89998722076416 340.43000411987305 L 81.42766380310059 337.6548204421997 L 80.00142669677734 334.8556728363037 L 78.62166595458984 332.0333261489868 L 77.28875827789307 329.1885528564453 L 76.00306701660156 326.32213020324707 L 74.76494598388672 323.4348421096802 L 73.57473182678223 320.5274772644043 L 72.43275165557861 317.600830078125 L 71.33931541442871 314.6557025909424 L 70.29472351074219 311.6928987503052 L 69.29926109313965 308.713228225708 L 68.35320091247559 305.7175064086914 L 67.45680141448975 302.70655250549316 L 66.61030673980713 299.681188583374 L 65.81394863128662 296.6422424316406 L 65.067946434021 293.59054470062256 L 64.37250137329102 290.52692890167236 L 63.727806091308594 287.4522342681885 L 63.13403511047363 284.36730098724365 L 62.59135150909424 281.2729721069336 L 62.09990406036377 278.17009258270264 L 61.65982627868652 275.0595121383667 L 61.271239280700684 271.9420804977417 L 60.934247970581055 268.8186502456665 L 60.648945808410645 265.6900749206543 L 60.41541004180908 262.5572109222412 L 60.23370552062988 259.42091274261475 L 60.103880882263184 256.282039642334 L 60.02597141265869 253.14144897460938 L 60.0 249.99999904632568 L 60.02597141265869 246.8585500717163 L 60.103880882263184 243.7179594039917 L 60.23370552062988 240.57908630371094 L 60.41541004180908 237.44278812408447 L 60.648945808410645 234.3099241256714 L 60.934247970581055 231.18134880065918 L 61.271239280700684 228.05791854858398 L 61.65982627868652 224.94048690795898 L 62.09990406036377 221.82990646362305 L 62.59135150909424 218.7270269393921 L 63.13403511047363 215.63269805908203 L 63.727806091308594 212.5477647781372 L 64.37250137329102 209.47307014465332 L 65.067946434021 206.40945434570312 L 65.81394863128662 203.35775661468506 L 66.61030673980713 200.31881046295166 L 67.45680141448975 197.29344654083252 L 68.35320091247559 194.28249263763428 L 69.29926109313965 191.28677082061768 L 70.29472351074219 188.3071002960205 L 71.33931541442871 185.3442964553833 L 72.43275165557861 182.39916896820068 L 73.57473182678223 179.4725217819214 L 74.76494598388672 176.5651569366455 L 76.00306701660156 173.6778688430786 L 77.28875827789307 170.81144618988037 L 78.62166595458984 167.96667289733887 L 80.00142669677734 165.14432621002197 L 81.42766380310059 162.34517860412598 L 82.89998722076416 159.56999492645264 L 84.41799354553223 156.8195333480835 L 85.98126792907715 154.09454727172852 L 87.58938407897949 151.3957805633545 L 89.24190139770508 148.72397136688232 L 90.93836879730225 146.07984924316406 L 92.6783218383789 143.46413898468018 L 94.46128463745117 140.87755393981934 L 96.28677082061768 138.32080173492432 L 98.1542797088623 135.79458141326904 L 100.06330299377441 133.2995843887329 L 102.01331615447998 130.83649158477783 L 104.00378799438477 128.4059772491455 L 106.0341739654541 126.00870513916016 L 108.10391902923584 123.64533042907715 L 110.21245670318604 121.31650066375732 L 112.35921096801758 119.02285194396973 L 114.54359436035156 116.76501083374023 L 116.76501083374023 114.54359436035156 L 119.02285194396973 112.35921096801758 L 121.31650066375732 110.21245670318604 L 123.64533042907715 108.10391902923584 L 126.00870513916016 106.0341739654541 L 128.4059772491455 104.00378799438477 L 130.83649158477783 102.01331615447998 L 133.2995843887329 100.06330299377441 L 135.79458141326904 98.1542797088623 L 138.32080173492432 96.28677082061768 L 140.87755393981934 94.46128463745117 L 143.46413898468018 92.6783218383789 L 146.07984924316406 90.93836879730225 L 148.72397136688232 89.24190139770508 L 151.3957805633545 87.58938407897949 L 154.09454727172852 85.98126792907715 L 156.8195333480835 84.41799354553223 L 159.56999492645264 82.89998722076416 L 162.34517860412598 81.42766380310059 L 165.14432621002197 80.00142669677734 L 167.96667289733887 78.62166595458984 L 170.81144618988037 77.28875827789307 L 173.6778688430786 76.00306701660156 L 176.5651569366455 74.76494598388672 L 179.4725217819214 73.57473182678223 L 182.39916896820068 72.43275165557861 L 185.3442964553833 71.33931541442871 L 188.3071002960205 70.29472351074219 L 191.28677082061768 69.29926109313965 L 194.28249263763428 68.35320091247559 L 197.29344654083252 67.45680141448975 L 200.31881046295166 66.61030673980713 L 203.35775661468506 65.81394863128662 L 206.40945434570312 65.067946434021 L 209.47307014465332 64.37250137329102 L 212.5477647781372 63.727806091308594 L 215.63269805908203 63.13403511047363 L 218.7270269393921 62.59135150909424 L 221.82990646362305 62.09990406036377 L 224.94048690795898 61.65982627868652 L 228.05791854858398 61.271239280700684 L 231.18134880065918 60.934247970581055 L 234.3099241256714 60.648945808410645 L 237.44278812408447 60.41541004180908 L 240.57908630371094 60.23370552062988 L 243.7179594039917 60.103880882263184 L 246.8585500717163 60.02597141265869 L 250.0 60.0 L 253.14144897460938 60.02597141265869 L 256.282039642334 60.103880882263184 L 259.42091274261475 60.23370552062988 L 262.5572109222412 60.41541004180908 L 265.6900749206543 60.648945808410645 L 268.8186502456665 60.934247970581055 L 271.9420804977417 61.271239280700684 L 275.0595121383667 61.65982627868652 L 278.17009258270264 62.09990406036377 L 281.2729721069336 62.59135150909424 L 284.36730098724365 63.13403511047363 L 287.4522342681885 63.727806091308594 L 290.52692890167236 64.37250137329102 L 293.59054470062256 65.067946434021 L 296.6422424316406 65.81394863128662 L 299.681188583374 66.61030673980713 L 302.70655250549316 67.45680141448975 L 305.7175064086914 68.35320091247559 L 308.713228225708 69.29926109313965 L 311.6928987503052 70.29472351074219 L 314.6557025909424 71.33931541442871 L 317.600830078125 72.43275165557861 L 320.5274772644043 73.57473182678223 L 323.4348421096802 74.76494598388672 L 326.32213020324707 76.00306701660156 L 329.1885528564453 77.28875827789307 L 332.0333261489868 78.62166595458984 L 333.3858394622803 79.28286933898926 L 333.2049341201782 81.97197341918945 L 332.96168518066406 85.1041202545166 L 332.6860818862915 88.23358726501465 L 332.37815380096436 91.3600378036499 L 332.03793239593506 94.48313999176025 L 331.66545581817627 97.60255908966064 L 331.26076316833496 100.71796321868896 L 330.82389640808105 103.82901859283447 L 330.3549041748047 106.93539333343506 L 329.8538360595703 110.0367546081543 L 329.32074451446533 113.13277339935303 L 328.75568771362305 116.22311782836914 L 328.1587247848511 119.30745697021484 L 327.52992057800293 122.38546371459961 L 326.86934185028076 125.45680713653564 L 326.177059173584 128.52116012573242 L 325.45314598083496 131.57819652557373 L 324.69768047332764 134.6275873184204 L 323.9107427597046 137.6690092086792 L 323.09241676330566 140.7021360397339 L 322.24279022216797 143.7266445159912 L 321.36195373535156 146.7422113418579 L 320.45000171661377 149.74851512908936 L 319.50703144073486 152.7452335357666 L 318.53314304351807 155.73204803466797 L 317.5284414291382 158.70863819122314 L 316.49303245544434 161.67468738555908 L 315.42702770233154 164.6298770904541 L 314.3305416107178 167.57389450073242 L 313.20369052886963 170.506422996521 L 312.046594619751 173.42714977264404 L 310.85937786102295 176.3357629776001 L 309.6421661376953 179.23195266723633 L 308.39509105682373 182.1154088973999 L 307.11828422546387 184.98582363128662 L 305.8118829727173 187.84289073944092 L 304.4760265350342 190.68630504608154 L 303.110857963562 193.51576232910156 L 301.7165222167969 196.330961227417 L 300.29316902160645 199.13160133361816 L 298.84095001220703 201.9173822402954 L 297.3600196838379 204.68800735473633 L 295.85053730010986 207.44318008422852 L 294.3126630783081 210.18260765075684 L 292.7465629577637 212.90599536895752 L 291.1524019241333 215.6130542755127 L 289.53035068511963 218.30349445343018 L 287.8805847167969 220.97702884674072 L 286.2032775878906 223.63337230682373 L 284.49860858917236 226.2722396850586 L 282.76676177978516 228.8933506011963 L 281.00792026519775 231.4964246749878 L 279.2222728729248 234.08118343353271 L 277.4100093841553 236.6473512649536 L 275.5713243484497 239.19465446472168 L 273.70641326904297 241.72282028198242 L 271.8154764175415 244.2315797805786 L 269.89871406555176 246.72066402435303 L 267.9563322067261 249.1898078918457 L 265.98853874206543 251.638747215271 L 263.9955425262451 254.0672197341919 L 261.9775562286377 256.47496795654297 L 259.934796333313 258.8617334365845 L 257.86748123168945 261.2272615432739 L 255.77583026885986 263.5712995529175 L 253.6600685119629 265.89359760284424 L 251.5204210281372 268.1939067840576 L 249.35711574554443 270.4719820022583 L 247.17038440704346 272.7275810241699 L 244.9604606628418 274.9604606628418 L 242.72758102416992 277.17038440704346 L 240.4719820022583 279.35711574554443 L 238.19390678405762 281.5204210281372 L 235.89359760284424 283.6600685119629 L 233.57129955291748 285.77583026885986 L 231.22726154327393 287.86748123168945 L 228.86173343658447 289.934796333313 L 226.47496795654297 291.9775562286377 L 224.0672197341919 293.9955425262451 L 221.638747215271 295.98853874206543 L 219.1898078918457 297.9563322067261 L 216.72066402435303 299.89871406555176 L 214.2315797805786 301.8154764175415 L 211.72282028198242 303.70641326904297 L 209.19465446472168 305.5713243484497 L 206.6473512649536 307.4100093841553 L 204.08118343353271 309.2222728729248 L 201.4964246749878 311.00792026519775 L 198.8933506011963 312.76676177978516 L 196.2722396850586 314.49860858917236 L 193.63337230682373 316.2032775878906 L 190.97702884674072 317.8805847167969 L 188.30349445343018 319.53035068511963 L 185.6130542755127 321.1524019241333 L 182.90599536895752 322.7465629577637 L 180.18260765075684 324.3126630783081 L 177.44318008422852 325.85053730010986 L 174.68800735473633 327.3600196838379 L 171.9173822402954 328.84095001220703 L 169.13160133361816 330.29316902160645 L 166.330961227417 331.7165222167969 L 163.51576232910156 333.110857963562 L 160.68630504608154 334.4760265350342 L 157.84289073944092 335.8118829727173 L 154.98582363128662 337.11828422546387 L 152.1154088973999 338.39509105682373 L 149.23195266723633 339.6421661376953 L 146.3357629776001 340.85937786102295 L 143.42714977264404 342.046594619751 L 140.506422996521 343.20369052886963 L 137.57389450073242 344.3305416107178 L 134.6298770904541 345.42702770233154 L 131.67468738555908 346.49303245544434 L 128.70863819122314 347.5284414291382 L 125.73204803466797 348.53314304351807 L 122.7452335357666 349.50703144073486 L 119.74851512908936 350.45000171661377 L 116.74221134185791 351.36195373535156 L 113.72664451599121 352.24279022216797 L 110.70213603973389 353.09241676330566 L 107.6690092086792 353.9107427597046 L 104.62758731842041 354.69768047332764 L 101.57819652557373 355.45314598083496 L 98.52116012573242 356.177059173584 L 95.45680713653564 356.86934185028076 Z" fill="#FC002C"/>
9
+ <path d=" M 249.99999904632568 440.0 L 246.8585500717163 439.974027633667 L 243.7179594039917 439.8961181640625 L 240.57908630371094 439.7662935256958 L 237.44278812408447 439.5845890045166 L 234.3099241256714 439.35105323791504 L 231.18134880065918 439.06575107574463 L 228.05791854858398 438.728759765625 L 224.94048690795898 438.34017276763916 L 221.82990646362305 437.9000949859619 L 218.7270269393921 437.40864753723145 L 215.63269805908203 436.86596393585205 L 212.5477647781372 436.2721929550171 L 209.47307014465332 435.62749767303467 L 206.40945434570312 434.9320526123047 L 203.35775661468506 434.18605041503906 L 200.31881046295166 433.38969230651855 L 197.29344654083252 432.54319763183594 L 194.28249263763428 431.6467981338501 L 191.28677082061768 430.70073795318604 L 188.3071002960205 429.7052755355835 L 185.3442964553833 428.660683631897 L 182.39916896820068 427.56724739074707 L 179.4725217819214 426.42526721954346 L 176.5651569366455 425.23505306243896 L 173.6778688430786 423.9969320297241 L 170.81144618988037 422.7112407684326 L 167.96667289733887 421.37833309173584 L 165.14432621002197 419.99857234954834 L 162.34517860412598 418.5723352432251 L 159.56999492645264 417.1000118255615 L 156.8195333480835 415.58200550079346 L 154.09454727172852 414.01873111724854 L 151.3957805633545 412.4106149673462 L 148.72397136688232 410.7580976486206 L 146.07984924316406 409.06163024902344 L 143.46413898468018 407.3216772079468 L 140.87755393981934 405.5387144088745 L 138.32080173492432 403.713228225708 L 135.79458141326904 401.8457193374634 L 133.2995843887329 399.93669605255127 L 130.83649158477783 397.9866828918457 L 128.4059772491455 395.9962110519409 L 126.00870513916016 393.9658250808716 L 123.64533042907715 391.89608001708984 L 121.31650066375732 389.78754234313965 L 119.02285194396973 387.6407880783081 L 116.76501083374023 385.4564046859741 L 114.54359436035156 383.23498821258545 L 112.35921096801758 380.97714710235596 L 110.21245670318604 378.68349838256836 L 108.10391902923584 376.35466861724854 L 106.0341739654541 373.9912939071655 L 104.00378799438477 371.5940217971802 L 102.01331615447998 369.16350746154785 L 100.06330299377441 366.7004146575928 L 98.76224708557129 365.0 L 100.0 365.0 L 129.84267807006836 356.8827362060547 L 159.7940092086792 349.17603874206543 L 189.8483362197876 341.88132190704346 L 220.0 335.0 L 240.31460571289062 330.5313720703125 L 260.57304763793945 325.814245223999 L 270.63723850250244 323.23012924194336 L 280.6346263885498 320.425048828125 L 290.5476236343384 317.3460578918457 L 300.3586435317993 313.9402093887329 L 310.052640914917 310.14536571502686 L 319.585750579834 305.9173812866211 L 328.89715576171875 301.2303009033203 L 337.92603874206543 296.0581684112549 L 346.61158180236816 290.3750276565552 L 354.8929681777954 284.1549234390259 L 362.7093801498413 277.37189960479736 L 370.0 270.0 L 373.56171131134033 265.9235420227051 L 376.9425916671753 261.69738960266113 L 380.1388931274414 257.330379486084 L 383.1468667984009 252.83134746551514 L 385.9627637863159 248.2091302871704 L 388.58283615112305 243.47256469726562 L 391.0033349990845 238.6304874420166 L 393.2205123901367 233.69173431396484 L 395.2306203842163 228.6651430130005 L 397.0299081802368 223.55954933166504 L 398.6146297454834 218.3837890625 L 399.98103618621826 213.1466999053955 L 401.1253786087036 207.85711860656738 L 402.04390811920166 202.52388095855713 L 402.7328767776489 197.15582370758057 L 403.18853664398193 191.7617826461792 L 403.40805435180664 186.35298347473145 L 403.39284324645996 180.94091510772705 L 403.14552211761475 175.53481197357178 L 402.66871070861816 170.1439085006714 L 401.96502685546875 164.77743816375732 L 401.0370903015137 159.44463729858398 L 399.8875198364258 154.15474033355713 L 398.51893520355225 148.9169797897339 L 396.9339542388916 143.74059200286865 L 395.1351957321167 138.6348114013672 L 393.125280380249 133.60887145996094 L 390.9068260192871 128.67200756072998 L 388.4824514389038 123.83345413208008 L 385.8547763824463 119.10244464874268 L 383.0264196395874 114.48821544647217 L 382.74244117736816 114.06707191467285 L 383.23498821258545 114.54359436035156 L 385.4564046859741 116.76501083374023 L 387.6407880783081 119.02285194396973 L 389.78754234313965 121.31650066375732 L 391.89608001708984 123.64533042907715 L 393.9658250808716 126.00870513916016 L 395.9962110519409 128.4059772491455 L 397.9866828918457 130.83649158477783 L 399.93669605255127 133.2995843887329 L 401.8457193374634 135.79458141326904 L 403.713228225708 138.32080173492432 L 405.5387144088745 140.87755393981934 L 407.3216772079468 143.46413898468018 L 409.06163024902344 146.07984924316406 L 410.7580976486206 148.72397136688232 L 412.4106149673462 151.3957805633545 L 414.01873111724854 154.09454727172852 L 415.58200550079346 156.8195333480835 L 417.1000118255615 159.56999492645264 L 418.5723352432251 162.34517860412598 L 419.99857234954834 165.14432621002197 L 421.37833309173584 167.96667289733887 L 422.7112407684326 170.81144618988037 L 423.9969320297241 173.6778688430786 L 425.23505306243896 176.5651569366455 L 426.42526721954346 179.4725217819214 L 427.56724739074707 182.39916896820068 L 428.660683631897 185.3442964553833 L 429.7052755355835 188.3071002960205 L 430.70073795318604 191.28677082061768 L 431.6467981338501 194.28249263763428 L 432.54319763183594 197.29344654083252 L 433.38969230651855 200.31881046295166 L 434.18605041503906 203.35775661468506 L 434.9320526123047 206.40945434570312 L 435.62749767303467 209.47307014465332 L 436.2721929550171 212.5477647781372 L 436.86596393585205 215.63269805908203 L 437.40864753723145 218.7270269393921 L 437.9000949859619 221.82990646362305 L 438.34017276763916 224.94048690795898 L 438.728759765625 228.05791854858398 L 439.06575107574463 231.18134880065918 L 439.35105323791504 234.3099241256714 L 439.5845890045166 237.44278812408447 L 439.7662935256958 240.57908630371094 L 439.8961181640625 243.7179594039917 L 439.974027633667 246.8585500717163 L 440.0 250.0 L 439.974027633667 253.14144897460938 L 439.8961181640625 256.282039642334 L 439.7662935256958 259.42091274261475 L 439.5845890045166 262.5572109222412 L 439.35105323791504 265.6900749206543 L 439.06575107574463 268.8186502456665 L 438.728759765625 271.9420804977417 L 438.34017276763916 275.0595121383667 L 437.9000949859619 278.17009258270264 L 437.40864753723145 281.2729721069336 L 436.86596393585205 284.36730098724365 L 436.2721929550171 287.4522342681885 L 435.62749767303467 290.52692890167236 L 434.9320526123047 293.59054470062256 L 434.18605041503906 296.6422424316406 L 433.38969230651855 299.681188583374 L 432.54319763183594 302.70655250549316 L 431.6467981338501 305.7175064086914 L 430.70073795318604 308.713228225708 L 429.7052755355835 311.6928987503052 L 428.660683631897 314.6557025909424 L 427.56724739074707 317.600830078125 L 426.42526721954346 320.5274772644043 L 425.23505306243896 323.4348421096802 L 423.9969320297241 326.32213020324707 L 422.7112407684326 329.1885528564453 L 421.37833309173584 332.0333261489868 L 419.99857234954834 334.8556728363037 L 418.5723352432251 337.6548204421997 L 417.1000118255615 340.43000411987305 L 415.58200550079346 343.1804656982422 L 414.01873111724854 345.90545177459717 L 412.4106149673462 348.6042184829712 L 410.7580976486206 351.27602767944336 L 409.06163024902344 353.9201498031616 L 407.3216772079468 356.5358600616455 L 405.5387144088745 359.12244510650635 L 403.713228225708 361.67919731140137 L 401.8457193374634 364.20541763305664 L 399.93669605255127 366.7004146575928 L 397.9866828918457 369.16350746154785 L 395.9962110519409 371.5940217971802 L 393.9658250808716 373.9912939071655 L 391.89608001708984 376.35466861724854 L 389.78754234313965 378.68349838256836 L 387.6407880783081 380.97714710235596 L 385.4564046859741 383.23498821258545 L 383.23498821258545 385.4564046859741 L 380.97714710235596 387.6407880783081 L 378.68349838256836 389.78754234313965 L 376.35466861724854 391.89608001708984 L 373.9912939071655 393.9658250808716 L 371.5940217971802 395.9962110519409 L 369.16350746154785 397.9866828918457 L 366.7004146575928 399.93669605255127 L 364.20541763305664 401.8457193374634 L 361.67919731140137 403.713228225708 L 359.12244510650635 405.5387144088745 L 356.5358600616455 407.3216772079468 L 353.9201498031616 409.06163024902344 L 351.27602767944336 410.7580976486206 L 348.6042184829712 412.4106149673462 L 345.90545177459717 414.01873111724854 L 343.1804656982422 415.58200550079346 L 340.43000411987305 417.1000118255615 L 337.6548204421997 418.5723352432251 L 334.8556728363037 419.99857234954834 L 332.0333261489868 421.37833309173584 L 329.1885528564453 422.7112407684326 L 326.32213020324707 423.9969320297241 L 323.4348421096802 425.23505306243896 L 320.5274772644043 426.42526721954346 L 317.600830078125 427.56724739074707 L 314.6557025909424 428.660683631897 L 311.6928987503052 429.7052755355835 L 308.713228225708 430.70073795318604 L 305.7175064086914 431.6467981338501 L 302.70655250549316 432.54319763183594 L 299.681188583374 433.38969230651855 L 296.6422424316406 434.18605041503906 L 293.59054470062256 434.9320526123047 L 290.52692890167236 435.62749767303467 L 287.4522342681885 436.2721929550171 L 284.36730098724365 436.86596393585205 L 281.2729721069336 437.40864753723145 L 278.17009258270264 437.9000949859619 L 275.0595121383667 438.34017276763916 L 271.9420804977417 438.728759765625 L 268.8186502456665 439.06575107574463 L 265.6900749206543 439.35105323791504 L 262.5572109222412 439.5845890045166 L 259.42091274261475 439.7662935256958 L 256.282039642334 439.8961181640625 L 253.14144897460938 439.974027633667 Z" fill="#0B60BB"/>
10
+ </svg>
Binary file
@@ -0,0 +1,9 @@
1
+ polygon(3, 70, at: [390,530], fill: 'yellow')
2
+ polygon(4, 70, at: [390,170], fill: 'blue')
3
+ pentagon(90, at: [130,120], fill: 'red')
4
+ hexagon(100, at: [300,350], fill: 'green')
5
+ polygon(7, 60, at: [100,360], fill: 'orange')
6
+ polygon(8, 120, at: [190,650], fill: 'purple')
7
+
8
+ square(10, at: [500,800])
9
+
@@ -0,0 +1,13 @@
1
+ <svg version="1.1"
2
+ xmlns="http://www.w3.org/2000/svg"
3
+ width="500"
4
+ height="800">
5
+
6
+ <path d="M 329.3782217350893 565.0 L 390.0 460.0 L 450.62177826491074 565.0 Z" fill="yellow"/>
7
+ <path d="M 340.50252531694167 219.49747468305833 L 340.50252531694167 120.50252531694167 L 439.49747468305833 120.50252531694167 L 439.49747468305833 219.49747468305833 Z" fill="blue"/>
8
+ <path d="M 77.09932729367742 192.81152949374527 L 44.40491353343617 92.18847050625475 L 129.99999999999997 30.0 L 215.59508646656383 92.18847050625472 L 182.9006727063226 192.81152949374524 Z" fill="red"/>
9
+ <path d="M 250.00000000000003 436.6025403784439 L 200.0 350.0 L 249.99999999999994 263.39745962155615 L 349.99999999999994 263.3974596215561 L 400.0 350.0 L 350.0000000000001 436.6025403784438 Z" fill="green"/>
10
+ <path d="M 73.96697565294652 414.05813207414513 L 41.504325269090586 373.35125603737885 L 53.09011105191821 322.590611888476 L 99.99999999999999 300.0 L 146.90988894808177 322.59061188847596 L 158.4956747309094 373.35125603737885 L 126.0330243470535 414.05813207414513 Z" fill="orange"/>
11
+ <path d="M 144.07798811618923 760.8655439013544 L 79.13445609864559 695.9220118838108 L 79.13445609864559 604.0779881161892 L 144.07798811618915 539.1344560986456 L 235.9220118838108 539.1344560986456 L 300.8655439013544 604.0779881161892 L 300.8655439013544 695.9220118838108 L 235.92201188381085 760.8655439013544 Z" fill="purple"/>
12
+ <rect x="500" y="800" width="10" height="10"/>
13
+ </svg>
@@ -0,0 +1,18 @@
1
+ rect 400, 300, fill: :none
2
+
3
+ path(
4
+ n1 = N.n(20, 280),
5
+ h1 = N.q(150, 50),
6
+ n2 = N.n(380, 280),
7
+ closed: false,
8
+ fill: :red,
9
+ stroke: :black,
10
+ stroke_width: 4
11
+ )
12
+
13
+ path(n1, N.n(*h1.at), closed: false, stroke: :blue, stroke_width: 2)
14
+ circle(4, at: h1.at, fill: :blue)
15
+ path(n2, N.n(*h1.at), closed: false, stroke: :blue, stroke_width: 2)
16
+
17
+ circle(4, at: n1.at, fill: :green)
18
+ circle(4, at: n2.at, fill: :green)
@@ -0,0 +1,13 @@
1
+ <svg version="1.1"
2
+ xmlns="http://www.w3.org/2000/svg"
3
+ width="400"
4
+ height="300">
5
+
6
+ <rect x="0" y="0" width="400" height="300" fill="none"/>
7
+ <path d="M 20 280 Q 150 50, 380 280" fill="red" stroke="black" stroke-width="4"/>
8
+ <path d="M 20 280 L 150 50" stroke="blue" stroke-width="2"/>
9
+ <circle cx="150" cy="50" r="4" fill="blue"/>
10
+ <path d="M 380 280 L 150 50" stroke="blue" stroke-width="2"/>
11
+ <circle cx="20" cy="280" r="4" fill="green"/>
12
+ <circle cx="380" cy="280" r="4" fill="green"/>
13
+ </svg>
Binary file
data/examples/rects.rb ADDED
@@ -0,0 +1,10 @@
1
+ # Simple rectangle 100x150
2
+ rect(100, 200)
3
+
4
+ rect(500, 10, at: [0, 200])
5
+
6
+ rect(300, 200, at: [100, 0], fill: 'yellow')
7
+
8
+ canvas << Rect.new(500, 30, at: [0, 410], fill: 'red').to_path
9
+
10
+ rect(20, 500, at: [400, 0])
@@ -0,0 +1,11 @@
1
+ <svg version="1.1"
2
+ xmlns="http://www.w3.org/2000/svg"
3
+ width="500"
4
+ height="500">
5
+
6
+ <rect x="0" y="0" width="100" height="200"/>
7
+ <rect x="0" y="200" width="500" height="10"/>
8
+ <rect x="100" y="0" width="300" height="200" fill="yellow"/>
9
+ <path d="M 0 410 L 0 440 L 500 440 L 500 410 Z" fill="red"/>
10
+ <rect x="400" y="0" width="20" height="500"/>
11
+ </svg>
Binary file
@@ -0,0 +1,29 @@
1
+ path(
2
+ N.n(0,0),
3
+ N.c(50,200),
4
+ N.c(200,250),
5
+ N.n(300,0)
6
+ ).to_simple_path
7
+
8
+ # A candle flame with mirrored cubic nodes
9
+ # Tricky using cubic nodes but still possible by hand
10
+ path(
11
+ N.n(105, 200), # tip
12
+ N.c(95, 220), # right inner top curve
13
+ N.c(95, 240),
14
+ N.n(110, 255), # right bulge
15
+ N.r,
16
+ N.c(120, 300), # right outer base curve
17
+ N.n(90, 300), # bottom
18
+ N.r,
19
+ N.c(55, 275),
20
+ N.n(65, 250), # left bulge
21
+ N.r,
22
+ N.c(80, 220), # left outer tip curve
23
+ N.n(105, 200),
24
+ fill: :yellow,
25
+ stroke: :orange,
26
+ stroke_width: 5,
27
+ stroke_linejoin: :miter,
28
+ stroke_miterlimit: 10
29
+ ).to_simple_path
@@ -0,0 +1,8 @@
1
+ <svg version="1.1"
2
+ xmlns="http://www.w3.org/2000/svg"
3
+ width="300"
4
+ height="300">
5
+
6
+ <path d="M0 0 L 2.4164199829101562 9.264564514160156 L 4.97589111328125 18.30596923828125 L 7.674980163574219 27.12078094482422 L 10.51025390625 35.70556640625 L 13.478279113769531 44.05689239501953 L 16.57562255859375 52.17132568359375 L 19.798851013183594 60.045433044433594 L 23.14453125 67.67578125 L 26.609230041503906 75.0589370727539 L 30.18951416015625 82.19146728515625 L 33.88195037841797 89.06993865966797 L 37.68310546875 95.69091796875 L 41.58954620361328 102.05097198486328 L 45.59783935546875 108.14666748046875 L 49.704551696777344 113.97457122802734 L 53.90625 119.53125 L 58.199501037597656 124.81327056884766 L 62.58087158203125 129.81719970703125 L 67.04692840576172 134.53960418701172 L 71.59423828125 138.97705078125 L 76.21936798095703 143.12610626220703 L 80.91888427734375 146.98333740234375 L 85.6893539428711 150.5453109741211 L 90.52734375 153.80859375 L 95.4294204711914 156.7697525024414 L 100.39215087890625 159.42535400390625 L 105.41210174560547 161.77196502685547 L 110.48583984375 163.80615234375 L 115.60993194580078 165.52448272705078 L 120.78094482421875 166.92352294921875 L 125.99544525146484 167.99983978271484 L 131.25 168.75 L 136.54117584228516 169.17057037353516 L 141.86553955078125 169.25811767578125 L 147.21965789794922 169.00920867919922 L 152.60009765625 168.42041015625 L 158.00342559814453 167.48828887939453 L 163.42620849609375 166.20941162109375 L 168.8650131225586 164.5803451538086 L 174.31640625 162.59765625 L 179.7769546508789 160.2579116821289 L 185.24322509765625 157.55767822265625 L 190.71178436279297 154.49352264404297 L 196.17919921875 151.06201171875 L 201.64203643798828 147.25971221923828 L 207.09686279296875 143.08319091796875 L 212.54024505615234 138.52901458740234 L 217.96875 133.59375 L 223.37894439697266 128.27396392822266 L 228.76739501953125 122.56622314453125 L 234.13066864013672 116.46709442138672 L 239.46533203125 109.97314453125 L 244.76795196533203 103.08094024658203 L 250.03509521484375 95.78704833984375 L 255.2633285522461 88.0880355834961 L 260.44921875 79.98046875 L 265.5893325805664 71.4609146118164 L 270.68023681640625 62.52593994140625 L 275.71849822998047 53.17211151123047 L 280.70068359375 43.39599609375 L 285.6233596801758 33.19416046142578 L 290.48309326171875 22.56317138671875 L 295.27645111083984 11.499595642089844 L 300 0 Z"/>
7
+ <path d="M105 200 L 103.243408203125 203.748779296875 L 101.728515625 207.490234375 L 100.462646484375 211.217041015625 L 99.453125 214.921875 L 98.707275390625 218.597412109375 L 98.232421875 222.236328125 L 98.035888671875 225.831298828125 L 98.125 229.375 L 98.507080078125 232.860107421875 L 99.189453125 236.279296875 L 100.179443359375 239.625244140625 L 101.484375 242.890625 L 103.111572265625 246.068115234375 L 105.068359375 249.150390625 L 107.362060546875 252.130126953125 L 110 255 L 112.576904296875 257.977294921875 L 114.677734375 261.240234375 L 116.295166015625 264.722900390625 L 117.421875 268.359375 L 118.050537109375 272.083740234375 L 118.173828125 275.830078125 L 117.784423828125 279.532470703125 L 116.875 283.125 L 115.438232421875 286.541748046875 L 113.466796875 289.716796875 L 110.953369140625 292.584228515625 L 107.890625 295.078125 L 104.271240234375 297.132568359375 L 100.087890625 298.681640625 L 95.333251953125 299.659423828125 L 92.73941040039062 299.9134826660156 L 90 300 L 84.66552734375 299.713134765625 L 79.90234375 298.876953125 L 75.69580078125 297.528076171875 L 72.03125 295.703125 L 68.89404296875 293.438720703125 L 66.26953125 290.771484375 L 64.14306640625 287.738037109375 L 62.5 284.375 L 61.32568359375 280.718994140625 L 60.60546875 276.806640625 L 60.32470703125 272.674560546875 L 60.46875 268.359375 L 61.02294921875 263.897705078125 L 61.97265625 259.326171875 L 63.30322265625 254.681396484375 L 65 250 L 66.822509765625 245.538330078125 L 68.564453125 241.494140625 L 70.262451171875 237.816162109375 L 71.953125 234.453125 L 73.673095703125 231.353759765625 L 75.458984375 228.466796875 L 79.375 223.125 L 81.578369140625 220.567626953125 L 83.994140625 218.017578125 L 86.658935546875 215.423583984375 L 89.609375 212.734375 L 92.882080078125 209.898681640625 L 96.513671875 206.865234375 L 100.540771484375 203.582763671875 L 105 200 Z" fill="yellow" stroke="orange" stroke-width="5" stroke-linejoin="miter" stroke-miterlimit="10"/>
8
+ </svg>
Binary file
data/examples/space.rb ADDED
@@ -0,0 +1,171 @@
1
+ QUALITY = 8 # 8
2
+ WIDTH = 1000
3
+ HEIGHT = (WIDTH / 16.0 * 9.0).round
4
+ GOLDEN = 1.618
5
+
6
+ def cluster_repeat(repeats:, width:, total:, i:)
7
+ period = total / repeats
8
+ repeat = i / period # integer division
9
+ t = i % period
10
+ sub_width = width / repeats
11
+ set = (Math.cos(1.0 / period * t * Math::PI) + 1) / 2 * sub_width
12
+ offset = sub_width * repeat
13
+
14
+ set + offset
15
+ end
16
+
17
+ def star(r, at:, shift: 30, bias: 2)
18
+ col = 255 - (1 - Random.rand**3) * shift
19
+ red = [255, col, col]
20
+ blue = [col, col, 255]
21
+ fill_a = [red, *[blue] * bias].sample
22
+ fill = "rgb(#{fill_a.join(',')})"
23
+ circle(r, at: at, fill: fill)
24
+ end
25
+
26
+ def background(n:, star:)
27
+ n.times do
28
+ r = Random.rand**2 * (WIDTH * star) + 0.05
29
+ x = Random.rand(WIDTH)
30
+ y = Random.rand(HEIGHT)
31
+
32
+ star(r, at: [x, y])
33
+ end
34
+ end
35
+
36
+ def galaxy(n:, star:, size:, at:, arms: 4)
37
+ a_n = n * 2
38
+
39
+ n.times do
40
+ r = Random.rand**2 * (WIDTH * star) + 0.05
41
+ dist = Random.rand**3 * size
42
+ twirl = (1 + Math.log(dist / size) / 2) * GOLDEN
43
+ a_c = cluster_repeat(repeats: arms, width: 2.0, total: a_n, i: Random.rand(a_n))
44
+ a = a_c + twirl
45
+
46
+ x = dist * Math.cos(a * Math::PI) + at[0]
47
+ y = dist * Math.sin(a * Math::PI) + at[1]
48
+
49
+ star(r, at: [x, y], shift: 120, bias: 4)
50
+ end
51
+ end
52
+
53
+ def asteroid(r, at:)
54
+ _r_min, r_max = 20, 55
55
+ #r = Random.rand(r_min..r_max)
56
+ #x = Random.rand(r..WIDTH - r)
57
+ #y = Random.rand(r..HEIGHT - r)
58
+ _c_min, c_max = 60, 120
59
+ c = c_max / r_max * r
60
+ col = "rgb(#{c}, #{c}, #{c})"
61
+ circle(r, at: at, fill: col).jitter(r / 8, fn: r)
62
+
63
+ Random.rand(1..6).times { crater(r: r, x: at[0], y: at[1], c: c) }
64
+ end
65
+
66
+ def crater(r:, x:, y:, c:)
67
+ r_min, r_max = r / 6, r / 3
68
+ cr = Random.rand(r_min..r_max)
69
+ margin = cr * 1.5
70
+ offset = Random.rand(0..r - margin)
71
+ a = Random.rand(2 * Math::PI)
72
+ cx = offset * Math.cos(a) + x
73
+ cy = offset * Math.sin(a) + y
74
+ cc = c * 0.9
75
+ col = "rgb(#{cc}, #{cc}, #{cc})"
76
+ circle(cr, at: [cx, cy], fill: col).jitter(cr / 4, fn: cr)
77
+ end
78
+
79
+ rect(WIDTH, HEIGHT, fill: '#000')
80
+
81
+ background(n: 500 * QUALITY, star: 1.0 / 550)
82
+
83
+ galaxy(n: 4_000 * QUALITY, size: WIDTH / 5, star: 1.0 / 700, at: [WIDTH / 3, HEIGHT / 2])
84
+ galaxy(n: 1_300 * QUALITY, size: WIDTH / 12, star: 1.0 / 800, arms: 2, at: [WIDTH / 4 * 3, HEIGHT / 6])
85
+
86
+ asteroid(25, at: [WIDTH * 0.4, HEIGHT / 2.2])
87
+ asteroid(40, at: [WIDTH * 0.22, HEIGHT * 0.36])
88
+ asteroid(30, at: [WIDTH * 0.11, HEIGHT * 0.28])
89
+ asteroid(55, at: [WIDTH * 0.15, HEIGHT * 0.75])
90
+ asteroid(35, at: [WIDTH * 0.55, HEIGHT * 0.65])
91
+ asteroid(40, at: [WIDTH * 0.5, HEIGHT * 0.15])
92
+ asteroid(45, at: [WIDTH * 0.4, HEIGHT * 0.85])
93
+ asteroid(30, at: [WIDTH * 0.91, HEIGHT * 0.13])
94
+ asteroid(50, at: [WIDTH * 0.85, HEIGHT])
95
+
96
+ def helmet(size, at:)
97
+ s15 = size / 1.5
98
+ s2 = size / 2
99
+ s3 = size / 3
100
+ s4 = size / 4
101
+ s5 = size / 5
102
+ s6 = size / 6
103
+ s8 = size / 8
104
+ s10 = size / 10
105
+ s16 = size / 16
106
+ s32 = size / 32
107
+
108
+ metal = '#aaa'
109
+
110
+ outer = Path.new(
111
+ N.g(0, - s2 - s32),
112
+ N.l(s2 - s16, s8),
113
+ N.n(s2 - s8, s2 + s8),
114
+ N.n(-s2 + s16, s2 + s8),
115
+ N.r(-s2, s8)
116
+ )
117
+
118
+ visor_hole = Path.new(
119
+ N.n(-s2, -s15),
120
+ N.r(-s4, -s2 + s16),
121
+ N.l(-s4, s10),
122
+ N.n(-s15, s10)
123
+ )
124
+
125
+ visor_inner = Circle.new(s2)
126
+
127
+ neck_hole = Path.new(
128
+ N.n(-s2, s2 - s8 - s8),
129
+ N.s(0, s2 - s8),
130
+ N.n(s2, s2 - s8 - s8),
131
+ N.n(s2, size),
132
+ N.n(-s2, size)
133
+ )
134
+
135
+ move(*at) do
136
+ rotate(-20) do
137
+ difference(fill: '#976', opacity: 0.4) do
138
+ canvas << visor_inner
139
+ square(size * 2, at: [0, -s2])
140
+ square(size * 2, at: [-s15, s10])
141
+ circle(s16, at: [-s2, -s16]).jitter(s16 / 3, fn: 16)
142
+ end.rotate(20)
143
+
144
+ difference(fill: :white) do
145
+ canvas << outer
146
+ canvas << visor_hole
147
+ canvas << neck_hole
148
+ end
149
+
150
+ intersection(fill: metal) do
151
+ difference do
152
+ canvas << visor_hole.scale(1.2).move(s32, s32 / 2)
153
+ canvas << visor_hole
154
+ end
155
+ canvas << outer
156
+ end
157
+
158
+ intersection(fill: metal) do
159
+ difference do
160
+ canvas << outer
161
+ canvas << neck_hole
162
+ end
163
+ canvas << neck_hole.move(0, -s16)
164
+ end.scale(1.02)
165
+ end
166
+ end
167
+
168
+ circle(s16, at: [s10, -s32], fill: metal).move(*at)
169
+ end
170
+
171
+ helmet(HEIGHT / 3 * 2, at: [WIDTH / 4 * 3, HEIGHT / 2 + HEIGHT / 16])