hotcocoa 0.5.1 → 0.6.0pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (181) hide show
  1. data/.yardopts +14 -0
  2. data/History.txt +21 -0
  3. data/README.markdown +84 -0
  4. data/Rakefile +47 -0
  5. data/bin/hotcocoa +20 -10
  6. data/docs/Contributors.markdown +25 -0
  7. data/docs/Mappings.markdown +352 -0
  8. data/docs/MappingsExplained.markdown +22 -0
  9. data/docs/Overview.markdown +58 -0
  10. data/docs/Resources.markdown +25 -0
  11. data/docs/Tutorial.markdown +3 -0
  12. data/lib/hotcocoa/application/builder.rb +237 -0
  13. data/lib/hotcocoa/application/specification.rb +373 -0
  14. data/lib/hotcocoa/application_builder.rb +338 -242
  15. data/lib/hotcocoa/attributed_string_helpers.rb +128 -0
  16. data/lib/hotcocoa/behaviors.rb +39 -6
  17. data/lib/hotcocoa/core_extensions/kernel.rb +67 -0
  18. data/lib/hotcocoa/core_extensions/nsarray.rb +15 -0
  19. data/lib/hotcocoa/core_extensions/nsmutable_attributed_string.rb +74 -0
  20. data/lib/hotcocoa/core_extensions/nsstring.rb +36 -0
  21. data/lib/hotcocoa/core_extensions/nsurl.rb +6 -0
  22. data/lib/hotcocoa/core_extensions/numeric.rb +9 -0
  23. data/lib/hotcocoa/core_extensions/object.rb +36 -0
  24. data/lib/hotcocoa/core_extensions/range.rb +30 -0
  25. data/lib/hotcocoa/core_extensions.rb +8 -0
  26. data/lib/hotcocoa/data_sources/combo_box_data_source.rb +38 -38
  27. data/lib/hotcocoa/data_sources/outline_view_data_source.rb +33 -0
  28. data/lib/hotcocoa/data_sources/table_data_source.rb +12 -13
  29. data/lib/hotcocoa/data_sources.rb +3 -0
  30. data/lib/hotcocoa/delegate_builder.rb +114 -79
  31. data/lib/hotcocoa/graphics/canvas.rb +211 -214
  32. data/lib/hotcocoa/graphics/color.rb +89 -91
  33. data/lib/hotcocoa/graphics/elements/particle.rb +16 -19
  34. data/lib/hotcocoa/graphics/elements/rope.rb +12 -14
  35. data/lib/hotcocoa/graphics/elements/sandpainter.rb +11 -13
  36. data/lib/hotcocoa/graphics/gradient.rb +13 -14
  37. data/lib/hotcocoa/graphics/image.rb +110 -83
  38. data/lib/hotcocoa/graphics/path.rb +44 -50
  39. data/lib/hotcocoa/graphics/pdf.rb +17 -19
  40. data/lib/hotcocoa/graphics.rb +21 -20
  41. data/lib/hotcocoa/kvo_accessors.rb +10 -11
  42. data/lib/hotcocoa/layout_view.rb +394 -379
  43. data/lib/hotcocoa/mapper.rb +346 -207
  44. data/lib/hotcocoa/mapping_methods.rb +107 -37
  45. data/lib/hotcocoa/mappings/appkit/alert.rb +25 -0
  46. data/lib/hotcocoa/mappings/appkit/application.rb +112 -0
  47. data/lib/hotcocoa/mappings/{array_controller.rb → appkit/array_controller.rb} +33 -35
  48. data/lib/hotcocoa/mappings/appkit/box.rb +37 -0
  49. data/lib/hotcocoa/mappings/appkit/button.rb +88 -0
  50. data/lib/hotcocoa/mappings/appkit/collection_view.rb +42 -0
  51. data/lib/hotcocoa/mappings/appkit/color.rb +40 -0
  52. data/lib/hotcocoa/mappings/appkit/column.rb +19 -0
  53. data/lib/hotcocoa/mappings/appkit/combo_box.rb +22 -0
  54. data/lib/hotcocoa/mappings/appkit/control.rb +31 -0
  55. data/lib/hotcocoa/mappings/appkit/font.rb +58 -0
  56. data/lib/hotcocoa/mappings/appkit/gradient.rb +19 -0
  57. data/lib/hotcocoa/mappings/appkit/image.rb +15 -0
  58. data/lib/hotcocoa/mappings/appkit/image_view.rb +41 -0
  59. data/lib/hotcocoa/mappings/appkit/label.rb +23 -0
  60. data/lib/hotcocoa/mappings/appkit/layout_view.rb +9 -0
  61. data/lib/hotcocoa/mappings/appkit/line.rb +16 -0
  62. data/lib/hotcocoa/mappings/appkit/menu.rb +78 -0
  63. data/lib/hotcocoa/mappings/appkit/menu_item.rb +47 -0
  64. data/lib/hotcocoa/mappings/appkit/outline_view.rb +62 -0
  65. data/lib/hotcocoa/mappings/appkit/popup.rb +106 -0
  66. data/lib/hotcocoa/mappings/appkit/progress_indicator.rb +61 -0
  67. data/lib/hotcocoa/mappings/appkit/scroll_view.rb +28 -0
  68. data/lib/hotcocoa/mappings/appkit/search_field.rb +9 -0
  69. data/lib/hotcocoa/mappings/appkit/secure_text_field.rb +15 -0
  70. data/lib/hotcocoa/mappings/appkit/segmented_control.rb +103 -0
  71. data/lib/hotcocoa/mappings/appkit/slider.rb +23 -0
  72. data/lib/hotcocoa/mappings/appkit/sound.rb +9 -0
  73. data/lib/hotcocoa/mappings/appkit/speech_synthesizer.rb +22 -0
  74. data/lib/hotcocoa/mappings/appkit/split_view.rb +19 -0
  75. data/lib/hotcocoa/mappings/appkit/status_bar.rb +7 -0
  76. data/lib/hotcocoa/mappings/appkit/status_item.rb +9 -0
  77. data/lib/hotcocoa/mappings/appkit/table_view.rb +108 -0
  78. data/lib/hotcocoa/mappings/appkit/text_field.rb +36 -0
  79. data/lib/hotcocoa/mappings/appkit/text_view.rb +13 -0
  80. data/lib/hotcocoa/mappings/appkit/toolbar.rb +99 -0
  81. data/lib/hotcocoa/mappings/appkit/toolbar_item.rb +36 -0
  82. data/lib/hotcocoa/mappings/appkit/tracking_area.rb +24 -0
  83. data/lib/hotcocoa/mappings/appkit/view.rb +65 -0
  84. data/lib/hotcocoa/mappings/appkit/window.rb +124 -0
  85. data/lib/hotcocoa/mappings/foundation/net_service.rb +65 -0
  86. data/lib/hotcocoa/mappings/foundation/net_service_browser.rb +27 -0
  87. data/lib/hotcocoa/mappings/foundation/notification.rb +24 -0
  88. data/lib/hotcocoa/mappings/foundation/sort_descriptor.rb +17 -0
  89. data/lib/hotcocoa/mappings/foundation/timer.rb +38 -0
  90. data/lib/hotcocoa/mappings/foundation/user_defaults.rb +43 -0
  91. data/lib/hotcocoa/mappings/foundation/xml_parser.rb +44 -0
  92. data/lib/hotcocoa/mappings/qtkit/movie.rb +15 -0
  93. data/lib/hotcocoa/mappings/qtkit/movie_view.rb +28 -0
  94. data/lib/hotcocoa/mappings/webkit/web_view.rb +20 -0
  95. data/lib/hotcocoa/mappings.rb +57 -111
  96. data/lib/hotcocoa/mvc.rb +90 -81
  97. data/lib/hotcocoa/notification_listener.rb +135 -58
  98. data/lib/hotcocoa/standard_rake_tasks.rb +17 -9
  99. data/lib/hotcocoa/target_action_convenience.rb +39 -0
  100. data/lib/hotcocoa/template.rb +90 -21
  101. data/lib/hotcocoa/version.rb +3 -0
  102. data/lib/hotcocoa.rb +12 -14
  103. data/template/Rakefile +31 -3
  104. data/template/__APPLICATION_NAME__.appspec +8 -0
  105. data/template/lib/application.rb +14 -17
  106. data/template/lib/menu.rb +11 -11
  107. data/test/application/test_builder.rb +28 -0
  108. data/test/application/test_specification.rb +280 -0
  109. data/test/core_extensions/test_kernel.rb +66 -0
  110. data/test/core_extensions/test_nsarray.rb +9 -0
  111. data/test/core_extensions/test_nsmutable_attributed_string.rb +86 -0
  112. data/test/core_extensions/test_nsstring.rb +20 -0
  113. data/test/core_extensions/test_nsurl.rb +9 -0
  114. data/test/core_extensions/test_numeric.rb +10 -0
  115. data/test/core_extensions/test_object.rb +37 -0
  116. data/test/core_extensions/test_range.rb +28 -0
  117. data/test/helper.rb +30 -0
  118. data/test/mappings/test_bonjour.rb +79 -0
  119. data/test/mappings/test_color.rb +16 -0
  120. data/test/mappings/test_font.rb +21 -0
  121. data/test/mappings/test_tracking_area.rb +18 -0
  122. data/test/test_application_builder.rb +95 -0
  123. data/test/test_attributed_string_helpers.rb +63 -0
  124. data/test/test_behaviours.rb +26 -0
  125. data/test/test_bin.rb +75 -0
  126. data/test/test_mapper.rb +100 -0
  127. data/test/test_mapping_methods.rb +67 -0
  128. data/test/test_mappings.rb +68 -0
  129. data/test/test_notification_listener.rb +19 -0
  130. data/test/test_template.rb +65 -0
  131. metadata +217 -90
  132. data/lib/hotcocoa/attributed_string.rb +0 -143
  133. data/lib/hotcocoa/kernel_ext.rb +0 -14
  134. data/lib/hotcocoa/mappings/alert.rb +0 -25
  135. data/lib/hotcocoa/mappings/application.rb +0 -112
  136. data/lib/hotcocoa/mappings/box.rb +0 -39
  137. data/lib/hotcocoa/mappings/button.rb +0 -92
  138. data/lib/hotcocoa/mappings/collection_view.rb +0 -44
  139. data/lib/hotcocoa/mappings/color.rb +0 -28
  140. data/lib/hotcocoa/mappings/column.rb +0 -21
  141. data/lib/hotcocoa/mappings/combo_box.rb +0 -24
  142. data/lib/hotcocoa/mappings/control.rb +0 -33
  143. data/lib/hotcocoa/mappings/font.rb +0 -44
  144. data/lib/hotcocoa/mappings/gradient.rb +0 -15
  145. data/lib/hotcocoa/mappings/image.rb +0 -15
  146. data/lib/hotcocoa/mappings/image_view.rb +0 -43
  147. data/lib/hotcocoa/mappings/label.rb +0 -25
  148. data/lib/hotcocoa/mappings/layout_view.rb +0 -9
  149. data/lib/hotcocoa/mappings/menu.rb +0 -71
  150. data/lib/hotcocoa/mappings/menu_item.rb +0 -47
  151. data/lib/hotcocoa/mappings/movie.rb +0 -13
  152. data/lib/hotcocoa/mappings/movie_view.rb +0 -27
  153. data/lib/hotcocoa/mappings/notification.rb +0 -17
  154. data/lib/hotcocoa/mappings/popup.rb +0 -110
  155. data/lib/hotcocoa/mappings/progress_indicator.rb +0 -68
  156. data/lib/hotcocoa/mappings/scroll_view.rb +0 -29
  157. data/lib/hotcocoa/mappings/search_field.rb +0 -9
  158. data/lib/hotcocoa/mappings/secure_text_field.rb +0 -17
  159. data/lib/hotcocoa/mappings/segmented_control.rb +0 -97
  160. data/lib/hotcocoa/mappings/slider.rb +0 -25
  161. data/lib/hotcocoa/mappings/sort_descriptor.rb +0 -13
  162. data/lib/hotcocoa/mappings/sound.rb +0 -9
  163. data/lib/hotcocoa/mappings/speech_synthesizer.rb +0 -25
  164. data/lib/hotcocoa/mappings/split_view.rb +0 -21
  165. data/lib/hotcocoa/mappings/status_bar.rb +0 -7
  166. data/lib/hotcocoa/mappings/status_item.rb +0 -9
  167. data/lib/hotcocoa/mappings/table_view.rb +0 -110
  168. data/lib/hotcocoa/mappings/text_field.rb +0 -41
  169. data/lib/hotcocoa/mappings/text_view.rb +0 -13
  170. data/lib/hotcocoa/mappings/timer.rb +0 -25
  171. data/lib/hotcocoa/mappings/toolbar.rb +0 -100
  172. data/lib/hotcocoa/mappings/toolbar_item.rb +0 -36
  173. data/lib/hotcocoa/mappings/view.rb +0 -67
  174. data/lib/hotcocoa/mappings/web_view.rb +0 -22
  175. data/lib/hotcocoa/mappings/window.rb +0 -118
  176. data/lib/hotcocoa/mappings/xml_parser.rb +0 -41
  177. data/lib/hotcocoa/object_ext.rb +0 -22
  178. data/lib/hotcocoa/plist.rb +0 -45
  179. data/template/config/build.yml +0 -8
  180. data/test/test_helper.rb +0 -3
  181. data/test/test_hotcocoa.rb +0 -11
@@ -1,12 +1,12 @@
1
- # Ruby Cocoa Graphics is a graphics library providing a simple object-oriented
2
- # interface into the power of Mac OS X's Core Graphics and Core Image drawing libraries.
3
- # With a few lines of easy-to-read code, you can write scripts to draw simple or complex
4
- # shapes, lines, and patterns, process and filter images, create abstract art or visualize
1
+ # Ruby Cocoa Graphics is a graphics library providing a simple object-oriented
2
+ # interface into the power of Mac OS X's Core Graphics and Core Image drawing libraries.
3
+ # With a few lines of easy-to-read code, you can write scripts to draw simple or complex
4
+ # shapes, lines, and patterns, process and filter images, create abstract art or visualize
5
5
  # scientific data, and much more.
6
- #
7
- # Inspiration for this project was derived from Processing and NodeBox. These excellent
8
- # graphics programming environments are more full-featured than RCG, but they are implemented
9
- # in Java and Python, respectively. RCG was created to offer similar functionality using
6
+ #
7
+ # Inspiration for this project was derived from Processing and NodeBox. These excellent
8
+ # graphics programming environments are more full-featured than RCG, but they are implemented
9
+ # in Java and Python, respectively. RCG was created to offer similar functionality using
10
10
  # the Ruby programming language.
11
11
  #
12
12
  # Author:: James Reynolds (mailto:drtoast@drtoast.com)
@@ -17,22 +17,22 @@ module HotCocoa::Graphics
17
17
 
18
18
  # define and manipulate colors in RGBA format
19
19
  class Color
20
-
20
+
21
21
  # License: GPL - includes ports of some code by Tom De Smedt, Frederik De Bleser
22
-
22
+
23
23
  #attr_accessor :r,:g,:b,:a
24
24
  attr_accessor :rgb
25
25
  # def initialize(r=0.0,g=0.0,b=0.0,a=1.0)
26
26
  # @c = CGColorCreate(@colorspace, [r,g,b,a])
27
27
  # end
28
-
28
+
29
29
  # create a new color with the given RGBA values
30
30
  def initialize(r=0.0, g=0.0, b=1.0, a=1.0)
31
31
  @nsColor = NSColor.colorWithDeviceRed r, green:g, blue:b, alpha:a
32
32
  @rgb = @nsColor.colorUsingColorSpaceName NSDeviceRGBColorSpace
33
33
  self
34
34
  end
35
-
35
+
36
36
  COLORNAMES = {
37
37
  "lightpink" => [1.00, 0.71, 0.76],
38
38
  "pink" => [1.00, 0.75, 0.80],
@@ -178,7 +178,7 @@ module HotCocoa::Graphics
178
178
  #"transparent" => [0.00, 0.00, 0.00, 0.00],
179
179
  "bark" => [0.25, 0.19, 0.13]
180
180
  }
181
-
181
+
182
182
  RYBWheel = [
183
183
  [ 0, 0], [ 15, 8],
184
184
  [ 30, 17], [ 45, 26],
@@ -203,7 +203,7 @@ module HotCocoa::Graphics
203
203
  end
204
204
  end
205
205
  end
206
-
206
+
207
207
  # create a color with the specified name
208
208
  def self.named(name)
209
209
  if COLORNAMES[name]
@@ -226,7 +226,7 @@ module HotCocoa::Graphics
226
226
  end
227
227
  color
228
228
  end
229
-
229
+
230
230
  # return the name of the nearest named color
231
231
  def name
232
232
  nearest, d = ["", 1.0]
@@ -244,22 +244,22 @@ module HotCocoa::Graphics
244
244
  end
245
245
  nearest
246
246
  end
247
-
247
+
248
248
  # return a copy of this color
249
249
  def copy
250
250
  Color.new(r, g, b, a)
251
251
  end
252
-
252
+
253
253
  # print the color's component values
254
254
  def to_s
255
255
  "color: #{name} (#{r} #{g} #{b} #{a})"
256
256
  end
257
-
257
+
258
258
  # sort the color by brightness in an array
259
259
  def <=> othercolor
260
260
  self.brightness <=> othercolor.brightness || self.hue <=> othercolor.hue
261
261
  end
262
-
262
+
263
263
  # set or retrieve the red component
264
264
  def r(val=nil)
265
265
  if val
@@ -270,7 +270,7 @@ module HotCocoa::Graphics
270
270
  @rgb.redComponent
271
271
  end
272
272
  end
273
-
273
+
274
274
  # set or retrieve the green component
275
275
  def g(val=nil)
276
276
  if val
@@ -281,7 +281,7 @@ module HotCocoa::Graphics
281
281
  @rgb.greenComponent
282
282
  end
283
283
  end
284
-
284
+
285
285
  # set or retrieve the blue component
286
286
  def b(val=nil)
287
287
  if val
@@ -292,7 +292,7 @@ module HotCocoa::Graphics
292
292
  @rgb.blueComponent
293
293
  end
294
294
  end
295
-
295
+
296
296
  # set or retrieve the alpha component
297
297
  def a(val=nil)
298
298
  if val
@@ -303,7 +303,7 @@ module HotCocoa::Graphics
303
303
  @rgb.alphaComponent
304
304
  end
305
305
  end
306
-
306
+
307
307
  # set or retrieve the hue
308
308
  def hue(val=nil)
309
309
  if val
@@ -314,7 +314,7 @@ module HotCocoa::Graphics
314
314
  @rgb.hueComponent
315
315
  end
316
316
  end
317
-
317
+
318
318
  # set or retrieve the saturation
319
319
  def saturation(val=nil)
320
320
  if val
@@ -325,7 +325,7 @@ module HotCocoa::Graphics
325
325
  @rgb.saturationComponent
326
326
  end
327
327
  end
328
-
328
+
329
329
  # set or retrieve the brightness
330
330
  def brightness(val=nil)
331
331
  if val
@@ -336,75 +336,75 @@ module HotCocoa::Graphics
336
336
  @rgb.brightnessComponent
337
337
  end
338
338
  end
339
-
339
+
340
340
  # decrease saturation by the specified amount
341
341
  def desaturate(step=0.1)
342
342
  saturation(saturation - step)
343
343
  self
344
344
  end
345
-
345
+
346
346
  # increase the saturation by the specified amount
347
347
  def saturate(step=0.1)
348
348
  saturation(saturation + step)
349
349
  self
350
350
  end
351
-
351
+
352
352
  # decrease the brightness by the specified amount
353
353
  def darken(step=0.1)
354
354
  brightness(brightness - step)
355
355
  self
356
356
  end
357
-
357
+
358
358
  # increase the brightness by the specified amount
359
359
  def lighten(step=0.1)
360
360
  brightness(brightness + step)
361
361
  self
362
362
  end
363
-
363
+
364
364
  # set the R,G,B,A values
365
365
  def set(r, g, b, a=1.0)
366
366
  set_rgb(r, g, b, a)
367
367
  self
368
368
  end
369
-
369
+
370
370
  # adjust the Red, Green, Blue, Alpha values by the specified amounts
371
371
  def adjust_rgb(r=0.0, g=0.0, b=0.0, a=0.0)
372
372
  r0, g0, b0, a0 = get_rgb
373
373
  set_rgb(r0+r, g0+g, b0+b, a0+a)
374
374
  self
375
375
  end
376
-
376
+
377
377
  # return RGBA values
378
378
  def get_rgb
379
379
  #@rgb.getRed_green_blue_alpha_()
380
380
  [@rgb.redComponent, @rgb.greenComponent, @rgb.blueComponent, @rgb.alphaComponent]
381
381
  end
382
-
382
+
383
383
  # set color using RGBA values
384
384
  def set_rgb(r, g, b, a=1.0)
385
385
  @rgb = NSColor.colorWithDeviceRed r, green:g, blue:b, alpha:a
386
386
  self
387
387
  end
388
-
388
+
389
389
  # return HSBA values
390
390
  def get_hsb
391
391
  #@rgb.getHue_saturation_brightness_alpha_()
392
392
  [@rgb.hueComponent, @rgb.saturationComponent, @rgb.brightnessComponent, @rgb.alphaComponent]
393
393
  end
394
-
394
+
395
395
  # set color using HSBA values
396
396
  def set_hsb(h,s,b,a=1.0)
397
397
  @rgb = NSColor.colorWithDeviceHue h, saturation:s, brightness:b, alpha:a
398
398
  self
399
399
  end
400
-
400
+
401
401
  # adjust Hue, Saturation, Brightness, and Alpha by specified amounts
402
402
  def adjust_hsb(h=0.0, s=0.0, b=0.0, a=0.0)
403
403
  h0, s0, b0, a0 = get_hsb
404
404
  set_hsb(h0+h, s0+s, b0+b, a0+a)
405
405
  self
406
406
  end
407
-
407
+
408
408
  # alter the color by the specified random scaling factor
409
409
  # def ish(angle=10.0,d=0.02)
410
410
  # # r,g,b,a = get_rgb
@@ -416,13 +416,13 @@ module HotCocoa::Graphics
416
416
  # analog(angle,d)
417
417
  # self
418
418
  # end
419
-
419
+
420
420
  # create a random color
421
421
  def random
422
422
  set_rgb(rand, rand, rand, 1.0)
423
423
  self
424
424
  end
425
-
425
+
426
426
  # rotate the color on the artistic RYB color wheel (0 to 360 degrees)
427
427
  def rotate_ryb(angle=180)
428
428
 
@@ -430,7 +430,7 @@ module HotCocoa::Graphics
430
430
  # (e.g. purple-yellow instead of purple-lime).
431
431
  # It is mathematically incorrect but generally assumed
432
432
  # to provide better complementary colors.
433
- #
433
+ #
434
434
  # http://en.wikipedia.org/wiki/RYB_color_model
435
435
 
436
436
  h = hue * 360
@@ -439,13 +439,13 @@ module HotCocoa::Graphics
439
439
 
440
440
  # Approximation of Itten's RYB color wheel.
441
441
  # In HSB, colors hues range from 0-360.
442
- # However, on the artistic color wheel these are not evenly distributed.
442
+ # However, on the artistic color wheel these are not evenly distributed.
443
443
  # The second tuple value contains the actual distribution.
444
444
 
445
445
  # Given a hue, find out under what angle it is
446
446
  # located on the artistic color wheel.
447
447
  (RYBWheel.size-1).times do |i|
448
- x0,y0 = RYBWheel[i]
448
+ x0,y0 = RYBWheel[i]
449
449
  x1,y1 = RYBWheel[i+1]
450
450
  y1 += 360 if y1 < y0
451
451
  if y0 <= h && h <= y1
@@ -453,14 +453,14 @@ module HotCocoa::Graphics
453
453
  break
454
454
  end
455
455
  end
456
-
456
+
457
457
  # And the user-given angle (e.g. complement).
458
458
  a = (a+angle) % 360
459
459
 
460
460
  # For the given angle, find out what hue is
461
461
  # located there on the artistic color wheel.
462
462
  (RYBWheel.size-1).times do |i|
463
- x0,y0 = RYBWheel[i]
463
+ x0,y0 = RYBWheel[i]
464
464
  x1,y1 = RYBWheel[i+1]
465
465
  y1 += 360 if y1 < y0
466
466
  if x0 <= a && a <= x1
@@ -468,12 +468,12 @@ module HotCocoa::Graphics
468
468
  break
469
469
  end
470
470
  end
471
-
471
+
472
472
  h = h % 360
473
473
  set_hsb(h/360, self.saturation, self.brightness, self.a)
474
474
  self
475
475
  end
476
-
476
+
477
477
  # rotate the color on the RGB color wheel (0 to 360 degrees)
478
478
  def rotate_rgb(angle=180)
479
479
  hue = (self.hue + 1.0 * angle / 360) % 1
@@ -488,7 +488,7 @@ module HotCocoa::Graphics
488
488
  c.lighten(d * (rand*2-1))
489
489
  c.saturate(d * (rand*2-1))
490
490
  end
491
-
491
+
492
492
  # randomly vary the color within a maximum hue range, saturation range, and brightness range
493
493
  def drift(maxhue=0.1,maxsat=0.3,maxbright=maxsat)
494
494
  # save original values the first time
@@ -512,7 +512,7 @@ module HotCocoa::Graphics
512
512
  self.brightness(randbright)
513
513
  self
514
514
  end
515
-
515
+
516
516
  # convert to the complementary color (the color at opposite on the artistic color wheel)
517
517
  def complement
518
518
  rotate_ryb(180)
@@ -525,22 +525,22 @@ module HotCocoa::Graphics
525
525
  # @rgb = blended.colorUsingColorSpaceName(NSDeviceRGBColorSpace)
526
526
  # self
527
527
  # end
528
-
528
+
529
529
  # create a new RGBA color
530
530
  def self.rgb(r, g, b, a=1.0)
531
531
  Color.new(r,g,b,a)
532
532
  end
533
-
533
+
534
534
  # create a new HSBA color
535
535
  def self.hsb(h, s, b, a=1.0)
536
536
  Color.new.set_hsb(h,s,b,a)
537
537
  end
538
-
538
+
539
539
  # create a new gray color with the specified darkness
540
540
  def self.gray(pct=0.5)
541
541
  Color.new(pct,pct,pct,1.0)
542
542
  end
543
-
543
+
544
544
  # return a random color
545
545
  def self.random
546
546
  Color.new.random
@@ -555,7 +555,7 @@ module HotCocoa::Graphics
555
555
  # 6) LIGHT SUPPORTING COMPLEMENT VARIANT: a lighter less saturated version of the complement hue
556
556
  def complementary
557
557
  colors = []
558
-
558
+
559
559
  # A contrasting color: much darker or lighter than the original.
560
560
  colors.push(self)
561
561
  c = self.copy
@@ -565,13 +565,13 @@ module HotCocoa::Graphics
565
565
  c.brightness(1.0 - c.brightness*0.25)
566
566
  end
567
567
  colors.push(c)
568
-
568
+
569
569
  # A soft supporting color: lighter and less saturated.
570
570
  c = self.copy
571
571
  c.brightness(0.3 + c.brightness)
572
572
  c.saturation(0.1 + c.saturation*0.3)
573
573
  colors.push(c)
574
-
574
+
575
575
  # A contrasting complement: very dark or very light.
576
576
  c_comp = self.copy.complement
577
577
  c = c_comp.copy
@@ -580,17 +580,17 @@ module HotCocoa::Graphics
580
580
  else
581
581
  c.brightness(1.0 - c.brightness*0.25)
582
582
  end
583
- colors.push(c)
584
-
583
+ colors.push(c)
584
+
585
585
  # The complement
586
586
  colors.push(c_comp)
587
-
587
+
588
588
  # and a light supporting variant.
589
589
  c = c_comp.copy
590
590
  c.brightness(0.3 + c.brightness)
591
591
  c.saturation(0.1 + c.saturation*0.25)
592
592
  colors.push(c)
593
-
593
+
594
594
  colors
595
595
  end
596
596
 
@@ -605,7 +605,7 @@ module HotCocoa::Graphics
605
605
  colors.push(comp.copy.rotate_ryb(angle).lighten(0.1))
606
606
  colors
607
607
  end
608
-
608
+
609
609
  # Returns the left half of the split complement.
610
610
  # A list is returned with the same darker and softer colors
611
611
  # as in the complementary list, but using the hue of the
@@ -618,7 +618,7 @@ module HotCocoa::Graphics
618
618
  colors[5].hue(left.hue)
619
619
  colors
620
620
  end
621
-
621
+
622
622
  # Returns the right half of the split complement.
623
623
  # A list is returned with the same darker and softer colors
624
624
  # as in the complementary list, but using the hue of the
@@ -631,10 +631,10 @@ module HotCocoa::Graphics
631
631
  colors[5].hue(right.hue)
632
632
  colors
633
633
  end
634
-
634
+
635
635
  # Returns colors that are next to each other on the wheel.
636
636
  # These yield natural color schemes (like shades of water or sky).
637
- # The angle determines how far the colors are apart,
637
+ # The angle determines how far the colors are apart,
638
638
  # making it bigger will introduce more variation.
639
639
  # The contrast determines the darkness/lightness of
640
640
  # the analogue colors in respect to the given colors.
@@ -658,7 +658,7 @@ module HotCocoa::Graphics
658
658
  colors
659
659
  end
660
660
 
661
- # Returns colors in the same hue with varying brightness/saturation.
661
+ # Returns colors in the same hue with varying brightness/saturation.
662
662
  def monochrome
663
663
 
664
664
  colors = [self]
@@ -683,10 +683,10 @@ module HotCocoa::Graphics
683
683
 
684
684
  colors
685
685
  end
686
-
686
+
687
687
  # Returns a triad of colors.
688
688
  # The triad is made up of this color and two other colors
689
- # that together make up an equilateral triangle on
689
+ # that together make up an equilateral triangle on
690
690
  # the artistic color wheel.
691
691
  def triad(angle=120)
692
692
  colors = [self]
@@ -694,7 +694,7 @@ module HotCocoa::Graphics
694
694
  colors.push(copy.rotate_ryb(-angle).lighten(0.1))
695
695
  colors
696
696
  end
697
-
697
+
698
698
  # Returns a tetrad of colors.
699
699
  # The tetrad is made up of this color and three other colors
700
700
  # that together make up a cross on the artistic color wheel.
@@ -707,7 +707,7 @@ module HotCocoa::Graphics
707
707
  c.brightness(c.brightness + 0.2)
708
708
  else
709
709
  c.brightness(c.brightness - 0.2)
710
- end
710
+ end
711
711
  colors.push(c)
712
712
 
713
713
  c = copy.rotate_ryb(angle*2)
@@ -716,17 +716,17 @@ module HotCocoa::Graphics
716
716
  else
717
717
  c.brightness(c.brightness - 0.1)
718
718
  end
719
-
719
+
720
720
  colors.push(c)
721
721
  colors.push(copy.rotate_ryb(angle*3).lighten(0.1))
722
722
  colors
723
723
  end
724
-
724
+
725
725
  # Roughly the complement and some far analogs.
726
726
  def compound(flip=false)
727
-
727
+
728
728
  d = (flip ? -1 : 1)
729
-
729
+
730
730
  colors = [self]
731
731
 
732
732
  c = copy.rotate_ryb(30*d)
@@ -755,30 +755,28 @@ module HotCocoa::Graphics
755
755
 
756
756
  colors
757
757
  end
758
-
758
+
759
759
  # Roughly the complement and some far analogs.
760
760
  def flipped_compound
761
761
  compound(true)
762
762
  end
763
-
763
+
764
764
  private
765
-
766
- # vary a single color component by a multiplier
767
- def vary(original, variance)
768
- newvalue = original + (rand * variance * (rand > 0.5 ? 1 : -1))
769
- newvalue = inrange(newvalue,0.0,1.0)
770
- newvalue
771
- end
772
-
773
- # wrap within range
774
- def _wrap(x, min, threshold, plus)
775
- if x - min < threshold
776
- x + plus
777
- else
778
- x - min
779
- end
765
+
766
+ # vary a single color component by a multiplier
767
+ def vary(original, variance)
768
+ newvalue = original + (rand * variance * (rand > 0.5 ? 1 : -1))
769
+ newvalue = inrange(newvalue,0.0,1.0)
770
+ newvalue
771
+ end
772
+
773
+ # wrap within range
774
+ def _wrap(x, min, threshold, plus)
775
+ if x - min < threshold
776
+ x + plus
777
+ else
778
+ x - min
780
779
  end
781
-
780
+ end
782
781
  end
783
-
784
782
  end
@@ -1,12 +1,12 @@
1
- # Ruby Cocoa Graphics is a graphics library providing a simple object-oriented
2
- # interface into the power of Mac OS X's Core Graphics and Core Image drawing libraries.
3
- # With a few lines of easy-to-read code, you can write scripts to draw simple or complex
4
- # shapes, lines, and patterns, process and filter images, create abstract art or visualize
1
+ # Ruby Cocoa Graphics is a graphics library providing a simple object-oriented
2
+ # interface into the power of Mac OS X's Core Graphics and Core Image drawing libraries.
3
+ # With a few lines of easy-to-read code, you can write scripts to draw simple or complex
4
+ # shapes, lines, and patterns, process and filter images, create abstract art or visualize
5
5
  # scientific data, and much more.
6
- #
7
- # Inspiration for this project was derived from Processing and NodeBox. These excellent
8
- # graphics programming environments are more full-featured than RCG, but they are implemented
9
- # in Java and Python, respectively. RCG was created to offer similar functionality using
6
+ #
7
+ # Inspiration for this project was derived from Processing and NodeBox. These excellent
8
+ # graphics programming environments are more full-featured than RCG, but they are implemented
9
+ # in Java and Python, respectively. RCG was created to offer similar functionality using
10
10
  # the Ruby programming language.
11
11
  #
12
12
  # Author:: James Reynolds (mailto:drtoast@drtoast.com)
@@ -14,32 +14,31 @@
14
14
  # License:: Distributes under the same terms as Ruby
15
15
 
16
16
  module HotCocoa::Graphics
17
-
18
- # wandering particle with brownian motion
19
- class Particle
20
17
 
18
+ # wandering particle with brownian motion
19
+ class Particle
21
20
  attr_accessor :acceleration, :points, :stroke, :velocity_x, :velocity_y, :x, :y
22
21
 
23
22
  # initialize particle origin x,y coordinates (relative to the center)
24
23
  def initialize (x, y, velocity_x=0.0, velocity_y=2.0)
25
24
  @age = 0
26
25
  @acceleration = 0.5
27
-
26
+
28
27
  @x = x
29
28
  @y = y
30
-
29
+
31
30
  @previous_x = 0
32
31
  @previous_y = 0
33
32
 
34
33
  # initialize velocity
35
34
  @velocity_x=velocity_x
36
35
  @velocity_y=velocity_y
37
-
36
+
38
37
  # append the point to the array
39
38
  @points = [NSPoint.new(@x, @y)]
40
39
  @stroke = Color.white
41
40
  end
42
-
41
+
43
42
  # move to a new position using brownian motion
44
43
  def move
45
44
  # save old x,y position
@@ -57,19 +56,17 @@ module HotCocoa::Graphics
57
56
  # draw a line from the old position to the new
58
57
  #CANVAS.line(@previous_x,@previous_y,@x,@y);
59
58
  @points.push(NSPoint.new(@x, @y))
60
-
59
+
61
60
  # grow old
62
61
  @age += 1
63
62
  if @age>200
64
63
  # die and be reborn
65
64
  end
66
-
67
65
  end
68
-
66
+
69
67
  def draw(canvas)
70
68
  canvas.nofill
71
69
  canvas.lines(@points)
72
70
  end
73
-
74
71
  end
75
72
  end
@@ -1,12 +1,12 @@
1
- # Ruby Cocoa Graphics is a graphics library providing a simple object-oriented
2
- # interface into the power of Mac OS X's Core Graphics and Core Image drawing libraries.
3
- # With a few lines of easy-to-read code, you can write scripts to draw simple or complex
4
- # shapes, lines, and patterns, process and filter images, create abstract art or visualize
1
+ # Ruby Cocoa Graphics is a graphics library providing a simple object-oriented
2
+ # interface into the power of Mac OS X's Core Graphics and Core Image drawing libraries.
3
+ # With a few lines of easy-to-read code, you can write scripts to draw simple or complex
4
+ # shapes, lines, and patterns, process and filter images, create abstract art or visualize
5
5
  # scientific data, and much more.
6
- #
7
- # Inspiration for this project was derived from Processing and NodeBox. These excellent
8
- # graphics programming environments are more full-featured than RCG, but they are implemented
9
- # in Java and Python, respectively. RCG was created to offer similar functionality using
6
+ #
7
+ # Inspiration for this project was derived from Processing and NodeBox. These excellent
8
+ # graphics programming environments are more full-featured than RCG, but they are implemented
9
+ # in Java and Python, respectively. RCG was created to offer similar functionality using
10
10
  # the Ruby programming language.
11
11
  #
12
12
  # Author:: James Reynolds (mailto:drtoast@drtoast.com)
@@ -14,11 +14,9 @@
14
14
  # License:: Distributes under the same terms as Ruby
15
15
 
16
16
  module HotCocoa::Graphics
17
-
18
17
  class Rope
19
-
20
18
  attr_accessor :x0, :y0, :x1, :y1, :width, :fibers, :roundness, :strokewidth
21
-
19
+
22
20
  def initialize(canvas, options={})
23
21
  @canvas = canvas
24
22
  @width = options[:width] || 200
@@ -26,7 +24,7 @@ module HotCocoa::Graphics
26
24
  @roundness = options[:roundness] || 1.0
27
25
  @strokewidth = options[:strokewidth] || 0.4
28
26
  end
29
-
27
+
30
28
  def hair(hair_x0=@x0, hair_y0=@y0, hair_x1=@x1, hair_y1=@y1, hair_width=@width, hair_fibers=@fibers)
31
29
  @canvas.push
32
30
  @canvas.strokewidth(@strokewidth)
@@ -52,7 +50,7 @@ module HotCocoa::Graphics
52
50
  end
53
51
  @canvas.pop
54
52
  end
55
-
53
+
56
54
  def ribbon(ribbon_x0=@x0, ribbon_y0=@y0, ribbon_x1=@x1, ribbon_y1=@y1, ribbon_width=@width, ribbon_fibers=@fibers)
57
55
  @canvas.push
58
56
  @canvas.strokewidth(@strokewidth)
@@ -84,7 +82,7 @@ module HotCocoa::Graphics
84
82
  # @canvas.fill(white)
85
83
  # @canvas.oval(cpx1,cpy1,5,5,:center)
86
84
  # @canvas.nofill
87
-
85
+
88
86
  @canvas.beginpath(x0, y0)
89
87
  @canvas.curveto(
90
88
  cpx0, cpy0, # control point 1