sccd_performance_cpu_time.xml 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. </transition>
  38. </state>
  39. </state>
  40. <state id="spawn_windows" initial="spawning">
  41. <state id="spawning">
  42. <transition target="." after="(1000 - self.getSimulatedTime() % 1000) / 1000.0" cond="self.nr_of_fields &lt; 10">
  43. <raise event="create_field" />
  44. </transition>
  45. </state>
  46. </state>
  47. </parallel>
  48. <state id="stopped" />
  49. </state>
  50. </scxml>
  51. </class>
  52. <class name="Field">
  53. <relationships>
  54. <association name="balls" class="Ball" />
  55. <association name="parent" class="MainApp" min="1" max="1" />
  56. </relationships>
  57. <scxml initial="root">
  58. <state id="root" initial="running">
  59. <parallel id="running">
  60. <state id="main_behaviour" initial="running">
  61. <state id="running">
  62. <transition event="spawn_ball" target="../creating">
  63. <parameter name="x" />
  64. <parameter name="y" />
  65. <raise scope="cd" event="create_instance">
  66. <parameter expr='"balls"' />
  67. <parameter expr='"Ball"' />
  68. <parameter expr="x" />
  69. <parameter expr="y" />
  70. </raise>
  71. </transition>
  72. </state>
  73. <state id="creating">
  74. <transition event="instance_created" target="../running">
  75. <parameter name="association_name" type="string"/>
  76. <raise scope="cd" event="start_instance">
  77. <parameter expr="association_name" />
  78. </raise>
  79. </transition>
  80. </state>
  81. </state>
  82. <state id="spawn_balls" initial="spawning">
  83. <state id="spawning">
  84. <transition target="." after="(50 - self.getSimulatedTime() % 50) / 1000.0">
  85. <raise event="spawn_ball">
  86. <parameter expr="150" />
  87. <parameter expr="150" />
  88. </raise>
  89. </transition>
  90. </state>
  91. </state>
  92. </parallel>
  93. <state id="deleting">
  94. <transition target="../deleted">
  95. <raise event="delete_field" scope="narrow" target="'parent'">
  96. <parameter expr='self.association_name' />
  97. </raise>
  98. </transition>
  99. </state>
  100. <state id="deleted" />
  101. </state>
  102. </scxml>
  103. </class>
  104. <class name="Ball">
  105. <relationships>
  106. <association name="parent" class="Field" min="1" max="1" />
  107. </relationships>
  108. <constructor>
  109. <parameter name="x" />
  110. <parameter name="y" />
  111. <body>
  112. <![CDATA[
  113. self.r = 20.0;
  114. self.vel = {'x': random.uniform(-5.0, 5.0), 'y': random.uniform(-5.0, 5.0)};
  115. self.mouse_pos = {};
  116. self.smooth = 0.4; # value between 0 and 1
  117. self.pos = {'x': x, 'y': y}
  118. ]]>
  119. </body>
  120. </constructor>
  121. <scxml initial="main_behaviour">
  122. <state id="main_behaviour" initial="bouncing">
  123. <state id="bouncing">
  124. <transition after="(20 - self.getSimulatedTime() % 20) / 1000.0" target=".">
  125. <script>
  126. <![CDATA[
  127. self.pos
  128. if self.pos['x'] - self.r <= 0 or self.pos['x'] + self.r >= 800 :
  129. self.vel['x'] = -self.vel['x'];
  130. if self.pos['y'] - self.r <= 0 or self.pos['y'] + self.r >= 600 :
  131. self.vel['y'] = -self.vel['y'];
  132. self.pos['x'] += self.vel['x']
  133. self.pos['y'] += self.vel['y']
  134. ]]>
  135. </script>
  136. </transition>
  137. </state>
  138. </state>
  139. </scxml>
  140. </class>
  141. </diagram>