Guest User

Untitled

a guest
Oct 19th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. using System;
  2. using JSIL;
  3. using JSIL.Meta;
  4.  
  5. public static class Program {
  6. public static int x = 10;
  7. public static int y = 20;
  8.  
  9. public static void Main () {
  10. dynamic document = Builtins.Global["document"];
  11. dynamic window = Builtins.Global["window"];
  12.  
  13. var canvas = document.createElement("canvas");
  14. var ctx = canvas.getContext("2d");
  15. var body = document.getElementsByTagName("body")[0];
  16.  
  17. // -----------------------------------------------
  18. //
  19. // Dynamically add a Button to a page
  20. //
  21. // -----------------------------------------------
  22. var element = document.createElement("input");
  23. element.setAttribute("type", "button");
  24. element.setAttribute("value", "button");
  25. element.setAttribute("name", "button");
  26. //
  27. //To add at a specific spot (like a span) do:
  28. //
  29. //var spanPOS = document.getElementById("spanID");
  30. //spanPOS.appendChild(element);
  31. body.appendChild(element);
  32.  
  33. // --- End of Button Example
  34.  
  35. Console.WriteLine("Hello JSIL World!");
  36.  
  37. body.appendChild(canvas);
  38.  
  39. window.setInterval((Action)(() => {
  40. Redraw(ctx);
  41. }), 25);
  42. }
  43.  
  44. public static void Redraw (dynamic ctx) {
  45. x += 2;
  46.  
  47. ctx.clearRect(0, 0, 300, 300);
  48.  
  49. ctx.fillStyle = "red";
  50. ctx.fillRect(x, y, 20, 20);
  51. }
  52. }
Add Comment
Please, Sign In to add comment