Advertisement
zephyrtronium

plugin low-level format

Apr 4th, 2011
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.82 KB | None | 0 0
  1.  
  2. stack is exactly 8 doubles in length
  3. the ith element refers to the value i places beneath the top of the stack
  4.  
  5. an array should be allocated for variables used during calculation
  6. the vth var refers to the var of index v
  7. alternatively, the vth var may be FTx, FPx, TC, etc. to use those values
  8.  
  9. operation summary:
  10. (these manipulate the stack or the values on it)
  11. dup [i] - duplicate the top or ith element
  12. push x[, ...] - push immediate values onto the stack
  13. drop n - discard n values off the top of the stack
  14. set x, i - set the ith element of the stack to x
  15. load v[, i] - push the vth var or set the ith element to the vth var
  16. loadxy - push FTy then FTx
  17. loadxyz - push FTz then FTy then FTx
  18. pop v - pop the top value to the vth var
  19. store v, i - copy the ith element to the vth var
  20. swap [i, j] - swap the first element with the second or the ith with the jth
  21.  
  22. (these binary operators pop the top two values; each has a two-argument i, j
  23. version which operates on the ith and jth elements without popping them, and
  24. versions named *xy, *xz, and *yz (e.g. addxy, addxz, addyz) which use
  25. FTx and FTy, FTx and FTz, and FTy and FTz, respectively, as their arguments)
  26. add - add the top two values and push the result
  27. sub - push the result of subtraction of the second element from the first
  28. rsub - push the result of subtraction of the first element from the second
  29. mul - multiply the top two values and push the result
  30. div - push the result of division of the first element by the second
  31. rdiv - push the result of division of the second element by the first
  32. mod - push the remainder of division of the first element by the second
  33. rmod - push the remainder of division of the second element by the first
  34. polar - push atan2(y, x) and hypot(y, x) where y is the second element and
  35. x is the first. the radius is the new first element.
  36. rect - push x * sin(y) and x * cos(y) where y is the second element and x is
  37. the first. the horizontal component is the new first element.
  38. note: polar and rect with nothing between them effectively become a nop
  39. pow - push the result of exponentiation of the second element by the first
  40. rpow - push the result of exponentiation of the first element by the second
  41. atan2 - atan2(y, x), where x is the first element and y the second
  42. note: the xy, xz, and yz versions of this are reversed; atan2xy is
  43. equivalent to atan2(FTy, FTx)
  44.  
  45. (these are similar to the binary operators above but with three arguments;
  46. i, j, k versions use the ith, jth, and kth elements, and *xyz versions use
  47. FTx, FTy, and FTz)
  48. spherical - push acos(z / sqrt(x*x + y*y + z*z)), atan2(y, x), and
  49. sqrt(x*x + y*y + z*z), where z is the third element, y is the second,
  50. and x is the first. the new first element is the radius and the second
  51. the angle from the arctangent.
  52. rect3d - push x * cos(z), x * sin(y) * sin(z), and x * cos(y) * sin(z). the
  53. new first element is the component along the x axis and the second the
  54. component along the y axis.
  55. fma - push x * y + z
  56.  
  57. (these unaries follow conventions similar to those of the binaries and
  58. ternaries, with i, *x, *y, *z versions)
  59. neg - change sign
  60. acos - arccosine
  61. asin - arcsine
  62. atan - arctangent
  63. cos - cosine
  64. cosh - hyperbolic cosine
  65. sin - sine
  66. sinh - hyperbolic sine
  67. tan - tangent
  68. tanh - hyperbolic tangent
  69. exp - exponential (e to the power of the first element)
  70. ln - natural logarithm
  71. sqrt - square root
  72. ceil - ceiling
  73. abs - absolute value
  74. floor - floor
  75.  
  76. (these unaries use common variables)
  77. mulv - multiply (in place) the top of the stack by VVAR
  78. addto* - pop stack and add to FP* (e.g. addtox -> FPx += top)
  79. subfrom* - pop stack and subtract from FP* (e.g. subfromx -> FPx -= top)
  80. vaddto* - same as mulv followed by addto*
  81. vsubfrom* - same as mulv followed by subfrom*
  82.  
  83. (control flow; branches pop the top two elements by default, but have *k
  84. versions (e.g. beqk) which do not pop. their arguments are a signed int8_t.)
  85. beq n - branch forward n bytes if the top two elements are equal
  86. bne n - branch forward n bytes if the top two elements are not equal
  87. bgt n - greater than
  88. ble n - not greater than
  89. bge n - greater than or equal
  90. blt n - neither greater than nor equal
  91. end - exit the function (in xi rho, the point is plotted)
  92. quit - exit the function (in xi rho, the point is not plotted)
  93.  
  94. (randomness)
  95. randint [a, b] - random integer in [0, DBL_MAX] or [a, b] (a and b are
  96. element numbers)
  97. random [a, b] - random real in [0, 1) or [a, b)
  98.  
  99. plugins can be text files so that implementations can interpret them as they
  100. will. dot directives. madness.
  101.  
  102. .name spherivoid // variation name is spherivoid
  103. .3d // 3d variation
  104. .vars real spherivoid_radius = 0 // like VAR_REAL(spherivoid_radius, 0.0)
  105. sphericalxyz // convert (FTx, FTy, FTz) to spherical coordinates
  106. load spherivoid_radius
  107. add // add spherivoid_radius to the radius coordinate
  108. rect3d // convert back to rectangular coordinates
  109. vaddtox
  110. vaddtoy
  111. vaddtoz
  112. end
  113.  
  114. .name julian
  115. .vars int julian_power = 2, real julian_dist = 1
  116. .privs int absn, real cn
  117. .prep // prepare method
  118. load julian_power
  119. dup
  120. abs
  121. store absn, 0
  122. load julian_dist, 0
  123. div
  124. push 0.5
  125. mul
  126. store cn, 0 // end following this line is implicit
  127. .calc // calculate method
  128. atan2xy // atan2(y, x)
  129. load absn
  130. push 0
  131. randint 0, 1 // random integer between 0 and absn
  132. swap 2, 0; drop 2 // remove absn and 0 from the stack
  133. push 6.283185308 // 2pi
  134. fma // 2pi * randint + theta
  135. load julian_power
  136. rdiv // (2pi * randint + theta) / power
  137. load ftx
  138. dup
  139. mul // sqr(ftx)
  140. load fty
  141. dup
  142. fma // sqr(ftx) + sqr(fty)
  143. load cn
  144. pow // pow(sqr(ftx) + sqr(fty), cn)
  145. load vvar
  146. mul // vvar * pow(sqr(ftx) + sqr(fty), cn)
  147. rect // convert to rectangular coordinates
  148. addtox
  149. addtoy
  150. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement