/API/yeux_robot.as

https://bitbucket.org/gobgob/yeux
ActionScript | 203 lines | 174 code | 23 blank | 6 comment | 16 complexity | dffef40bf4b00769b6675069d219d83b MD5 | raw file
  1. package
  2. {
  3. import flash.desktop.Clipboard;
  4. import flash.display.MovieClip;
  5. import flash.display.Shape;
  6. import flash.display.Sprite;
  7. import flash.events.KeyboardEvent;
  8. import flash.events.MouseEvent;
  9. import flash.system.System;
  10. public class yeux_robot extends Sprite
  11. {
  12. public static var color:int = 0; // Color for painting
  13. public static var colorPicker:ColorPicker = new ColorPicker();
  14. public var aide:Aide = new Aide();
  15. public var layer:int = 1; // Number of the layer for export
  16. public function yeux_robot()
  17. {
  18. //Left eye
  19. for(var col:int=0; col<16 ; col++)
  20. {
  21. for(var row:int=0; row<8; row++)
  22. {
  23. var diode000:Diode = new Diode();
  24. diode000.name = "diode_"+row+"_"+col;
  25. diode000.x = 45*col +300;
  26. diode000.y = 45*row +200;
  27. addChild(diode000);
  28. }
  29. }
  30. // Color picker
  31. colorPicker.x = 30;
  32. colorPicker.y = 30;
  33. addChild(colorPicker);
  34. // Event Listener
  35. stage.addEventListener(KeyboardEvent.KEY_DOWN, export);
  36. // Help menu (F1)
  37. aide.x = stage.width/2;
  38. aide.y = stage.height/2;
  39. }
  40. public function export (e:KeyboardEvent)
  41. {
  42. trace (e.keyCode);
  43. var print:String = new String();
  44. switch(e.keyCode)
  45. {
  46. case 32 : //Touche espace -> print result
  47. print = "";
  48. for (var color:int= 0; color<3; color++)
  49. {
  50. for(var row:int=0; row<8; row++)
  51. {
  52. print += "g_layer["+layer+"]["+row+"]["+color+"] = (unsigned short)( B";
  53. for(var col:int=0; col<16 ; col++)
  54. {
  55. if (col == 8)
  56. {
  57. print += "<< DECAL1 ) | (unsigned short)( B";
  58. }
  59. // print += Diode(getChildByName("diode_"+row+"_"+col)).value;
  60. switch (color)
  61. {
  62. case 0: // RED
  63. switch (Diode(getChildByName("diode_"+row+"_"+col)).value)
  64. {
  65. case 4:
  66. case 5:
  67. case 6:
  68. case 7:
  69. print += "1";
  70. break;
  71. default:
  72. print += "0";
  73. break;
  74. }
  75. break;
  76. case 1: // BLUE
  77. switch (Diode(getChildByName("diode_"+row+"_"+col)).value)
  78. {
  79. case 1:
  80. case 3:
  81. case 5:
  82. case 7:
  83. print += "1";
  84. break;
  85. default:
  86. print += "0";
  87. break;
  88. }
  89. break;
  90. case 2: // GREEN
  91. switch (Diode(getChildByName("diode_"+row+"_"+col)).value)
  92. {
  93. case 2:
  94. case 3:
  95. case 6:
  96. case 7:
  97. print += "1";
  98. break;
  99. default:
  100. print += "0";
  101. break;
  102. }
  103. break;
  104. }
  105. }
  106. print += " << DECAL2 );\n";
  107. }
  108. }
  109. //trace(diode(getChildByName("diode_3_1")).value);
  110. trace(print);
  111. System.setClipboard(print);
  112. break;
  113. case 46 : // Touche suppr -> Clear display
  114. for(col=0; col<16 ; col++)
  115. {
  116. for(row=0; row<8; row++)
  117. {
  118. Diode(getChildByName("diode_"+row+"_"+col)).clear();
  119. }
  120. }
  121. break;
  122. case 112 : // F1 -> Aide
  123. case 27 : // Echap
  124. if (stage.contains(aide))
  125. removeChild(aide);
  126. else
  127. addChild(aide);
  128. break;
  129. case 38 : // Up
  130. if (yeux_robot.color > 0){
  131. yeux_robot.color--;
  132. yeux_robot.colorPicker.refreshColor();
  133. }
  134. break;
  135. case 40 : // Down
  136. if (yeux_robot.color < 7){
  137. yeux_robot.color++;
  138. yeux_robot.colorPicker.refreshColor();
  139. }
  140. break;
  141. case 49 : // 1 -> black
  142. yeux_robot.color = 0;
  143. yeux_robot.colorPicker.refreshColor();
  144. layer = 1;
  145. break;
  146. case 50 : // 2 -> blue
  147. yeux_robot.color = 1;
  148. yeux_robot.colorPicker.refreshColor();
  149. layer = 2;
  150. break;
  151. case 51 : // 3 -> green
  152. yeux_robot.color = 2;
  153. yeux_robot.colorPicker.refreshColor();
  154. layer = 3;
  155. break;
  156. case 52 : // 4 -> cyan
  157. yeux_robot.color = 3;
  158. yeux_robot.colorPicker.refreshColor();
  159. layer = 4;
  160. break;
  161. case 53 : // 5 -> red
  162. yeux_robot.color = 4;
  163. yeux_robot.colorPicker.refreshColor();
  164. break;
  165. case 54 : // 6 -> pink
  166. yeux_robot.color = 5;
  167. yeux_robot.colorPicker.refreshColor();
  168. break;
  169. case 55 : // 7 -> yellow
  170. yeux_robot.color = 6;
  171. yeux_robot.colorPicker.refreshColor();
  172. break;
  173. case 56 : // 8 -> white
  174. yeux_robot.color = 7;
  175. yeux_robot.colorPicker.refreshColor();
  176. break;
  177. }
  178. }
  179. }
  180. }