![]() ![]() I won’t go into too much detail about it here, but I highly recommend the MDN docs and the tutorials there for playing around with it.įor both of these games, I want to be able to play a single tone for a certain amount of time. The main interface for sound in the browser is the Web Audio API. You can do so many things with JavaScript, and luckily, this is one of them. The first thing that comes to mind for these games is the ability to play sound. These games are written in vanilla JavaScript, and the source code is available here and here. The games include some options, including the speed that the Morse code plays (ranging from slow to fast for both the Farnsworth method and extending all times) and the difficulty (with the target ranging from a single letter to a number of words). ![]() The second game is a “speaking” game, where it gives you a random target string and you have to enter it in Morse code. The first game is a listening game, where it plays the Morse code representation of a random target and you have to enter it in. I wanted to take some time to describe how I made them and some of the challenges that came up along the way. Last week, I posted a pair of games I made to play with Morse code in your browser. Parsing the incoming signal into Morse code.We also need to check that value at particular index of the sequence matches the given value. It would check for arguments and if they all match arguments from the previous call it would just return the previous result, without calling the method. All we need to do is add decorator on top of the getter. After the value is requested for the first time we replace getter with a plain property containing the result. This is a memoization pattern for delayed computation. We use it a lot in our library for lazy getters. For this purposes we can use decorator from Taiga UI. There's one thing that we do not need and that is - recreating the Array everytime we request it. But then we will not be able to create them in *ngFor. If it was a static string value and not an input we could have changed Directive to instead of and get its value in constructor. Copy private get sequence ( ) : readonly ( 0 | 1 ) We will use it to send letter with mouse and virtual on-screen keyboard: This way we can type really fast and we'll never lose a letter in transition.įor the sake of a demo let's also make a simple service to send those sequences. ![]() Whenever a new value comes (a user presses a key) - it waits for the previous Observable to complete (a sequence is played out) before proceeding to create the next sequence Observable. It is a member of the Higher Order Observables family of operators and we use it to map every value to an Observable. Because we want to preserve the order of emissions and never lose a character from previous emission, we will use concatMap operator. It means that letters are translated into sequences that have duration. Let's make unit duration an InjectionToken as well so it can be customized! But since we emulate an analog device which is based on duration of signals - we will designate a certain length to every unit. Each letter would turn into an array of 0s and 1s instantly. We can encode every letter synchronously. And projects can swap it for their Morse code table: With second parameter having factory function we can provide this implementation as default value. ![]() If we were to implement this code table in Angular, this would be a good candidate for an InjectionToken. This is a standard US Morse code table, but there are other versions. Dot is a single 1, which also should be separated with 0, so we'll have 4 of 1s and 3 zeros in between: 1010101. You can also see the signal grid, black square means 1, white square is 0.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |