diff --git a/IMC_WebDev/FromDayToNight-CreatingInteractiveColorPalettesWithJavaScript/blog.md b/IMC_WebDev/FromDayToNight-CreatingInteractiveColorPalettesWithJavaScript/blog.md new file mode 100644 index 0000000..296e455 --- /dev/null +++ b/IMC_WebDev/FromDayToNight-CreatingInteractiveColorPalettesWithJavaScript/blog.md @@ -0,0 +1,396 @@ +# From Day to Night - Creating Interactive Color Palettes with JavaScript + +Now that you have completed setting up your Mini City in HTML and CSS, have you ever wondered what your Mini City would look like at night? Let's create a day-to-night color palette change by adding buttons with JavaScript! JavaScript is a programming language that is used to create interactive designs, such as buttons, pop-up windows, and more, bringing user interaction to web development projects. + +In this tutorial, you will learn how to do the following: + +- Create buttons with HTML + +- Stylize elements with CSS + +- Add interactivity with JavaScript + + + +## Setting Up Elements in HTML and CSS + +### HTML Code + +Before we start incorporating interactivity into our Mini City with JavaScript, we first need to set up these elements by adding to our HTML code. + +In order to switch from a daytime to nighttime color palette, we will create two clickable buttons, labelled "day" and "night", that will allow us to select the desired setting. To do this, we will add a set of `` tags for each button in the `body` element: + +```html +... + + + + +... +``` + +To prepare for our planned color changes, we need to assign an `id` attribute for each element that is involved, and this allows these elements to be stylized in CSS and manipulate in JavaScript. + +To create a sun that can change into a moon for our Mini City, we will add a `
` element with an `id` named "sun". To change the color of the sky, we must access the `background-color` attribute of the `body` element, so we will set up an `id` named "body". Add the following lines of code to the `body` element: + +```html +... + + + .... +
+ +... +``` + +This is what our completed additions to the HTML code should look like: + +```html +... + + + + + +
+ +... +``` + +This is what our Mini City should look like so far: + +![html_code_1](photos/html_code_1.jpg) + +### CSS Code: Sun and Moon Elements + +Now that we have set up our elements in HTML, we can start adjusting and stylizing them in CSS. + +For our sun element, we will be adding a `#id` selector into our CSS code: + +```html +... + +... +``` + +This kind of selector accesses the element that has the `id` listed after the hashtag, so whatever we add in this selector will affect the `sun` element, which we declared in our HTML code. + +For our `#sun` selector, we will first create the shape and color of the sun using the following attributes: + +```css +... +#sun { + width: 115px; + height: 115px; + border-radius: 50%; + background: radial-gradient(#FFF89E, #FFDE45); +} +... +``` + +With our `width` and `height` attributes having the same length, the default shape that will be created is a square. The `border-radius` attribute defines the radius of the sun's corners, and setting this attribute to 50% will create a perfect circle. Then, in the `background` attribute, we can determine the color of our sun by using the `radial-gradient` function, which creates a gradual transition of colors — the first declared color (light mellow yellow) will be the color at the center of the sun, and the second color (brighter warm yellow) will be the color along the edge of the sun. + +Then, we will determine the location of the sun by adding the following attributes: + +```css +... +#sun { + ... + position: absolute; + left: 350px; + bottom: 75px; +} +... +``` + +Similar to the other elements in our Mini City, we will declaring the `absolute` value to the sun's `position` attribute, which allows the element to move along with the webpage's document body. The `left` attribute affects the element's horizontal position by pushing the sun more to the side, and `bottom` attribute affects the element's vertical position by lifting the sun upwards. + +This is what our sun should look like in our Mini City: + +![](photos/css_code_1.jpg) + +In preparation for our day-to-night change, we can also create our moon element by using the same code template we have for our `sun` element: + +```css +... +#sun { + ... +} + +#moon { + position: absolute; + left: 350px; + bottom: 75px; + width: 115px; + height: 115px; + border-radius: 50%; + background: radial-gradient(#D3D3D3, #555AA6); +} +... +``` + +For our moon, we will use a new selector labelled `#moon` and change the colors in the `radial-gradient` function — the color at the center of our moon will be a light cool gray, and the color at the edges will be a dark grayish violet. + +At this point, we will not be able to view our moon element because we have not declared a `
` element for it in our HTML code. We do not need to declare this because will only be switching back and forth between these two selectors, which we will code in JavaScript later on. + +This is what our completed `#sun` and `#moon` elements should look like: + +```css +... +#sun { + position: absolute; + left: 350px; + bottom: 75px; + background: radial-gradient(#FFF89E, #FFDE45); + width: 115px; + height: 115px; + border-radius: 50%; +} + +#moon { + position: absolute; + left: 350px; + bottom: 75px; + width: 115px; + height: 115px; + border-radius: 50%; + background: radial-gradient(#D3D3D3, #555AA6); +} +... +``` + +### CSS Code: Day and Night Buttons + +To start stylizing our buttons' properties, we will be adding a `button` selector into our code: + +```css +... + +... +``` + +This selector accesses all ` + + +
+ + + +... +``` + +If we want to manipulate the colors of the sun/moon element and the background, we must retrieve our `sun` and `body` elements, respectively, by calling on their `id`. + +To do this, we will declare a `var` or variable — `circle` for the `sun` element and `sky` for the `body` element — and then access each element by using the `document` method `getElementById()`: + +```js +... + +... +``` + +Since we already established the `moon` element for our planned color palette change, we should also choose the color we want our night sky to be. + +To do this, we will create an array named `colors` that will contain the color of our daytime sky and nighttime sky: + +```js +... + +... +``` + +The first color in the array is our default daytime color, which is the light blue that we currently set, and the second color is for our nighttime color palette, which is a dark cool blue. + +Now, to set up our day and night color palettes, we will set up two functions labelled `day` and `night`: + +```js +... + +... +``` + +For each function, we will need to establish two changes: one for our sun-to-moon switch, and another for our day-to-night color change. + +To display our sun during the day and our moon at night, we will retrieve information from our `#sun` and `#moon` elements by using the `setAttribute()` method on our `circle` variable. For the two required parameters, we will set the `id` of this variable to the `sun` and `moon` elements for the day and night color palettes, respectively: + +```js +... +function day() { + circle.setAttribute("id", "sun"); +} +function night() { + circle.setAttribute("id", "moon"); +} +... +``` + +To set our sky colors for the daytime and nighttime, we will accessing the `backgroundColor` attribute of the `body` element through our `sky` variable by appending `.style.backgroundColor` to retrieve and manipulate the CSS properties of this variable. Then, we will set this equal to its respective color of the day and night color palettes in our `colors` array (the index of an array always starts from the number `0`, so `colors[0]` is referring to the daytime color while `colors[1]` is referring to the nighttime color): + +```js +... +function day() { + circle.setAttribute("id", "sun"); + sky.style.backgroundColor = colors[0]; +} +function night() { + circle.setAttribute("id", "moon"); + sky.style.backgroundColor = colors[1]; +} +... +``` + +This is what your completed JavaScript code should look like: + +```js +... + +... +``` + +To tie everything together, we need move back to our HTML code to link our `day()` and `night()` functions to our `day` and `night` buttons, respectively, by adding the `onclick` event to each button: + +```html +... + + + + +... +``` + +Now, you can interact with your Mini City by changing the time of day through the click of a button: + +![CITY](photos/CITY.gif) + + + +## Conclusion + +Congrats on adding an interactive color component to your Mini City! + +Throughout this tutorial, we designed buttons in JavaScript and learned how to stylize and link these elements in HTML and CSS. + +Feel free to add more decorative features to your buttons or implement more actions under the day and night functions to create a more distinct switch between the changing times of the day. Though this blog series may only serve as a very simple introduction to these programming tools, hopefully, this project has sparked your interest and built your confidence in web development and design. diff --git a/IMC_WebDev/FromDayToNight-CreatingInteractiveColorPalettesWithJavaScript/code_finished/base.html b/IMC_WebDev/FromDayToNight-CreatingInteractiveColorPalettesWithJavaScript/code_finished/base.html new file mode 100644 index 0000000..42eca28 --- /dev/null +++ b/IMC_WebDev/FromDayToNight-CreatingInteractiveColorPalettesWithJavaScript/code_finished/base.html @@ -0,0 +1,591 @@ + + + + Mini City Webinar + + + + + + + + +
+ + + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+ +
+ + +
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+ + + \ No newline at end of file diff --git a/IMC_WebDev/FromDayToNight-CreatingInteractiveColorPalettesWithJavaScript/code_starter/base.html b/IMC_WebDev/FromDayToNight-CreatingInteractiveColorPalettesWithJavaScript/code_starter/base.html new file mode 100644 index 0000000..2a4d5c3 --- /dev/null +++ b/IMC_WebDev/FromDayToNight-CreatingInteractiveColorPalettesWithJavaScript/code_starter/base.html @@ -0,0 +1,534 @@ + + + + Mini City Webinar + + + + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+ +
+ + +
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+ + + \ No newline at end of file diff --git a/IMC_WebDev/FromDayToNight-CreatingInteractiveColorPalettesWithJavaScript/photos/CITY.gif b/IMC_WebDev/FromDayToNight-CreatingInteractiveColorPalettesWithJavaScript/photos/CITY.gif new file mode 100644 index 0000000..90ce902 Binary files /dev/null and b/IMC_WebDev/FromDayToNight-CreatingInteractiveColorPalettesWithJavaScript/photos/CITY.gif differ diff --git a/IMC_WebDev/FromDayToNight-CreatingInteractiveColorPalettesWithJavaScript/photos/css_code_1.jpg b/IMC_WebDev/FromDayToNight-CreatingInteractiveColorPalettesWithJavaScript/photos/css_code_1.jpg new file mode 100644 index 0000000..c422716 Binary files /dev/null and b/IMC_WebDev/FromDayToNight-CreatingInteractiveColorPalettesWithJavaScript/photos/css_code_1.jpg differ diff --git a/IMC_WebDev/FromDayToNight-CreatingInteractiveColorPalettesWithJavaScript/photos/css_code_2.jpg b/IMC_WebDev/FromDayToNight-CreatingInteractiveColorPalettesWithJavaScript/photos/css_code_2.jpg new file mode 100644 index 0000000..0459132 Binary files /dev/null and b/IMC_WebDev/FromDayToNight-CreatingInteractiveColorPalettesWithJavaScript/photos/css_code_2.jpg differ diff --git a/IMC_WebDev/FromDayToNight-CreatingInteractiveColorPalettesWithJavaScript/photos/html_code_1.jpg b/IMC_WebDev/FromDayToNight-CreatingInteractiveColorPalettesWithJavaScript/photos/html_code_1.jpg new file mode 100644 index 0000000..5fdd210 Binary files /dev/null and b/IMC_WebDev/FromDayToNight-CreatingInteractiveColorPalettesWithJavaScript/photos/html_code_1.jpg differ diff --git a/IMC_WebDev/FromDayToNight-CreatingInteractiveColorPalettesWithJavaScript/proposal.md b/IMC_WebDev/FromDayToNight-CreatingInteractiveColorPalettesWithJavaScript/proposal.md new file mode 100644 index 0000000..4d6b05c --- /dev/null +++ b/IMC_WebDev/FromDayToNight-CreatingInteractiveColorPalettesWithJavaScript/proposal.md @@ -0,0 +1,30 @@ +**TITLE:** +From Day to Night - Creating Interactive Color Palettes with JavaScript + +**TOPIC:** +JavaScript + +**DESCRIPTION (5-7+ sentences):** +This blog will be the last part of the tiny city blog series, which starts with setting up the HTML and CSS code in the blogs before. Here, the blog will provide a step-by-step tutorial to how to adding interactivity with JavaScript to the tiny city project. The viewer will learn how to adding a mouse-click feature to their project that will switch between a daytime and nighttime setting by changing the colors of their city. Since this blog will be catered towards people who are just getting into web development and coding, this blog will provide thorough explanations at each step and definitions for programming terms. By the end of this blog, the viewer will know the very basics of JavaScript, how to implement and incorporate a mouse-click interaction, and have completed their tiny city web development project. + +### :pushpin: Step 2 +:family: **TARGET AUDIENCE (3-5+ sentences):** +This blog will serve as an introduction to JavaScript for people who are beginners at coding. The viewer will learn, throughout the blog series, how to design a tiny city with learning basic knowledge in HTML/CSS and JavaScript. The content of this blog will be geared towards people who are interested in web development and the intersection between computer science and design. + +### :pushpin: Step 3 +> Outline your learning/teaching structure: + +**Beginning (2-3+ sentences):** +The blog will start by introducing the end goal--adding mouse-click feature to the tiny city project with JavaScript--and the basics of JavaScript. This will allow the viewer to clearly understand what they are adding to the tiny city, how this connects with the prior HTML and CSS code, and how certain functions work in JavaScript. + +**Middle (2-3+ sentences):** +Here, the blog will dive into the coding aspect by first teaching the reader how to setup and save a JavaScript file along with their HTML and CSS files. The blog will continue by walk through each step of the process, providing a definition along with each new term, and show how the reader how to customize their color palettes for the mouse-click interaction. + +**End (2-3+ sentences):** +Now, the blog will show the reader how the JavaScript code connects with the HTML and CSS code, then allow the reader to run and adjust the colors if needed. Since this blog is the last part of the tiny city series, the blog will encourage the reader to continue to build and customize their tiny city and suggest how to learn more about web development and design. + + + +LOOM VIDEO: + +https://www.loom.com/share/0129881d019d4f4cb44075adea6e807a \ No newline at end of file