sccd_performance_threads.xml 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?xml version="1.1" ?>
  2. <diagram author="Simon Van Mierlo+Raphael Mannadiar" name="Bouncing_Balls_Python_Version">
  3. <description>
  4. Tkinter frame with bouncing balls in it.
  5. </description>
  6. <top>
  7. import random, sys
  8. </top>
  9. <class name="MainApp" default="true">
  10. <relationships>
  11. <association name="fields" class="Field" />
  12. </relationships>
  13. <constructor>
  14. <body>
  15. <![CDATA[
  16. self.nr_of_fields = 0
  17. ]]>
  18. </body>
  19. </constructor>
  20. <scxml initial="running">
  21. <state id="running" initial="root">
  22. <parallel id="root">
  23. <state id="cd_behaviour" initial="waiting">
  24. <state id="waiting">
  25. <transition event="create_field" target="../creating">
  26. <raise scope="cd" event="create_instance">
  27. <parameter expr='"fields"' />
  28. </raise>
  29. </transition>
  30. </state>
  31. <state id="creating">
  32. <transition event="instance_created" target="../waiting">
  33. <parameter name="association_name" type="string"/>
  34. <raise scope="cd" event="start_instance">
  35. <parameter expr="association_name" />
  36. </raise>
  37. <script>
  38. self.nr_of_fields += 1
  39. </script>
  40. </transition>
  41. </state>
  42. </state>
  43. <state id="spawn_windows" initial="spawning">
  44. <state id="spawning">
  45. <transition target="." after="(1000 - self.getSimulatedTime() % 1000) / 1000.0" cond="self.nr_of_fields &lt; 10">
  46. <raise event="create_field" />
  47. </transition>
  48. </state>
  49. </state>
  50. </parallel>
  51. <state id="stopped" />
  52. </state>
  53. </scxml>
  54. </class>
  55. <class name="Field">
  56. <relationships>
  57. <association name="balls" class="Ball" />
  58. <association name="parent" class="MainApp" min="1" max="1" />
  59. </relationships>
  60. <scxml initial="root">
  61. <state id="root" initial="running">
  62. <parallel id="running">
  63. <state id="main_behaviour" initial="running">
  64. <state id="running">
  65. <transition event="spawn_ball" target="../creating">
  66. <parameter name="x" />
  67. <parameter name="y" />
  68. <raise scope="cd" event="create_instance">
  69. <parameter expr='"balls"' />
  70. <parameter expr='"Ball"' />
  71. <parameter expr="x" />
  72. <parameter expr="y" />
  73. </raise>
  74. </transition>
  75. </state>
  76. <state id="creating">
  77. <transition event="instance_created" target="../running">
  78. <parameter name="association_name" type="string"/>
  79. <raise scope="cd" event="start_instance">
  80. <parameter expr="association_name" />
  81. </raise>
  82. </transition>
  83. </state>
  84. </state>
  85. <state id="spawn_balls" initial="spawning">
  86. <state id="spawning">
  87. <transition target="." after="(50 - self.getSimulatedTime() % 50) / 1000.0">
  88. <raise event="spawn_ball">
  89. <parameter expr="150" />
  90. <parameter expr="150" />
  91. </raise>
  92. </transition>
  93. </state>
  94. </state>
  95. </parallel>
  96. <state id="deleting">
  97. <transition target="../deleted">
  98. <raise event="delete_field" scope="narrow" target="'parent'">
  99. <parameter expr='self.association_name' />
  100. </raise>
  101. </transition>
  102. </state>
  103. <state id="deleted" />
  104. </state>
  105. </scxml>
  106. </class>
  107. <class name="Ball">
  108. <relationships>
  109. <association name="parent" class="Field" min="1" max="1" />
  110. </relationships>
  111. <constructor>
  112. <parameter name="x" />
  113. <parameter name="y" />
  114. <body>
  115. <![CDATA[
  116. self.r = 20.0;
  117. self.vel = {'x': random.uniform(-5.0, 5.0), 'y': random.uniform(-5.0, 5.0)};
  118. self.mouse_pos = {};
  119. self.smooth = 0.4; # value between 0 and 1
  120. self.pos = {'x': x, 'y': y}
  121. ]]>
  122. </body>
  123. </constructor>
  124. <scxml initial="main_behaviour">
  125. <state id="main_behaviour" initial="bouncing">
  126. <state id="bouncing">
  127. <transition after="(20 - self.getSimulatedTime() % 20) / 1000.0" target=".">
  128. <script>
  129. <![CDATA[
  130. self.pos
  131. if self.pos['x'] - self.r <= 0 or self.pos['x'] + self.r >= 800 :
  132. self.vel['x'] = -self.vel['x'];
  133. if self.pos['y'] - self.r <= 0 or self.pos['y'] + self.r >= 600 :
  134. self.vel['y'] = -self.vel['y'];
  135. self.pos['x'] += self.vel['x']
  136. self.pos['y'] += self.vel['y']
  137. ]]>
  138. </script>
  139. </transition>
  140. </state>
  141. </state>
  142. </scxml>
  143. </class>
  144. </diagram>