[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/firefox-javascript-repl 7c8f747bba 10/24: Add a JavaScr
From: |
Thomas Fitzsimmons |
Subject: |
[elpa] externals/firefox-javascript-repl 7c8f747bba 10/24: Add a JavaScript example with which to test |
Date: |
Thu, 1 Jun 2023 00:41:52 -0400 (EDT) |
branch: externals/firefox-javascript-repl
commit 7c8f747bbad02fa0554aabea1cfd8b2cc3bf6661
Author: Thomas Fitzsimmons <fitzsim@fitzsim.org>
Commit: Thomas Fitzsimmons <fitzsim@fitzsim.org>
Add a JavaScript example with which to test
* example.js: Import from developer.mozilla.org tutorial.
---
example.js | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 72 insertions(+)
diff --git a/example.js b/example.js
new file mode 100644
index 0000000000..a55b87d6fb
--- /dev/null
+++ b/example.js
@@ -0,0 +1,72 @@
+// From https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial
+// This work is licensed under the Creative Commons
+// Attribution-ShareAlike 2.5 Generic License. To view a copy of this
+// license, visit http://creativecommons.org/licenses/by-sa/2.5/ or
+// send a letter to Creative Commons, PO Box 1866, Mountain View, CA
+// 94042, USA.
+var canvas = document.createElement('canvas');
+canvas.width = 600;
+canvas.height = 300;
+canvas.style = "border: 1px solid";
+document.body.appendChild(canvas);
+const context = canvas.getContext("2d");
+let animation;
+let running = false;
+
+const ball = {
+ x: 100,
+ y: 100,
+ vx: 5,
+ vy: 1,
+ radius: 25,
+ color: "blue",
+ draw() {
+ context.beginPath();
+ context.arc(this.x, this.y, this.radius, 0, Math.PI * 2, true);
+ context.closePath();
+ context.fillStyle = this.color;
+ context.fill();
+ },
+};
+
+function clear() {
+ context.fillStyle = "rgba(255, 255, 255, 0.3)";
+ context.fillRect(0, 0, canvas.width, canvas.height);
+}
+
+function draw() {
+ clear();
+ ball.draw();
+ ball.x += ball.vx;
+ ball.y += ball.vy;
+
+ if (ball.y + ball.vy > canvas.height || ball.y + ball.vy < 0) {
+ ball.vy = -ball.vy;
+ }
+ if (ball.x + ball.vx > canvas.width || ball.x + ball.vx < 0) {
+ ball.vx = -ball.vx;
+ }
+
+ animation = window.requestAnimationFrame(draw);
+}
+
+canvas.addEventListener("mousemove", (e) => {
+ if (!running) {
+ clear();
+ ball.x = e.clientX;
+ ball.y = e.clientY;
+ ball.draw();
+ }
+});
+
+canvas.addEventListener("click", (e) => {
+ if (!running) {
+ animation = window.requestAnimationFrame(draw);
+ running = true;
+ }
+});
+
+canvas.addEventListener("mouseout", (e) => {
+ window.cancelAnimationFrame(animation);
+ running = false;
+});
- [elpa] branch externals/firefox-javascript-repl created (now 7b288e2dba), Thomas Fitzsimmons, 2023/06/01
- [elpa] externals/firefox-javascript-repl 18fa0a257b 07/24: Enable font lock, Thomas Fitzsimmons, 2023/06/01
- [elpa] externals/firefox-javascript-repl f601354463 08/24: Show JavaScript quirk on startup, Thomas Fitzsimmons, 2023/06/01
- [elpa] externals/firefox-javascript-repl 7c8f747bba 10/24: Add a JavaScript example with which to test,
Thomas Fitzsimmons <=
- [elpa] externals/firefox-javascript-repl 76fe78566b 11/24: Polish process management, debugging and naming, Thomas Fitzsimmons, 2023/06/01
- [elpa] externals/firefox-javascript-repl 075bd87281 15/24: Adjust commentary wording, Thomas Fitzsimmons, 2023/06/01
- [elpa] externals/firefox-javascript-repl 2016b0eafa 22/24: Make firefox-javascript-repl--mode private, Thomas Fitzsimmons, 2023/06/01
- [elpa] externals/firefox-javascript-repl c2a0f7f44a 04/24: Get basic REPL working, Thomas Fitzsimmons, 2023/06/01
- [elpa] externals/firefox-javascript-repl f0ed5fbf81 03/24: Get ready for asynchronous JavaScript evaluation, Thomas Fitzsimmons, 2023/06/01
- [elpa] externals/firefox-javascript-repl 77c9907e3e 18/24: Move usage to start of commentary, Thomas Fitzsimmons, 2023/06/01
- [elpa] externals/firefox-javascript-repl 1e0638d411 17/24: Mention throwaway profile in commentary, Thomas Fitzsimmons, 2023/06/01
- [elpa] externals/firefox-javascript-repl 7b288e2dba 24/24: Bump version to 0.9.0, Thomas Fitzsimmons, 2023/06/01
- [elpa] externals/firefox-javascript-repl 7bed24ae8e 23/24: Ignore errors when showing quirk, Thomas Fitzsimmons, 2023/06/01
- [elpa] externals/firefox-javascript-repl b0695f591d 02/24: Complete actor retrieval, Thomas Fitzsimmons, 2023/06/01