Javascript Magic 8 Ball

0 views
Skip to first unread message

Fritzi Vanderweel

unread,
Aug 5, 2024, 4:10:58 AM8/5/24
to tanmegorta
Tostart developing for the web, all you really need is a text editor program. I like Sublime, but there are many good ones to choose from. You can even use plain old Notepad, but I recommend downloading something better. Here is a good list to pick from:

The first element you see is the doctype. This is not an HTML tag, but information the browser needs to know what kind of document to display. In our case, the type of document is an HTML document. There are other doctypes, but that discussion is beyond the scope of this tutorial.


We have three tags so far: html, head, and body. The html tag signifies the beginning of the HTML document. Everything on the page goes inside it. The head tag contains meta information about the page and can also be used as a place to import other files. The body tag is where the bulk of our content will go.


We have added a main tag inside the body. This element contains the main content of the page. In our case, this is almost everything. On other websites, however, you might find items like common footers and navigation elements outside of the main tag.


At this point you should save your changes. Then, navigate to this file and open it in a browser. In the address bar you should be able to see the path to your file. On the page itself you should see the title and the links below it.


After refreshing the page you should see everything centered on the page much more nicely. We have set the max width of the main element to 610px (px stands for pixels), and we have set the margin to auto, horizontally centering all of the content within it.


We are setting the font size to 14pt. This seemed reasonable after I did a little bit of testing. We are also setting the background to white and the text color to black so that the answer area will have good contrast and look good on top of the magic eight ball image.


The first thing we do is get a random index. This random index will correspond to one of the elements in our answers array. Each element in the array is assigned an index, starting with 0. So the array above looks like this:


I hope you learned something from this tutorial, especially if you are brand new to programming. We have barely begun scratching the surface on what we can accomplish with these programming languages. The whole web is built using these technologies, and there are many more elements we can create, styles we can apply, functions we can write. There is boundless room for creativity.


We are ready to create our magic 8-ball method now. In this challenge, we are going back to the magic 8-ball object we created and adding to it the method you will use to make it work just like a magic 8-ball. You will write pseudocode for your method just like the one we just wrote for the chair method we did in the last challenge. By the end of this challenge, you will have a method and a call to get your method to run.


This lets the computer know the user needs to give it a question to start working. Once the user has given a question, it is time for the magic 8 ball to start working. The second step will be where the magic 8 ball shakes.


It needs a list of answers to reference and pick from to decide what to display. After the second step, I will put a line that says the 8-ball picks an answer from the list of answers. We are in the home stretch with this method.


These magic crystals balls are SO easy to make, here are the materials needed to make the crystal ball and watch the video for a quick tutorial. I made these for our Halloween party for table decor but they can be used anytime for a party- Harry Potter party anyone?? Makes cute little party favors as well- any creative use you can think of, the girls want it as a night light, so I may upgrade the light source.


The lights I used are called balloon lights and are meant for parties, not to last forever. The time varies on how long they last 12, 24 hours and some had a dim light a couple days later. I used approximately 4 balloon lights for each crystal ball. If you want something that lasts longer for your crystal ball, an alternative may be a reusable tea light or led light. However, if you get the smaller snow globe available at dollar store, just be sure the light you use can fit when you open the snow globe.


Currently you have JavaScript disabled. In order to post comments, please make sure JavaScript and Cookies are enabled, and reload the page. Click here for instructions on how to enable JavaScript in your browser.


While working on improving my map editor for DuckBlur, I decided to port and finish an old game of mine. It's a Puyo Puyo-style puzzle game with somewhat poker rules. Falling blocks are cards, and you need to match 3 or more of a kind, create a straight, or achieve a flush to make them disappear.


I made some profiling and the main slowdowns were caused by the high number of sprites (up to 87 per side + 6 layers for the background + 6 for the magic ball) and by the earthquake effect when chips are sent by the opponent.


I found a way to optimize those two points at the same time: when a card is placed in the board, I now remove the sprite and draw its image on the board itself. That makes the number of updated sprites way lower.


Before each battle, the characters talks in short dialogue scenes. As these scenes will represent a significant part of the game, I wanted to include support for multiple languages in the game system. I expected encoding issues (and wasn't disappointed!), so I wanted to incorporate this early in the development.


However, I started encountering some display issues with accents in French. I noticed that the len argument of the method playdate->graphics->drawText(const void* text, size_t len, PDStringEncoding encoding, int x, int y) is in fact not the number of bytes to display but the number of characters. So when I passed strlen(line) (i.e. the buffer length), it displayed a few extra characters.


Second problem: Japanese doesn't have spaces!

In English and French, the text reflow was handled by looking for the next space or the end of the sentence. If the displayed text size + the next word exceeded the width of the screen, the word would move to the next line. But in Japanese, it displayed nothing because the sentence didn't fit in width. So now, I display letter by letter when the language is Japanese.


The len argument also took its revenge! Naturally, the one in playdate->graphics->getTextWidth(LCDFont* font, const void* text, size_t len, PDStringEncoding encoding, int tracking) is also in the number of characters and not in the number of bytes, but I had forgotten to modify the code here as well >_


Fortunately, I was still able to make progress. I tried GarageBand on iOS during my commute, and I was pleasantly surprised. It is full-featured and very capable. For Kuroobi, I used a MIDI keyboard (Roland FP-10) alongside the macOS version of GarageBand to create the music, but the virtual piano on the iPhone screen was good enough to work.


so I shared a screenshot of my script the yellow highlight is the one where the magical ball is spinning perfectly but the other 3 highlighted in red will not spin how do I get them all to spin till the magical ball is no longer in the scene?


It is so cool, right? Did you have fun and show this magic fire to your friends? I hope you like it, this demo utilized an advanced technique called Hand Tracking, which can identify human hands in an image or video stream.


Thanks to handtrack.js, an awesome javascript library that uses the TensorFlow.js object detection API to empower hand tracking in the browser. If you are interested in building your own hand tracking app, please follow me below for the journey of how I implemented it.


In order to perform hand tracking, we first need to load the pre-trained HandTrack model, by calling the API of handTrack.load(modelParams). HandTrack comes with a few optional parameters of the model:


Next, we start to feed the webcam stream through the HandTrack model to perform hand detection, by calling the API of model.detect(video). It takes an input image element (can be an img, video, canvas tag) and returns an array of bounding boxes with class name and confidence level.


Thank you for reading. If you like this article, please share on Facebook or Twitter. Let me know in the comment if you have any questions. Follow me on Medium, GitHub and Linkedin. Support me on Ko-fi.


Starter Devin Lancaster tossed two scoreless frames to open the contest, keeping the Morehead State offense off balance while allowing just one hit. The Eagles broke through in the third, scoring three times, including one unearned run.


Ethan Roberts took over on the hill, turning in an incredible performance out of the bullpen to give the Golden Eagle offense a chance to solve the Morehead State starter, Garret Rogers. Roberts finished off the final two outs of the third before embarking on a masterful showing over the next four frames.


The Sparta native worked out of a few jams, scattering five hits and three walks in his four and two thirds innings of work while striking out two. After the first two batters of the fifth reached, the junior forced three lazy fly balls to escape the trouble.


Tech broke through offensively in the fifth, beginning with a one-out walk to senior Collin Harris. Alex Junior followed by ripping a single up the middle to put two on for senior Trevor Putzig. The third baseman fouled off two pitches and watched one miss the zone to make it a 1-2 count.


Putzig absolutely crushed a game-tying, three-run home run down the left field line and into the wind, just staying inside the foul pole. The senior's 16th long ball of the year represented the team's 128th on the year, breaking the OVC's single-season mark set in 2002 by Morehead State.


Roberts took back over on the hill and struck out the first batter he saw in the sixth. After a bang-bang play at first on a bunt ended in a hit, Morehead made it two on with one out with another base hit. The Tech closer never wavered, inducing a double play ball to third base which Putzig and Ham turned beautifully with Chase Chambers at first to end the frame.

3a8082e126
Reply all
Reply to author
Forward
0 new messages