User Tools

Site Tools


javascript_terminal

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
javascript_terminal [2023/11/20 12:17] appledogjavascript_terminal [2023/11/24 01:34] (current) appledog
Line 1: Line 1:
 = JavaScript Terminal = JavaScript Terminal
 +* Also see: [[JavaScript Terminal v2|Version 2]] which is a more advanced version of this codebase.
 +
 This section will outline the basic JavaScript terminal code. This code was not used much when I taught JavaScript to Roger and Neo, but it serves the same basic purpose as the [[PyGame Terminal]]. This section will outline the basic JavaScript terminal code. This code was not used much when I taught JavaScript to Roger and Neo, but it serves the same basic purpose as the [[PyGame Terminal]].
  
-The level of this code will be towards the end of JavaScript Season 1, or at the beginning of JavaScript Season 2. I thinkthat we will use console for Season 1, and start with this in Season 2 -- maybeIt's advanced because it has several classes and data structures, so it feels more like Season 2 itemAnyways,+The level of this code is the beginning of Season 2, for many reasonsIf we took out the resize codeit might be late season materialbut with the resize code in I would say it is good for Season 2. Maybe a stripped down version could be produced later; but the idea here is that it will display on cellphone or a tablet as well as on a desktop.
  
-You can view a technical demo of this directly at: [[https://helloneo.ca/jnw/archive/jttd1/index.html|JavaScript Terminal Technical Demo 1]].+You can view a technical demo of this program at: [[https://helloneo.ca/jnw/archive/jttd1/index.html|JavaScript Terminal Technical Demo 1]].
  
 == The Font == The Font
Line 15: Line 17:
 <html> <html>
 <head> <head>
 +    <meta name="viewport" content="width=device-width, initial-scale=1">
     <title>Basic Javascript Terminal</title>     <title>Basic Javascript Terminal</title>
  
Line 42: Line 45:
 </Code> </Code>
  
-There is not much to see here. In the original we used normalizer, modernizer and a few other things, but I have stripped those off to show the basic idea.+There is not much to see here. The most interesting line is probably the meta tag. We must set initial_scale to 1 or the text will look too small on higher resolution screens.
  
-There are four main parts: Color.js, which is a color map, Character.js which discusses what needs to be known to represent a character, Terminal, which holds the information about characters on the screen and how to draw them, and main.js which sets up everything and starts the game loop.+Otherwise our main goal is to load and run the JavaScript files. There are four main parts: Color.js, which is a color map, Character.js which discusses what needs to be known to represent a character, Terminal, which holds the information about characters on the screen and how to draw them, and main.js which sets up everything and starts the game loop.
  
 Actually, you could probably refactor some things in main into a class (such as a Game.js class) and then just instantiate and run the class, like we do in Python for PyGame. Perhaps this will be done in a part two sequel article to this one. For now, it's left as an exercise to the reader. Actually, you could probably refactor some things in main into a class (such as a Game.js class) and then just instantiate and run the class, like we do in Python for PyGame. Perhaps this will be done in a part two sequel article to this one. For now, it's left as an exercise to the reader.
Line 119: Line 122:
     }     }
 } }
- 
 </Code> </Code>
  
Line 249: Line 251:
 // load font // load font
 const font = new FontFace('myvga', 'url(PxPlus_IBM_VGA_8x16.ttf)'); const font = new FontFace('myvga', 'url(PxPlus_IBM_VGA_8x16.ttf)');
- 
  
 font.load().then(() => { font.load().then(() => {
Line 277: Line 278:
     terminal.copyContentTo(t);     terminal.copyContentTo(t);
     terminal = t;     terminal = t;
 +
 +    ctx.font = '32px myvga'; // This seems to be needed here.
 } }
  
Line 294: Line 297:
         background = Color.black         background = Color.black
         terminal.setch(x, y, ch, color, background)         terminal.setch(x, y, ch, color, background)
-        console.log("[" + ch + "], " + x + "," + y + " " + color);+        //console.log("[" + ch + "], " + x + "," + y + " " + color);
     }     }
 } }
Line 336: Line 339:
 == Analysis == Analysis
 Most of this should already be familiar since all of it would have been covered in JavaScript Season 1. Most of this should already be familiar since all of it would have been covered in JavaScript Season 1.
 +
 +However, one interesting quirk which arose is that the ctx.font has to be set upon terminal resize. I am not sure where the best place is to set it, but it seems to work great setting it on a resize. It would also work if you set it every time you drew a character, but if we assume that we are only using one font and are essentially the main application (a one-canvas app) then setting it on every character draw is probably unnecessary.
 +
 +== Also See
 +* Also see: [[JavaScript Terminal v2|Version 2]] which is a more advanced version of this codebase.
 +
 +
  
javascript_terminal.1700482629.txt.gz · Last modified: 2023/11/20 12:17 by appledog

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki