From 6e2e69f404d40d6c815d80a629d3b387a755051b Mon Sep 17 00:00:00 2001 From: BhargavM1 <58884443+BhargavM1@users.noreply.github.com> Date: Sun, 14 Nov 2021 14:41:37 -0500 Subject: [PATCH 1/7] Started while-loop demo --- while-loop-demo/README.md | 125 ++++++++++++++++++ while-loop-demo/index.html | 114 +++++++++++++++++ while-loop-demo/script.js | 28 +++++ while-loop-demo/style.css | 252 +++++++++++++++++++++++++++++++++++++ while-loop-demo/style.scss | 72 +++++++++++ 5 files changed, 591 insertions(+) create mode 100644 while-loop-demo/README.md create mode 100644 while-loop-demo/index.html create mode 100644 while-loop-demo/script.js create mode 100644 while-loop-demo/style.css create mode 100644 while-loop-demo/style.scss diff --git a/while-loop-demo/README.md b/while-loop-demo/README.md new file mode 100644 index 0000000..ae5f377 --- /dev/null +++ b/while-loop-demo/README.md @@ -0,0 +1,125 @@ +# interactive-tutorials Template Files + +This folder is made to show what the start of an interactive tutorial might look like. +Remember, however, that a lot of creating a tutorial is creative freedom. +Thus, don't take these as hard fast rules but rather guidelines. +We want to show a uniform look in all the tutorials and so that's why this template exists. +With this said, this document will walk you through how to create your own interactive tutorial. + +### Jumping In + +First, we need to get the back-bone of the tutorial page. +There is an `index.html` file inside the `template` directory, this is an example of a minimal demo. +In fact, this demo isn't even functional. +With no editor, input, or real result, you'll have to add all those yourself. +To do this we need a `script.js` and some understanding of how each of the common assets work. + +Let's start! +Copy the `template` folder to a new folder in the same root `interactive-demos` directory. +For our purposes, we'll call this the `test-demo`. +Then open the `index.html` file. +Inside you'll find HTML comments with the prefix `TODO:`, these point to places that need replaced. +For example, the header below the `` comment should be replaced with the name of your demo. +Inside the `"content"` div there is already a few sections. +Open the page up to see what this layout produces and read the contents of each section. + +### The First Common + +There's already styling on the page, but how exactly does it work? +There's a `style.css` file, but this isn't our css file. +Another file, `style.scss`, is what we use to modify the styling on the page. +If you don't already know SASS, quickly read up on it [here][0]. +Then, install it using the instructions [here][1]. +(The best method is just using `npm install -g sass`.) + +Notice the top of the `style.scss` file, `@import "../assets/common.scss";`. +This takes the common SASS file and using its styling and then overwrites them with whatever your styles are. +The `..` is there because the assets directory is one level up from where the demos are. +If you use any other assets such as CodeJar, line numbers, or the options files, don't forget this `..` before the path. + +### Proper Local Development + +So far, we've been viewing the file as the `index.html` file, and sometimes this is fine. +However, for the best results, we should use a local webserver. +To do this we will use `serve` on npm. +Install it using `npm install -g serve`. +Then run it using `serve` inside the `interactive-demos` directory. +It's recommended to do this in a new terminal window. +It should then start hosting a static webserver at `localhost:5000`. +When making changes to any files be sure to also reload your web view. +To stop it, press `Ctrl + C`. + +### Code Editor + +The code editor that the demos use is called CodeJar. +First, we must add the assets to the html file. +Add these three script tags to the bottom of the body in the `index.html` file. + +```html + + + +``` + +The first asset, CodeJar, is the actual code editor. +We'll add the editor in a moment. +Next, `linenumbers.js` is an extension to the CodeJar library. +Finally, Prism is a code highlighting library. +We also need to add a CSS file to the head for this one to work. +The link tag should be as follows: + +```html + +``` + +Take note that there is a `../assets/` preceeding each filename. +This is very important for the way the file URL's work. + +Let's add an editor to the HTML page now. +To whichever section you want to make the editor section, add the class `editor-section`. +Then place another div inside of this section with the class `editor`. +Best practice is also to give the editor div an ID so that it identifiable from the script. +For the code highlighting to work, also add a language class to the editor. +This should be something like `"lang-html"` or `"lang-js"`. +The final result should look something like this: + +```html +
+
+
+``` + +We now add this editor as a CodeJar in the script. +First, create a `script.js` file and add it to the end of the body, after the other three script tags. +In this file, we'll create a CodeJar and test the methods of manipulating it. +First, get the div element with the class `"editor"`, in this case it has an id of `"editor"` as well. +Then pass this into the `Codejar` class constructor. +For the basic highlighting use `Prism.highlightElement`; for line numbers wrap this in the `withLineNumbers` function. +The last argument is for the options of the editor. +A final Codejar with line numbers and prism highlighting would look something like this. + +```js +let editorElement = document.getElementById("editor"); +let jar = CodeJar(editorElement, withLineNumbers(Prism.highlightElement, { + color: '#000', + backgroundColor: 'rgb(232, 232, 232)' +}), { + tab: ' ', + indentOn: /[\[({]$/ +}); +``` + +The last options are the tab size/character, and when to auto-indent. +For JavaScript this can be kept to default, however, for HTML it should be changed to something like `/<[a-zA-Z =\"\-]+>$/`. + +There are three methods that are used on this code jar: `updateCode`, `toString`, and `onUpdate`. +First, `updateCode` takes in a string and sets the code in the editor. +The method `toString` returns a string containing the code in the editor. +Finally, `onUpdate` takes a function as the only parameter, which is called any time the code in the editor changes. + +Examples of these functions being used include: an execute button that calls `toString` and passes it into the source of an iframe, auto saving 3 seconds after the last code update, and creating an animated code/result display. +All three of these examples are in the `div-demo/script.js` file. + + +[0]: https://sass-lang.com/guide +[1]: https://sass-lang.com/install diff --git a/while-loop-demo/index.html b/while-loop-demo/index.html new file mode 100644 index 0000000..cfe22f8 --- /dev/null +++ b/while-loop-demo/index.html @@ -0,0 +1,114 @@ + + + + While Loop Demo | Bit by Bit + + + + + + + + + +
+
+

+

While Loops

+ Loops are a way to iterate a piece of code for as long as you want it to be run. While loops are a type of loop that run code as long as the given condition is true. + These loops are useful when you want to run code for an unknown number of times, until a condition is no longer true, or while a condition is being met. +

+ Some uses of while loops include: + +

+
+
+
+

+

Example 1

+ Hold down the button to start the timer, and let go to stop the timer. The counter goes up only while the button is pressed. Once you let go of the button, the condition is no longer met, and the counter stops counting. Use the slider to change the interval between increments of the counter. +

+
+

+ Count Gap: +
+

+

+ Counter: 0 +

+
+
+

+ //Finds the place where "Counter" is located
+ var countValue = document.getElementById("Counter");
+ //Sets initial count to 0
+ var count = 0;
+
+ //This function is run when the button is pressed
+ function startCount() {
+
+  //As long as the button is held down, the code is run
+  while (buttonPressed) {
+   countValue.innerHTML = Counter + count;
+   count++;
+  }
+ }
+ *Simplified version of code +

+
+
+
+
+
+

+

Example 2

+ Hover over the space below to view the BxB bots. The images will only show up while the mouse is hovering over them. Once you move your mouse off the images, they will no longer be visible.

+ + + + + + +
+
+

+ //Finds the place where the BxB bot is located
+ var botImage = document.getElementById("bot");
+ //Sets initial opacity to 0, making it invisible
+ botImage.style.opacity = "0"; +

+ //This function is run only while the image is being hovered over.
+ function changeVisibility() {
+
+  //While the mouse is hovering over the image, the opacity is changed to 1.
+  while (botImage.hovered === true) {
+   botImage.style.opacity = "1";
+  }
+ }
+ *Simplified version of code +

+
+
+ +
+ + diff --git a/while-loop-demo/script.js b/while-loop-demo/script.js new file mode 100644 index 0000000..4000ce8 --- /dev/null +++ b/while-loop-demo/script.js @@ -0,0 +1,28 @@ +var e1CounterText = document.getElementById('e1'); +var e1SliderAmount = document.getElementById("e1SliderAmount"); +var c; +var count = 0; + +function e1stop() +{ + clearInterval(c); +} +function e1start() +{ + var e1Slider = document.getElementById("e1TimerValue"); + if (e1Slider.value == 10) + { + e1SliderAmount.innerHTML = "1 second"; + } + else{ + e1SliderAmount.innerHTML = (e1Slider.value*100)+" millseconds"; + } + c = setInterval(function() { + e1CounterText.innerHTML = "Counter: "+count; + count++; + }, (e1Slider.value*100)); +} +function e1onchange(x) { + e1SliderValue = x; + +} diff --git a/while-loop-demo/style.css b/while-loop-demo/style.css new file mode 100644 index 0000000..512769f --- /dev/null +++ b/while-loop-demo/style.css @@ -0,0 +1,252 @@ +/* style.scss */ +/* Import the common styling */ +/* common.scss */ +/* Define all the colors */ +body { + margin: 5em 0 0 0; + padding: 0; + background-color: #fff; + font-family: 'Nunito', sans-serif; + font-weight: 600; +} + +button { + border: none; + background: #38Bfe7; + padding: 0.5em 1em; + -webkit-box-shadow: 0.125em 0.125em 0.2em #bfbfbf; + box-shadow: 0.125em 0.125em 0.2em #bfbfbf; + cursor: pointer; +} + +button:hover { + background-color: #19a8d3; +} + +button:active { + -webkit-box-shadow: none; + box-shadow: none; +} + +#header { + padding: 1em 2em; + background-color: white; + color: #000; + position: fixed; + top: 0; + left: 0; + width: 100%; + max-height: 3em; + z-index: 1000; + opacity: 95%; + -webkit-box-shadow: 0 2px 2px #eee; + box-shadow: 0 2px 2px #eee; +} + +#header > * { + margin: 0; +} + +#header button { + width: 3em; +} + +#back-button { + padding: 0.25em 1em; + font-size: 1em; + height: 48px; +} + +.content { + padding: 1em; + max-width: 80%; + margin: 0 auto; +} + +/*Flexbox*/ +.flex-container-header { + display: -webkit-box; + display: -ms-flexbox; + display: flex; + -webkit-box-pack: justify; + -ms-flex-pack: justify; + justify-content: space-between; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; +} + +.flex-container-left { + display: -webkit-box; + display: -ms-flexbox; + display: flex; + -webkit-box-pack: space-evenly; + -ms-flex-pack: space-evenly; + justify-content: space-evenly; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + max-width: -webkit-max-content; + max-width: -moz-max-content; + max-width: max-content; +} + +.flex-item-header { + -webkit-box-flex: 1; + -ms-flex: 1 1 200px; + flex: 1 1 200px; +} + +.flex-item-left { + -webkit-box-flex: 1; + -ms-flex: 1 1 100px; + flex: 1 1 100px; + max-width: -webkit-max-content; + max-width: -moz-max-content; + max-width: max-content; +} + +#top-heading { + width: -webkit-max-content; + width: -moz-max-content; + width: max-content; +} + +#bxb-logo { + max-height: 3em; + display: block; + text-align: left; + margin-left: calc(100% - 200px); +} + +.section { + margin: 1em 0; + padding: 0.5em; + border: 0.2em solid #38Bfe7; + background-color: #fff; + color: #000; +} + +.flex-box { + display: -webkit-box; + display: -ms-flexbox; + display: flex; +} + +.flex-col { + -webkit-box-flex: 1; + -ms-flex: 1; + flex: 1; + padding: 0.5em; +} + +.flex-col:not(:last-child) { + margin: 0 0.2em 0 0; +} + +.flex-col:last-child { + margin: 0 0 0 0.2em; +} + +.no-flex-col { + -webkit-box-flex: 0; + -ms-flex: 0; + flex: 0; +} + +.showcase-section { + padding: 0; +} + +.editor-section { + position: relative; + overflow: scroll; + padding: 0; +} + +.editor { + margin: 0; + height: 20em; + width: calc(100% - 35px - calc(0.625em*2)); + font-family: 'Anonymous Pro', monospace; + font-size: 0.875em; + line-height: 1.25em; + padding: 1px 0.625em; +} + +.editor-button-overlay { + position: absolute; + bottom: 1em; + right: 1em; + padding: 0; +} + +/* The page-specific styling */ +/* TODO: Put whatever styles you need for just your demo here */ +.bold { + font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; + font-weight: 800; +} + +.center { + text-align: center; +} + +.e1 { + text-align: center; + color: #f19100; +} + +.slider { + -webkit-appearance: none; + width: 100%; + height: 15px; + border-radius: 5px; + background: #d3d3d3; + outline: none; + opacity: 0.7; + -webkit-transition: .2s; + -webkit-transition: opacity .2s; + transition: opacity .2s; +} + +.slider::-webkit-slider-thumb { + -webkit-appearance: none; + appearance: none; + width: 20px; + height: 20px; + border-radius: 50%; + background: #38Bfe7; + cursor: pointer; +} + +.slider::-moz-range-thumb { + width: 20px; + height: 20px; + border-radius: 50%; + background: #38Bfe7; + cursor: pointer; +} + +.comment { + font-style: italic; + color: #0ba06e; +} + +.code { + color: #f19100; +} + +.bot { + width: 100px; + transition: opacity 0.5s; + -webkit-transition: opacity 0.5s; + opacity: 0; +} + +.bot:hover { + transition: opacity 0.5s; + -webkit-transition: opacity 0.5s; + opacity: 1; +} +/*# sourceMappingURL=style.css.map */ \ No newline at end of file diff --git a/while-loop-demo/style.scss b/while-loop-demo/style.scss new file mode 100644 index 0000000..c94d97a --- /dev/null +++ b/while-loop-demo/style.scss @@ -0,0 +1,72 @@ +/* style.scss */ + +/* Import the common styling */ +@import "../assets/common.scss"; + +/* The page-specific styling */ +/* TODO: Put whatever styles you need for just your demo here */ + +.bold { + font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; + font-weight: 800; + } + + +.center { + text-align: center; +} + +.e1 { + text-align:center; + color:#f19100; +} + +//slider +.slider { + -webkit-appearance: none; + width: 100%; + height: 15px; + border-radius: 5px; + background: #d3d3d3; + outline: none; + opacity: 0.7; + -webkit-transition: .2s; + transition: opacity .2s; +} + +.slider::-webkit-slider-thumb { + -webkit-appearance: none; + appearance: none; + width: 20px; + height: 20px; + border-radius: 50%; + background: #38Bfe7; + cursor: pointer; +} + +.slider::-moz-range-thumb { + width: 20px; + height: 20px; + border-radius: 50%; + background: #38Bfe7; + cursor: pointer; +} +.comment { + font-style: italic; + color:rgb(11, 160, 110); +} +.code { + color: #f19100; +} + +.bot { + width:100px; + transition: opacity 0.5s; + -webkit-transition: opacity 0.5s; + opacity: 0; +} +.bot:hover { + transition: opacity 0.5s; + -webkit-transition: opacity 0.5s; + opacity: 1; +} \ No newline at end of file From fb11604551f9ef6f1075d95dcd437a1c54849a66 Mon Sep 17 00:00:00 2001 From: BhargavM1 <58884443+BhargavM1@users.noreply.github.com> Date: Mon, 15 Nov 2021 23:24:21 -0500 Subject: [PATCH 2/7] added do while loop --- while-loop-demo/index.html | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/while-loop-demo/index.html b/while-loop-demo/index.html index cfe22f8..8b3cb29 100644 --- a/while-loop-demo/index.html +++ b/while-loop-demo/index.html @@ -104,10 +104,24 @@

Example 2

  botImage.style.opacity = "1";
 }
}
- *Simplified version of code + *Simplified version of code

+
+

+

Do While Loops

+ Do while loops are a type of while loops. They have the same function as while loops, but they run one time before even checking the condition of the while loop. In other words, + it runs the code one time and then checks to see if it should keep running. +

+ Some uses of do while loops include: + +

+
From aa0a56f5b2a375f88d2ff05e4ff0744e47b66d60 Mon Sep 17 00:00:00 2001 From: BhargavM1 <58884443+BhargavM1@users.noreply.github.com> Date: Tue, 16 Nov 2021 18:33:53 -0500 Subject: [PATCH 3/7] added do-while loop demo + font change --- while-loop-demo/index.html | 32 ++++++++++++++++++++++++++++++++ while-loop-demo/script.js | 12 ++++++++++++ while-loop-demo/style.css | 1 + while-loop-demo/style.scss | 1 + 4 files changed, 46 insertions(+) diff --git a/while-loop-demo/index.html b/while-loop-demo/index.html index 8b3cb29..95c5ac8 100644 --- a/while-loop-demo/index.html +++ b/while-loop-demo/index.html @@ -122,6 +122,38 @@

Do While Loops

+
+
+

+

Example 3

+ Try out an application of do while loops below. The purpose of this program is to keep asking for the password until you get it right. It will run the code once to get your first attempt and keep running until you get it right.
Hint: The password is "password123".

+
+ +
+
+
+

+ //Sets an empty string to the password variable.
+ var pass = "";
+

+ //This function runs when the button is pressed and it asks for the password.
+ function askPassword() {
+
+  //The code is run once to ask for initial password input..
+  do {
+   pass = prompt("Please enter the password");

+ //This lets the user know if the password is incorrect. +   if (pass!="password123")
+     alert("Incorrect password");

+  }
+  while(pass!="password123")

+ //Lets the user know the correct password was entered
+  alert("Correct password entered");
+ }
+ *Simplified version of code +

+
+
diff --git a/while-loop-demo/script.js b/while-loop-demo/script.js index 4000ce8..631b955 100644 --- a/while-loop-demo/script.js +++ b/while-loop-demo/script.js @@ -26,3 +26,15 @@ function e1onchange(x) { e1SliderValue = x; } + +function e3() { +var pass = ""; + do { + pass = prompt("Please enter the password"); + if (pass!="password123") + alert("Incorrect password"); + } + while(pass!="password123") + + alert("Correct password entered"); +} \ No newline at end of file diff --git a/while-loop-demo/style.css b/while-loop-demo/style.css index 512769f..10bf0fe 100644 --- a/while-loop-demo/style.css +++ b/while-loop-demo/style.css @@ -235,6 +235,7 @@ button:active { .code { color: #f19100; + font-family: 'Anonymous Pro', monospace; } .bot { diff --git a/while-loop-demo/style.scss b/while-loop-demo/style.scss index c94d97a..68e7cda 100644 --- a/while-loop-demo/style.scss +++ b/while-loop-demo/style.scss @@ -57,6 +57,7 @@ } .code { color: #f19100; + font-family: 'Anonymous Pro', monospace; } .bot { From d9a291aece7838aaa749cf225038a16b068380a1 Mon Sep 17 00:00:00 2001 From: BhargavM1 <58884443+BhargavM1@users.noreply.github.com> Date: Wed, 17 Nov 2021 22:33:45 -0500 Subject: [PATCH 4/7] Update script.js --- script.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/script.js b/script.js index 2e5f581..8f2c63f 100644 --- a/script.js +++ b/script.js @@ -55,6 +55,11 @@ let interactiveTutorials = { path: 'truthy-falsy-demo', title: 'TRUTHY AND FALSY VALUES DEMO', content: "What are truthy and falsy values in JavaScript? What expressions evaluate to boolean false?" + }, + whileLoopDemo: { + path: 'while-loop-demo', + title: 'WHILE LOOP DEMO', + content: "What are while loops and do while loops?" } }; From d97abb8b8e4767e9961c58a16ac993b614c19a41 Mon Sep 17 00:00:00 2001 From: BhargavM1 <58884443+BhargavM1@users.noreply.github.com> Date: Sun, 21 Nov 2021 22:13:44 -0500 Subject: [PATCH 5/7] started animations demo --- animations-demo/README.md | 125 +++++++++++++++++++++++ animations-demo/index.html | 76 ++++++++++++++ animations-demo/script.js | 4 + animations-demo/style.css | 200 +++++++++++++++++++++++++++++++++++++ animations-demo/style.scss | 21 ++++ 5 files changed, 426 insertions(+) create mode 100644 animations-demo/README.md create mode 100644 animations-demo/index.html create mode 100644 animations-demo/script.js create mode 100644 animations-demo/style.css create mode 100644 animations-demo/style.scss diff --git a/animations-demo/README.md b/animations-demo/README.md new file mode 100644 index 0000000..ae5f377 --- /dev/null +++ b/animations-demo/README.md @@ -0,0 +1,125 @@ +# interactive-tutorials Template Files + +This folder is made to show what the start of an interactive tutorial might look like. +Remember, however, that a lot of creating a tutorial is creative freedom. +Thus, don't take these as hard fast rules but rather guidelines. +We want to show a uniform look in all the tutorials and so that's why this template exists. +With this said, this document will walk you through how to create your own interactive tutorial. + +### Jumping In + +First, we need to get the back-bone of the tutorial page. +There is an `index.html` file inside the `template` directory, this is an example of a minimal demo. +In fact, this demo isn't even functional. +With no editor, input, or real result, you'll have to add all those yourself. +To do this we need a `script.js` and some understanding of how each of the common assets work. + +Let's start! +Copy the `template` folder to a new folder in the same root `interactive-demos` directory. +For our purposes, we'll call this the `test-demo`. +Then open the `index.html` file. +Inside you'll find HTML comments with the prefix `TODO:`, these point to places that need replaced. +For example, the header below the `` comment should be replaced with the name of your demo. +Inside the `"content"` div there is already a few sections. +Open the page up to see what this layout produces and read the contents of each section. + +### The First Common + +There's already styling on the page, but how exactly does it work? +There's a `style.css` file, but this isn't our css file. +Another file, `style.scss`, is what we use to modify the styling on the page. +If you don't already know SASS, quickly read up on it [here][0]. +Then, install it using the instructions [here][1]. +(The best method is just using `npm install -g sass`.) + +Notice the top of the `style.scss` file, `@import "../assets/common.scss";`. +This takes the common SASS file and using its styling and then overwrites them with whatever your styles are. +The `..` is there because the assets directory is one level up from where the demos are. +If you use any other assets such as CodeJar, line numbers, or the options files, don't forget this `..` before the path. + +### Proper Local Development + +So far, we've been viewing the file as the `index.html` file, and sometimes this is fine. +However, for the best results, we should use a local webserver. +To do this we will use `serve` on npm. +Install it using `npm install -g serve`. +Then run it using `serve` inside the `interactive-demos` directory. +It's recommended to do this in a new terminal window. +It should then start hosting a static webserver at `localhost:5000`. +When making changes to any files be sure to also reload your web view. +To stop it, press `Ctrl + C`. + +### Code Editor + +The code editor that the demos use is called CodeJar. +First, we must add the assets to the html file. +Add these three script tags to the bottom of the body in the `index.html` file. + +```html + + + +``` + +The first asset, CodeJar, is the actual code editor. +We'll add the editor in a moment. +Next, `linenumbers.js` is an extension to the CodeJar library. +Finally, Prism is a code highlighting library. +We also need to add a CSS file to the head for this one to work. +The link tag should be as follows: + +```html + +``` + +Take note that there is a `../assets/` preceeding each filename. +This is very important for the way the file URL's work. + +Let's add an editor to the HTML page now. +To whichever section you want to make the editor section, add the class `editor-section`. +Then place another div inside of this section with the class `editor`. +Best practice is also to give the editor div an ID so that it identifiable from the script. +For the code highlighting to work, also add a language class to the editor. +This should be something like `"lang-html"` or `"lang-js"`. +The final result should look something like this: + +```html +
+
+
+``` + +We now add this editor as a CodeJar in the script. +First, create a `script.js` file and add it to the end of the body, after the other three script tags. +In this file, we'll create a CodeJar and test the methods of manipulating it. +First, get the div element with the class `"editor"`, in this case it has an id of `"editor"` as well. +Then pass this into the `Codejar` class constructor. +For the basic highlighting use `Prism.highlightElement`; for line numbers wrap this in the `withLineNumbers` function. +The last argument is for the options of the editor. +A final Codejar with line numbers and prism highlighting would look something like this. + +```js +let editorElement = document.getElementById("editor"); +let jar = CodeJar(editorElement, withLineNumbers(Prism.highlightElement, { + color: '#000', + backgroundColor: 'rgb(232, 232, 232)' +}), { + tab: ' ', + indentOn: /[\[({]$/ +}); +``` + +The last options are the tab size/character, and when to auto-indent. +For JavaScript this can be kept to default, however, for HTML it should be changed to something like `/<[a-zA-Z =\"\-]+>$/`. + +There are three methods that are used on this code jar: `updateCode`, `toString`, and `onUpdate`. +First, `updateCode` takes in a string and sets the code in the editor. +The method `toString` returns a string containing the code in the editor. +Finally, `onUpdate` takes a function as the only parameter, which is called any time the code in the editor changes. + +Examples of these functions being used include: an execute button that calls `toString` and passes it into the source of an iframe, auto saving 3 seconds after the last code update, and creating an animated code/result display. +All three of these examples are in the `div-demo/script.js` file. + + +[0]: https://sass-lang.com/guide +[1]: https://sass-lang.com/install diff --git a/animations-demo/index.html b/animations-demo/index.html new file mode 100644 index 0000000..0731f88 --- /dev/null +++ b/animations-demo/index.html @@ -0,0 +1,76 @@ + + + + + Animations Demo | Bit by Bit + + + + + + + + +
+ +
+

+ Animations are used in many T.V. shows and cartoons, and they can also be programmed in JavaScript. All you have to do is write a function, to perform a movement or change in color/shape + and call that function with an object.

+ + You can use animations to perform any of these: +

+

+
+
+
+

+

Example 1

+ Press the button below and watch the BxB bot move from one side to the oher. The button is linked to a function that animates the bot to move from one side to the other. +

+ +
+
+

+ //Finds the place where "Counter" is located
+ var countValue = document.getElementById("Counter");
+ //Sets initial count to 0
+ var count = 0;
+
+ //This function is run when the button is pressed
+ function startCount() {
+
+  //As long as the button is held down, the code is run
+  while (buttonPressed) {
+   countValue.innerHTML = Counter + count;
+   count++;
+  }
+ }
+ *Simplified version of code +

+
+
+ +
+ + + diff --git a/animations-demo/script.js b/animations-demo/script.js new file mode 100644 index 0000000..f231dec --- /dev/null +++ b/animations-demo/script.js @@ -0,0 +1,4 @@ +e1animate() +{ + +} \ No newline at end of file diff --git a/animations-demo/style.css b/animations-demo/style.css new file mode 100644 index 0000000..aa70982 --- /dev/null +++ b/animations-demo/style.css @@ -0,0 +1,200 @@ +/* style.scss */ +/* Import the common styling */ +/* common.scss */ +/* Define all the colors */ +body { + margin: 5em 0 0 0; + padding: 0; + background-color: #fff; + font-family: 'Nunito', sans-serif; + font-weight: 600; +} + +button { + border: none; + background: #38Bfe7; + padding: 0.5em 1em; + -webkit-box-shadow: 0.125em 0.125em 0.2em #bfbfbf; + box-shadow: 0.125em 0.125em 0.2em #bfbfbf; + cursor: pointer; +} + +button:hover { + background-color: #19a8d3; +} + +button:active { + -webkit-box-shadow: none; + box-shadow: none; +} + +#header { + padding: 1em 2em; + background-color: white; + color: #000; + position: fixed; + top: 0; + left: 0; + width: 100%; + max-height: 3em; + z-index: 1000; + opacity: 95%; + -webkit-box-shadow: 0 2px 2px #eee; + box-shadow: 0 2px 2px #eee; +} + +#header > * { + margin: 0; +} + +#header button { + width: 3em; +} + +#back-button { + padding: 0.25em 1em; + font-size: 1em; + height: 48px; +} + +.content { + padding: 1em; + max-width: 80%; + margin: 0 auto; +} + +/*Flexbox*/ +.flex-container-header { + display: -webkit-box; + display: -ms-flexbox; + display: flex; + -webkit-box-pack: justify; + -ms-flex-pack: justify; + justify-content: space-between; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; +} + +.flex-container-left { + display: -webkit-box; + display: -ms-flexbox; + display: flex; + -webkit-box-pack: space-evenly; + -ms-flex-pack: space-evenly; + justify-content: space-evenly; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + max-width: -webkit-max-content; + max-width: -moz-max-content; + max-width: max-content; +} + +.flex-item-header { + -webkit-box-flex: 1; + -ms-flex: 1 1 200px; + flex: 1 1 200px; +} + +.flex-item-left { + -webkit-box-flex: 1; + -ms-flex: 1 1 100px; + flex: 1 1 100px; + max-width: -webkit-max-content; + max-width: -moz-max-content; + max-width: max-content; +} + +#top-heading { + width: -webkit-max-content; + width: -moz-max-content; + width: max-content; +} + +#bxb-logo { + max-height: 3em; + display: block; + text-align: left; + margin-left: calc(100% - 200px); +} + +.section { + margin: 1em 0; + padding: 0.5em; + border: 0.2em solid #38Bfe7; + background-color: #fff; + color: #000; +} + +.flex-box { + display: -webkit-box; + display: -ms-flexbox; + display: flex; +} + +.flex-col { + -webkit-box-flex: 1; + -ms-flex: 1; + flex: 1; + padding: 0.5em; +} + +.flex-col:not(:last-child) { + margin: 0 0.2em 0 0; +} + +.flex-col:last-child { + margin: 0 0 0 0.2em; +} + +.no-flex-col { + -webkit-box-flex: 0; + -ms-flex: 0; + flex: 0; +} + +.showcase-section { + padding: 0; +} + +.editor-section { + position: relative; + overflow: scroll; + padding: 0; +} + +.editor { + margin: 0; + height: 20em; + width: calc(100% - 35px - calc(0.625em*2)); + font-family: 'Anonymous Pro', monospace; + font-size: 0.875em; + line-height: 1.25em; + padding: 1px 0.625em; +} + +.editor-button-overlay { + position: absolute; + bottom: 1em; + right: 1em; + padding: 0; +} + +/* The page-specific styling */ +/* TODO: Put whatever styles you need for just your demo here */ +.bold { + font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; + font-weight: 800; +} + +.comment { + font-style: italic; + color: #0ba06e; +} + +.code { + color: #f19100; + font-family: 'Anonymous Pro', monospace; +} +/*# sourceMappingURL=style.css.map */ \ No newline at end of file diff --git a/animations-demo/style.scss b/animations-demo/style.scss new file mode 100644 index 0000000..a3fa53a --- /dev/null +++ b/animations-demo/style.scss @@ -0,0 +1,21 @@ +/* style.scss */ + +/* Import the common styling */ +@import "../assets/common.scss"; + +/* The page-specific styling */ +/* TODO: Put whatever styles you need for just your demo here */ + +.bold { + font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; + font-weight: 800; + } + +.comment { + font-style: italic; + color:rgb(11, 160, 110); +} +.code { + color: #f19100; + font-family: 'Anonymous Pro', monospace; +} \ No newline at end of file From e45939146299d96edaaca66f90f3e0eecc56219e Mon Sep 17 00:00:00 2001 From: BhargavM1 <58884443+BhargavM1@users.noreply.github.com> Date: Wed, 29 Dec 2021 21:45:41 -0500 Subject: [PATCH 6/7] finished animations demo --- animations-demo/index.html | 120 ++++++++++++++++++++++++++++++++----- animations-demo/script.js | 45 +++++++++++++- animations-demo/style.css | 47 +++++++++++++++ animations-demo/style.scss | 46 ++++++++++++++ 4 files changed, 241 insertions(+), 17 deletions(-) diff --git a/animations-demo/index.html b/animations-demo/index.html index 0731f88..13b4edc 100644 --- a/animations-demo/index.html +++ b/animations-demo/index.html @@ -45,30 +45,122 @@

ANIMATIONS DEMO

Example 1

- Press the button below and watch the BxB bot move from one side to the oher. The button is linked to a function that animates the bot to move from one side to the other. + Press the button below and watch the BxB bot move from one side to the other. The button is linked to a function that animates the bot to move from one side to the other.

- +

+ BxB Bot

- //Finds the place where "Counter" is located
- var countValue = document.getElementById("Counter");
- //Sets initial count to 0
- var count = 0;
+ //This is the css declaration for the image of the bot. This is applied via Javascript when the button is pressed.
+ #animatedBot {
+  width: 20%;
+  height: 20%;
+  position: relative; +  -webkit-animation:move 2.5s ease-in-out;
+ }
+
+ //This is the actual animation of the bot
+ @-webkit-keyframes move {
+  from {
+   left: 0px;
+   top: 0px;
+  }
- //This function is run when the button is pressed
- function startCount() {
-
-  //As long as the button is held down, the code is run
-  while (buttonPressed) {
-   countValue.innerHTML = Counter + count;
-   count++;
-  }
+  to {
+   left: 300px;
+   top: 0px;
+  }

+ *Simplified version of code +

+
+ +
+
+
+

+

Example 2

+ Press the button below to watch the BxB bot appear and disappear. Animations can be also set with a delay, which makes them appear after a period of time. +

+

+ Delay:

+ BxB Bot +
+
+

+ //This is the css declaration for the image of the bot. This is applied via Javascript when the button is pressed.
+ #animatedBot {
+  width: 20%;
+  height: 20%;
+  position: relative; +  -webkit-animation:appear 2.5 ease-in-out;
+  animation-delay: (delay set by Javascript)
}
+
+ //This is the actual animation of the bot
+ @-webkit-keyframes appear {
+  from {
+   opacity: 0;
+  } +

+  to {
+   opacity: 1;
+  }

*Simplified version of code

+
+

+ There are many different properties of animations that could be applied. The table below shows the name and purpose of a few of these properties. +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
PropertyDescription
@keyframesSignifies the animation code
animationSets all animation properties to default
animation-delaySets delay for animation
animation-directionSets the cycle in which the animation should run
animation-durationSets the time-period for one animation cycle
animation-fill-modeSets style for animation while not running
animation-iteration-countSpecifies the number of times the animation should run
animation-nameSets the name of the @keyframes animation
animation-play-stateSets the current status of animation (playing, paused)
animation-timing-functionSpecifies the speed of the animation
+
diff --git a/animations-demo/script.js b/animations-demo/script.js index f231dec..cf2dee3 100644 --- a/animations-demo/script.js +++ b/animations-demo/script.js @@ -1,4 +1,43 @@ -e1animate() -{ - +var id = null; +function e1Example() { + var elem = document.getElementById("e1Bot"); + var pos = 0; + clearInterval(id); + id = setInterval(frame, 10); + function frame() { + if (pos == 300) { + clearInterval(id); + } else { + pos++; + elem.style.left = pos + 'px'; + } + } +} + +function e2Example() { + var elem = document.getElementById("e2Bot"); + var delay = document.getElementById("e2DelayValue"); + setTimeout(e2, delay.value*1000); +} + +function e2() { + var elem = document.getElementById("e2Bot"); + var opacity = 0; + clearInterval(id); + id = setInterval(frames, 100); + function frames() { + if (opacity == 1) { + clearInterval(id); + } + else { + opacity+=0.1; + elem.style.opacity = opacity; + } + } + setTimeout(e2Finish, 1000) +} + +function e2Finish() { + var elem = document.getElementById("e2Bot"); + elem.style.opacity = 0; } \ No newline at end of file diff --git a/animations-demo/style.css b/animations-demo/style.css index aa70982..43cd838 100644 --- a/animations-demo/style.css +++ b/animations-demo/style.css @@ -197,4 +197,51 @@ button:active { color: #f19100; font-family: 'Anonymous Pro', monospace; } + +.slider { + -webkit-appearance: none; + width: 70%; + height: 15px; + border-radius: 5px; + background: #d3d3d3; + outline: none; + opacity: 0.7; + -webkit-transition: .2s; + -webkit-transition: opacity .2s; + transition: opacity .2s; +} + +.slider::-webkit-slider-thumb { + -webkit-appearance: none; + appearance: none; + width: 20px; + height: 20px; + border-radius: 50%; + background: #38Bfe7; + cursor: pointer; +} + +.slider::-moz-range-thumb { + width: 20px; + height: 20px; + border-radius: 50%; + background: #38Bfe7; + cursor: pointer; +} + +table, th, td { + border: 1px solid black; +} + +#e1Bot { + width: 20%; + height: 20%; + position: relative; +} + +#e2Bot { + width: 20%; + height: 20%; + opacity: 0; +} /*# sourceMappingURL=style.css.map */ \ No newline at end of file diff --git a/animations-demo/style.scss b/animations-demo/style.scss index a3fa53a..af2b3a2 100644 --- a/animations-demo/style.scss +++ b/animations-demo/style.scss @@ -18,4 +18,50 @@ .code { color: #f19100; font-family: 'Anonymous Pro', monospace; +} + +.slider { + -webkit-appearance: none; + width: 70%; + height: 15px; + border-radius: 5px; + background: #d3d3d3; + outline: none; + opacity: 0.7; + -webkit-transition: .2s; + transition: opacity .2s; +} + +.slider::-webkit-slider-thumb { + -webkit-appearance: none; + appearance: none; + width: 20px; + height: 20px; + border-radius: 50%; + background: #38Bfe7; + cursor: pointer; +} + +.slider::-moz-range-thumb { + width: 20px; + height: 20px; + border-radius: 50%; + background: #38Bfe7; + cursor: pointer; +} + +table, th, td { + border:1px solid black; +} + +#e1Bot { + width: 20%; + height: 20%; + position: relative; +} + +#e2Bot { + width: 20%; + height: 20%; + opacity: 0; } \ No newline at end of file From ffd17129b802acfd2aa4f5d59e9e5289c3546ba6 Mon Sep 17 00:00:00 2001 From: BhargavM1 <58884443+BhargavM1@users.noreply.github.com> Date: Sun, 2 Jan 2022 18:58:46 -0500 Subject: [PATCH 7/7] final animations demo --- animations-demo/index.html | 107 +++++++++++++++++++------------------ animations-demo/style.css | 11 +++- animations-demo/style.scss | 10 +++- 3 files changed, 72 insertions(+), 56 deletions(-) diff --git a/animations-demo/index.html b/animations-demo/index.html index 13b4edc..3947091 100644 --- a/animations-demo/index.html +++ b/animations-demo/index.html @@ -29,7 +29,9 @@

ANIMATIONS DEMO

+

Introduction

+ Animations are used in many T.V. shows and cartoons, and they can also be programmed in JavaScript. All you have to do is write a function, to perform a movement or change in color/shape and call that function with an object.

@@ -41,6 +43,58 @@

ANIMATIONS DEMO

+
+

Properties

+

+ There are many different properties of animations that could be applied. The table below shows the name and purpose of a few of these properties. +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
PropertyDescription
@keyframesSignifies the animation code
animationSets all animation properties to default
animation-delaySets delay for animation
animation-directionSets the cycle in which the animation should run
animation-durationSets the time-period for one animation cycle
animation-fill-modeSets style for animation while not running
animation-iteration-countSpecifies the number of times the animation should run
animation-nameSets the name of the @keyframes animation
animation-play-stateSets the current status of animation (playing, paused)
animation-timing-functionSpecifies the speed of the animation
+

@@ -92,7 +146,7 @@

Example 2

#animatedBot {
 width: 20%;
 height: 20%;
-  position: relative; +  position: relative;
 -webkit-animation:appear 2.5 ease-in-out;
 animation-delay: (delay set by Javascript)
}
@@ -110,57 +164,6 @@

Example 2

-
-

- There are many different properties of animations that could be applied. The table below shows the name and purpose of a few of these properties. -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PropertyDescription
@keyframesSignifies the animation code
animationSets all animation properties to default
animation-delaySets delay for animation
animation-directionSets the cycle in which the animation should run
animation-durationSets the time-period for one animation cycle
animation-fill-modeSets style for animation while not running
animation-iteration-countSpecifies the number of times the animation should run
animation-nameSets the name of the @keyframes animation
animation-play-stateSets the current status of animation (playing, paused)
animation-timing-functionSpecifies the speed of the animation
-
diff --git a/animations-demo/style.css b/animations-demo/style.css index 43cd838..1ace458 100644 --- a/animations-demo/style.css +++ b/animations-demo/style.css @@ -229,8 +229,15 @@ button:active { cursor: pointer; } -table, th, td { - border: 1px solid black; +table, th { + border: 2px solid #38bfe7; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + margin: 0 auto; + position: relative; + border-collapse: collapse; + padding: 1%; } #e1Bot { diff --git a/animations-demo/style.scss b/animations-demo/style.scss index af2b3a2..28b48af 100644 --- a/animations-demo/style.scss +++ b/animations-demo/style.scss @@ -50,8 +50,14 @@ cursor: pointer; } -table, th, td { - border:1px solid black; + +table, th{ + border:2px solid #38bfe7; + align-items: center; + margin: 0 auto; + position: relative; + border-collapse: collapse; + padding: 1%; } #e1Bot {