/libs/ObjectAL/Actions/OALFunction.h

http://github.com/kstenerud/ObjectAL-for-iPhone · C Header · 266 lines · 55 code · 57 blank · 154 comment · 0 complexity · b11ec31c955839e9f1566b4c9bc60790 MD5 · raw file

  1. //
  2. // OALFunction.h
  3. // ObjectAL
  4. //
  5. // Created by Karl Stenerud on 10-08-22.
  6. //
  7. // Copyright 2010 Karl Stenerud
  8. //
  9. // Licensed under the Apache License, Version 2.0 (the "License");
  10. // you may not use this file except in compliance with the License.
  11. // You may obtain a copy of the License at
  12. //
  13. // http://www.apache.org/licenses/LICENSE-2.0
  14. //
  15. // Unless required by applicable law or agreed to in writing, software
  16. // distributed under the License is distributed on an "AS IS" BASIS,
  17. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18. // See the License for the specific language governing permissions and
  19. // limitations under the License.
  20. //
  21. // Note: You are NOT required to make the license available from within your
  22. // iOS application. Including it in your project is sufficient.
  23. //
  24. // Attribution is not required, but appreciated :)
  25. //
  26. #import <Foundation/Foundation.h>
  27. #import "SynthesizeSingleton.h"
  28. #pragma mark OALFunction
  29. /**
  30. * A function takes a value from 0.0 to 1.0 and returns
  31. * another value from 0.0 to 1.0.
  32. */
  33. @protocol OALFunction
  34. #pragma mark Function
  35. /** Calculate the function value.
  36. *
  37. * @param inputValue A value from 0.0 to 1.0
  38. * @return The resulting value, which will also be from 0.0 to 1.0.
  39. */
  40. - (float) valueForInput:(float) inputValue;
  41. @end
  42. #pragma mark -
  43. #pragma mark OALLinearFunction
  44. /** Function that changes at a constant rate.
  45. * <pre>
  46. ##
  47. ##
  48. ##
  49. ##
  50. ##
  51. ##
  52. ##
  53. ##
  54. ##
  55. ##
  56. ##
  57. </pre>
  58. */
  59. @interface OALLinearFunction : NSObject <OALFunction>
  60. {
  61. }
  62. #pragma mark Object Management
  63. /** Singleton implementation providing "sharedInstance" and "purgeSharedInstance" methods.
  64. *
  65. * <b>- (OALLinearFunction*) sharedInstance</b>: Get the shared singleton instance. <br>
  66. * <b>- (void) purgeSharedInstance</b>: Purge (deallocate) the shared instance.
  67. */
  68. SYNTHESIZE_SINGLETON_FOR_CLASS_HEADER(OALLinearFunction);
  69. /** Generate an instance of this function.
  70. *
  71. * @return An instance of this function.
  72. */
  73. + (id) function;
  74. @end
  75. #pragma mark -
  76. #pragma mark OALSCurveFunction
  77. /** Changes slowly at the start, quickly at the midpoint, then slowly
  78. * again at the end.
  79. * <pre>
  80. ####
  81. ###
  82. ##
  83. #
  84. #
  85. #
  86. #
  87. #
  88. ##
  89. ###
  90. ####
  91. </pre>
  92. */
  93. @interface OALSCurveFunction : NSObject <OALFunction>
  94. {
  95. }
  96. #pragma mark Object Management
  97. /** Singleton implementation providing "sharedInstance" and "purgeSharedInstance" methods.
  98. *
  99. * <b>- (OALSCurveFunction*) sharedInstance</b>: Get the shared singleton instance. <br>
  100. * <b>- (void) purgeSharedInstance</b>: Purge (deallocate) the shared instance.
  101. */
  102. SYNTHESIZE_SINGLETON_FOR_CLASS_HEADER(OALSCurveFunction);
  103. /** Generate an instance of this function.
  104. *
  105. * @return An instance of this function.
  106. */
  107. + (id) function;
  108. @end
  109. #pragma mark -
  110. #pragma mark OALExponentialFunction
  111. /** Changes slowly at the start, and quickly at the end.
  112. * <pre>
  113. #
  114. #
  115. #
  116. #
  117. #
  118. #
  119. ##
  120. ###
  121. ####
  122. #####
  123. ######
  124. </pre>
  125. */
  126. @interface OALExponentialFunction : NSObject <OALFunction>
  127. {
  128. }
  129. #pragma mark Object Management
  130. /** Singleton implementation providing "sharedInstance" and "purgeSharedInstance" methods.
  131. *
  132. * <b>- (OALExponentialFunction*) sharedInstance</b>: Get the shared singleton instance. <br>
  133. * <b>- (void) purgeSharedInstance</b>: Purge (deallocate) the shared instance.
  134. */
  135. SYNTHESIZE_SINGLETON_FOR_CLASS_HEADER(OALExponentialFunction);
  136. /** Generate an instance of this function.
  137. *
  138. * @return An instance of this function.
  139. */
  140. + (id) function;
  141. @end
  142. #pragma mark -
  143. #pragma mark OALLogarithmicFunction
  144. /** Changes quickly at the start, and slowly at the end.
  145. * <pre>
  146. ######
  147. #####
  148. ####
  149. ###
  150. ##
  151. #
  152. #
  153. #
  154. #
  155. #
  156. #
  157. </pre>
  158. */
  159. @interface OALLogarithmicFunction : NSObject <OALFunction>
  160. {
  161. }
  162. #pragma mark Object Management
  163. /** Singleton implementation providing "sharedInstance" and "purgeSharedInstance" methods.
  164. *
  165. * <b>- (OALLogarithmicFunction*) sharedInstance</b>: Get the shared singleton instance. <br>
  166. * <b>- (void) purgeSharedInstance</b>: Purge (deallocate) the shared instance.
  167. */
  168. SYNTHESIZE_SINGLETON_FOR_CLASS_HEADER(OALLogarithmicFunction);
  169. /** Generate an instance of this function.
  170. *
  171. * @return An instance of this function.
  172. */
  173. + (id) function;
  174. @end
  175. #pragma mark -
  176. #pragma mark OALReverseFunction
  177. /** Returns the reverse of another function.
  178. * For example, a linear up ramp will become a linear down ramp:
  179. * <pre>
  180. | Before: | After: |
  181. | ## | ## |
  182. | ## | ## |
  183. | ## | ## |
  184. | ## | ## |
  185. | ## | ## |
  186. | ## | ## |
  187. </pre>
  188. */
  189. @interface OALReverseFunction : NSObject <OALFunction>
  190. {
  191. id<OALFunction, NSObject> function;
  192. }
  193. #pragma mark Properties
  194. /** The function which will have its value reversed. */
  195. @property(readwrite,retain) id<OALFunction, NSObject> function;
  196. #pragma mark Object Management
  197. /** Create a new reverse function.
  198. *
  199. * @param function The function to reverse.
  200. * @return the new reversed function.
  201. */
  202. + (id) functionWithFunction:(id<OALFunction, NSObject>) function;
  203. /** Initialize a reverse function.
  204. *
  205. * @param function The function to reverse.
  206. * @return the initialized reversed function.
  207. */
  208. - (id) initWithFunction:(id<OALFunction, NSObject>) function;
  209. @end