HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<canvas id="myCanvas"></canvas>
<header>
<base target="_blank">
<!-- makes all links open in new tab -->
<a name='top'></a>
<ul class="navigation" role="navigation">
<li><a href="#scratch" class="border" target="_self">Scratch</a></li>
<li><a href="#HTML" class="border" target="_self">HTML</a></li>
<li><a href="#CSS" class="border" target="_self">CSS</a></li>
<li><a href="#js" class="border" target="_self">JavaScript</a></li>
<li><a href="#js canvas" class="border" target="_self">Canvas</a></li>
<li><a href="#lib" class="border" target="_self">Libraries</a></li>
<li><a href="#projects" class="border" target="_self">Projects</a></li>
</ul>
</header>
<article>
<!-- <h1 id="titlemain">Computer Science</h1> -->
<svg xmlns="http://www.w3.org/2000/svg" width="600" height="100">
<text class = 'draw-lines' x="300" y="30" stroke = '#222' stroke-width = '3' stroke-linecap="square"
fill = none font-family="Arial Black, Gadget, sans-serif" font-size="58" text-anchor="middle" alignment-baseline="middle">
Computer Science </text>
<text class = 'draw-lines' x="300" y="85" stroke = '#222' stroke-width = '3' stroke-linecap="square"
fill = none font-family="Arial Black, Gadget, sans-serif" font-size="50" text-anchor="middle" alignment-baseline="middle">
fall 2021 </text>
</svg>
<p>In this class we will learn to code by making projects. We start with Scratch, a block based language. Next we will learn how to make web pages with HTML and CSS, followed by JavaScript. Finally,
we will learn how to program Arduino microcontrollers.
</p>
<p>
Computer are provided in the classroom. A computer at home can be helpful for if students want to continue their projects, but it isn't required.
</p>
<p>
This class focuses on project based learning. Students will have a one on one meeting with Mr Landgreen every couple weeks to set individualized goals for their projects. Students will then work to meet the goals and they will get a grade based on how closely they achieve their objectives.
</p>
<p>A = 90%, B = 80%, C = 70%, Pass = 60%, F = Less than 60%</p>
<!-- ******************************* -->
<a name='scratch'></a>
<h1 class="underlined">Scratch</h1>
<div class='task'>
<h2>task - make your first project!</h2>
<p>Make a free account on <a href="https://scratch.mit.edu/">scratch</a>. Play around a bit with the interface. Start your first project.</p>
<p> First Project Ideas:
<br>have the sprit move when you press the arrow keys
<br>have the sprit move randomly and bounce off the walls
<br>try one of the suggested <a href="https://scratch.mit.edu/tips">starter</a> projects
</p>
</div>
<div class='task'>
<h2>task - conditional logic project</h2>
<p>This project must take advantage of some of the more interesting features of a programming language. Design a fun project that uses these required blocks in a meaningful way.</p>
<p> Required blocks:<strong>
<br>variable
<br>if statement
<br>Any loop
</strong>
</p>
</div>
<!-- ******************************* -->
<a name='HTML'></a>
<h1 class="underlined">HTML</h1>
<div class='task'>
<h2>task - learn HTML syntax</h2>
<p> Make an account on <a href='https://www.codecademy.com/'>codecademy</a>.
<br>
<br>Under the unit on language skills
<br>Select <a href='https://www.codecademy.com/learn/learn-html-css'>HTML & CSS</a>.
<br>Complete unit 1: HTML Fundamentals
<br>Complete unit 2: HTML Content
</p>
</div>
<div class='project'>
<h2>project - make a web site</h2>
<p><b>choose a topic:</b> music, TV show, project for another class, game, a guide to ____, cooking, sports teams, your bio, an art gallery, ...
</p>
<p>Make an account on <a href='https://codepen.io/'>codepen</a>.
<br>Make a <b>+ New Pen</b>
<br>In the HTML section start writing a website:
<br>There must be: headings, p, div, br, <a href="https://codepen.io/" target="_blank">links</a>, <b>bold</b>, <i>italics</i>, hidden, ...
<p>Codepen automatically adds html and body elements as hidden and it links your JavaScript, and css pages to the index.html.</p>
<p><a href='https://www.w3schools.com/html/'>W3 Schools</a> is a good reference for syntax.
<p>
</p>
</div>
<div class='info'>
<h2>Resources</h2>
<p> <a href='https://internetingishard.com/html-and-css/'> HTML and CCS guide</a>
<br><a href='http://htmlreference.io/'> HTML Elements Reference</a>
</p>
</div>
<!-- ****************************************** -->
<br>
<a name='CSS'></a>
<h1 class="underlined">CSS</h1>
<div class='task'>
<h2>task - learn CSS syntax</h2>
<p> Return to codecademy and select <a href='https://www.codecademy.com/learn/learn-html-css'>HTML & CSS</a>.
<br>Complete UNIT 3: CSS Fundamentals
<br>Complete UNIT 4: Styling with CSS
<br>Complete UNIT 5: Organizing HTML & CSS
<br>Complete UNIT 6: The CSS Box Model
<br>Complete UNIT 7: CSS Positioning
<br>Complete UNIT 8: Images
<p>Read some web developers <a href='https://css-tricks.com/moment-css-started-making-sense/'>writing</a> about learning CSS.
</p>
</div>
<div class='quiz'>
<h2><a href= "https://docs.google.com/a/newwestcharter.org/forms/d/e/1FAIpQLSeNhnaQNoybCo0PgD-jDBsgH7c_O0e6uJMVpM_7UX2L4PC0BA/viewform" target="_blank">quiz</a> - colors!</h2>
<p>Learn <span style='color: green'>c</span><span style='color: red'>o</span><span style='color: #888'>l</span><span style='color: #991'>o</span><span style='color: pink'>r</span><span style='color: RGB(255,0,255)'>s</span>: <a href='http://htmlcolorcodes.com/'>HTML Color Codes</a>
<br>Learn advanced methods: <a href='https://css-tricks.com/nerds-guide-color-web/' target="_blank">CSS-Tricks</a>.
<br>Be able to tell roughly what color comes from RGB, and HEX codes.
<br>Be able to write the RGB and HEX codes for different colors.
</p>
</div>
<div class='project'>
<h2>project - make your web site pretty</h2>
<p>Return to your web site project on <a href='https://codepen.io/'>codepen</a>.
<br>In the CSS section add in some style
<br>Use: <span style='color: #f0f'>color</span>, <span style='background-color: #cdc'>background-color</span>, <span style='font-family: "Times New Roman", Times, serif;'>font</span>, <span style='padding: 0.2em;border: 1px solid grey;'>padding</span>,
<span style='margin: 0.2em;border: 1px solid grey;'>margin</span>, id, class
<br>Don't use: inline styles (use classes)
<br>It must look nice...
</p>
<p>Read this example of <a href='http://jgthms.com/web-design-in-4-minutes/' target="_blank">styling</a> a page.
</p>
<p><a href='https://www.w3schools.com/css/'>W3 Schools</a> is a good reference for syntax.
<p>
</div>
<div class='project'>
<h2>task - play CSS learning games</h2>
<a href='https://flukeout.github.io/'>CSS diner</a>: learn CSS selectors
<br><a href='http://flexboxfroggy.com/'>Flexbox Froggy</a>: learn flexbox
<br><a href='http://www.flexboxdefense.com/'>Flexbox Defense</a>: learn flexbox
</div>
<!-- ********************************************* -->
<!-- <br>
<a name='hosting'></a>
<h1 class="underlined">Hosting</h1>
<div class='task'>
<h2>task - setup github</h2>
<p>Make an account on <a href='https://github.com/'>github.com</a>
</p>
<p>Follow <a href="https://pages.github.com/">these</a> instructions to make your Gthub account a public website.</p>
<p>Make updates to your Github public website repository as you add to your website.</p>
</div>
<div class='task'>
<h2>task - add a favicon</h2>
<p>Go to <a href='http://www.favicon.cc/'>favicon.cc</a> and make an amazing looking favicon for your site.
</p>
<p>Download and place the favicon.ico file in your website directory
<br>Add this code to the head element of your index.html:
<xmp>
<link rel='shortcut icon' href='location/of/favicon.ico' type='image/x-icon' />
</xmp>
</p>
</div>
<div class='task'>
<h2>task - clean up your HTML head</h2>
<p>Read through the <a href='https://developer.mozilla.org/en-US/Learn/HTML/Introduction_to_HTML/The_head_metadata_in_HTML'>Mozilla head tutorial</a>.
<br>add any missing sections to the head of your index.html.
</p>
</div> -->
<!-- ******************************************* -->
<br>
<a name='js'></a>
<h1 class="underlined">JavaScript</h1>
<div class='task'>
<h2>task - learn JavaScript syntax</h2>
<p>Return to codecademy - Language Skills - <a href='https://www.codecademy.com/learn/learn-javascript'>JavaScript</a>.
<br>Complete the first lesson. <b>INTRODUCTION TO JAVASCRIPT</b>
<br><em>(don't accidently start learning Java, its not the same as JavaScript)</em>
</p>
</div>
<div class='info'>
<h2>info - JavaScript reference</h2>
<a href='https://www.w3schools.com/js/'>W3 school JS</a>: tutorials and syntax
<br><a href='https://developer.mozilla.org/en-US/docs/Web/JavaScript'>Mozilla Developer Network</a>: advanced tutorials and syntax
<br><a href='http://eloquentjavascript.net/'>Eloquent JavaScript</a>: online text book
<br><a href='https://github.com/getify/You-Dont-Know-JS'>You Don't Know JS</a>: online text books
</div>
<div class='project'>
<h2>project - start your own JavaScript program</h2>
<p>Build your own creative JavaScript project
<br><strong>or</strong> expand on one of my project ideas below
<br><strong>or</strong> try some <a href="https://enlight.ml/">templates</a> out
<br><strong>or</strong> take a look at this extensive list of <a href='http://rosettacode.org/wiki/Category:Programming_Tasks'>programming tasks</a>.
</p>
</div>
<div class='info'>
<h2>info - console / DevTools</h2>
<p>Web development tools allow web developers to test and debug their code. They are different from website builders and IDEs in that they do not assist in the direct creation of a webpage, rather they are tools used for testing the user facing interface
of a website or web application.
</p>
<p>Error messages and console.log("message") show up in the console. It can be accessed on chrome through the DevTools. To get to the <a href='https://developers.google.com/web/tools/chrome-devtools/'>DevTools</a> in chrome right-click on the background
of a site and choose inspect. You can try it right now on this site, I'll wait...</p>
</div>
<div class='project'>
<h2>project - JavaScript challenges</h2>
<p>Fork the <a href='https://codepen.io/lilgreenland/pen/xVOdPM?editors=0010'>JavaScript challenges</a>. Add your own code to solve the problems in the comments.</p>
</div>
<div class='project'>
<h2>project - random name generator</h2>
<p>Make a new codepen that outputs random names. Follow these <a href='https://codepen.io/lilgreenland/pen/KzOjjd?editors=1010'>instructions</a>.</p>
</div>
<div class='project'>
<h2>project - make a chatbot</h2>
<p>Fork the <a href='https://codepen.io/lilgreenland/pen/pyVvqB?editors=0010'>chatbot template</a>. Edit the chatbotResponse() function to make the bot chat.</p>
</div>
<div class='info'>
<h2>info - Integrated Development Environment (IDE)</h2>
<p>JavaScript can be produced in a basic text editor, but it is faster to use an application dedicated to programming.</p>
<p><strong>In Browser:</strong>
<br><a href='https://codepen.io/'>Codepen</a>: combines HTML, CSS, and JS with a strong community
<br><a href='https://repl.it/'>repl.it</a>: simple: works for most languages
</p>
<p><strong>Text Editors:</strong>
<br><a href='https://code.visualstudio.com/'>VS Code</a>: free, fast, powerful
<br><a href='https://www.sublimetext.com/'>Sublime</a>: fast, simple
<br><a href='https://atom.io/'>Atom</a>: customizable, open source, free
</p>
</div>
<div class='project'>
<h2>project - use a public API</h2>
<p>An API is an "Application Programming Interface". It is a way for your website to get data from a server. </p>
<a href='https://codepen.io/lilgreenland/pen/EWGoQK?editors=0010'>How to use a public JSON API</a>
<br><a href='https://codepen.io/lilgreenland/pen/mmJNJr?editors=0010'>Example project</a>.
<p>Build a website that pulls data from a public API. In addition to the API query, the project needs to have a web interface for the query and the outputted data.</p>
</div>
<!-- ******************************************* -->
<br>
<a name='js canvas'></a>
<h1 class="underlined">Canvas</h1>
<div class='info'>
<h2>info - canvas</h2>
<p>Canvas is a html5 element that lets you draw in the browser. You can make graphics, games, interfaces, animations, whatever.</p>
<p><a href="https://www.w3schools.com/tags/ref_canvas.asp">canvas reference</a>: w3 schools
<br><a href="https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API">canvas tutorials</a>: Mozilla Developer Network
<br>
<br><a href="https://codepen.io/lilgreenland/pen/zKVXxo?editors=0010">canvas template</a>: starter code for a canvas with inputs and animation loop
<br><a href="https://codepen.io/lilgreenland/pen/zoZNVX?editors=0010">canvas template (full screen)</a>: same, but the canvas fills the page.
</p>
</div>
<div class='project'>
<h2>project - draw a <a href="https://www.google.com/search?q=flags&rlz=1C1CHFX_enUS532US532&source=lnms&tbm=isch&sa=X&ved=0ahUKEwjv_7ns0YLQAhUqq1QKHXyjDh8Q_AUICCgB&biw=1396&bih=725">flag</a> on canvas</h2>
</div>
<div class='project'>
<h2>project - make an animation</h2>
<p>Use <a href="https://css-tricks.com/using-requestanimationframe/">requestAnimationFrame()</a> to make things move.
</p>
</div>
<div class='info'>
<h2>info - inputs</h2>
<p><a href="https://www.w3schools.com/tags/ref_canvas.asp">mouse events</a>: w3 schools guide
<br><a href="https://codepen.io/lilgreenland/pen/XXamaQ?editors=0010">mouse coordinates</a>: codepen example
<br><a href="https://css-tricks.com/snippets/javascript/javascript-keycodes/">keyboard keycodes</a>: the standard value for each key
</p>
</div>
<div class='project'>
<h2>project - make a game</h2>
<p><a href='https://www.w3schools.com/graphics/game_intro.asp'>game example</a> W3 Schools.
</p>
<p>top view, side view, something else?
<br>what are the controls?
<br>what is the goal?
<br>object oriented?
</p>
</div>
<div class='project'>
<h2>project - make art</h2>
<p>
<a href='https://generativeartistry.com/'>generative artistry</a>: js art tutorials
</p>
</div>
<!-- ******************************************* -->
<!-- <br>
<a name='mobile'></a>
<h1 class="underlined">Mobile</h1>
<div class='info'>
<h2>info - mobile</h2>
<p class='listoflinks'><a href="https://codepen.io/collection/XkEeQP/">Examples: from Landgreen's codepen</a>
<br><a href="https://css-tricks.com/snippets/css/a-guide-to-flexbox/">Flexbox</a>: tutorial
<br><a href='http://www.flexboxpatterns.com/home'>Flexbox Patterns</a>: learn flexbox
<br><a href="https://bradfrost.github.io/this-is-responsive/patterns.html">Responsive Design</a>: Examples
<br><a href="https://developer.mozilla.org/en-US/docs/Web/API/Detecting_device_orientation">Detecting device orientation</a>
<br><a href="https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/Using_geolocation">Geolocation</a>
</p>
</div> -->
<!-- ******************************************* -->
<br>
<a name='lib'></a>
<h1 class="underlined">Libraries</h1>
<div class='info'>
<h2>info - library ideas</h2>
<p class="listoflinks">
<a href="https://github.com/davidmerfield/randomColor">RandomColor.js</a>: pretty colors - (easy)
<br><a href="http://qrohlf.com/trianglify/#gettingstarted"> Trianglify</a>: triangle art - (easy)
<br><a href="https://github.com/mrdoob/stats.js/">stats.js</a>: frames per second tracker - (easy)
<br><a href="http://www.chartjs.org/">Chart.js</a>: charts in canvas (<a href="https://codepen.io/lilgreenland/pen/OXbbVR">example</a>) - (medium)
<br><a href="https://workshop.chromeexperiments.com/examples/gui/#1--Basic-Usage">dat.GUI</a>: graphical user interface (<a href="https://codepen.io/lilgreenland/pen/LNjJpr">example</a>) - (medium)
<br><a href="https://github.com/jdan/isomer">isomer.js</a>: Isometric graphics for canvas - (medium)
<br><a href="https://tonejs.github.io/">Tone.js</a>: make music (<a href="https://codepen.io/lilgreenland/pen/bvPQyy">example</a>) - (hard)
<br><a href="http://brm.io/matter-js/">Matter.js</a>: physics engine (<a href="https://codepen.io/collection/Fuagy/">example</a>) - (hard)
<br><a href="https://vuejs.org/">Vue.js</a>: user interface framework - (hard)
<br><a href="https://threejs.org/">three.js </a>: 3-d graphics (<a href="https://codepen.io/lilgreenland/pen/RVpBjr">example</a>) - (hard)
<br>
<br><a href="https://www.javascripting.com/">JavaScripting</a>: list of popular js libraries
</p>
</div>
<!-- ******************************************* -->
<br>
<a name='projects'></a>
<h1 class="underlined">Projects</h1>
<table>
<tr>
<th>Project</th>
<th>Skills</th>
<th>Notes</th>
</tr>
<tr>
<td>Your first project</td>
<td>Scratch</td>
<td></td>
</tr>
<tr>
<td>conditional logic project</td>
<td>Scratch</td>
<td></td>
</tr>
<tr>
<td>Make a website</td>
<td>HTML</td>
<td></td>
</tr>
<tr>
<td>Add CSS to the website</td>
<td>CSS</td>
<td></td>
</tr>
<tr>
<td>Make a simple JavaScript program</td>
<td>JS</td>
<td></td>
</tr>
<tr>
<td>Solve JavaScript challenges</td>
<td>JS</td>
<td></td>
</tr>
<tr>
<td>Random name generator</td>
<td>JS</td>
<td></td>
</tr>
<tr>
<td>Make a chatbot</td>
<td>HTML CSS JS</td>
<td></td>
</tr>
<tr>
<td>Draw a flag on canvas</td>
<td>JS canvas</td>
<td></td>
</tr>
<tr>
<td>Make an animation</td>
<td>JS canvas</td>
<td></td>
</tr>
<tr>
<td>Make a game</td>
<td>JS canvas inputs</td>
<td></td>
</tr>
<tr>
<td>Make a project with a library</td>
<td>HTML CSS JS</td>
<td></td>
</tr>
<tr>
<td>Make a project with an API</td>
<td>HTML CSS JS API</td>
<td></td>
</tr>
<tr>
<td>Arduino kits</td>
<td>C
</td>
<td></td>
</tr>
</table>
</article>
/************Reset**************/
* {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}a
html,
body,
div,
object,
iframe,
fieldset {
margin: 0;
padding: 0;
border: 0;
}
ol,
ul {
list-style: none;
margin: 0;
padding: 0;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
header,
footer,
nav,
section,
article,
hgroup,
figure {
display: block;
}
legend {
display: none;
}
svg:not(:root) {
overflow: hidden;
}
/************End Reset**************/
/*global elements______________*/
body {
font-family: "Arial", sans-serif;
font-size: 110%;
background-color: #fff;
/* background-color: #d0f4f8; */
color: #222;
margin: 0;
/* padding: 0em 1em 2em 1em; */
}
article {
/* background-color: #fff; */
/* border-radius: 20px; */
/* padding: 1.0em; */
margin: 0 auto;
max-width: 600px;
line-height: 1.6;
}
header {
margin: 0 auto;
max-width: 750px;
}
a {
text-decoration: none;
color: #f16;
}
a:hover {
text-decoration: underline;
}
hr {
border: 0;
border-bottom: 3px solid #222;
}
h1,
h2,
h3 {
font-weight: 400;
}
::selection {
color: white;
background: #f16;
}
canvas {
position: fixed;
left: 0;
top: 0;
z-index: -1;
}
table {
margin: 25px auto;
border-collapse: collapse;
border: 1px solid #eee;
/*border-bottom: 2px solid #222;*/
width: 100%;
}
table tr:hover {
background: #f4f4f4;
}
table tr:hover td {
color: #555;
}
table th, table td {
color: #777;
border: 1px solid #eee;
padding: 12px 20px;
border-collapse: collapse;
}
table th {
background: #444;
color: #fff;
text-transform: uppercase;
font-size: 0.85em;
}
table th.last {
border-right: none;
}
/*classes_______________________*/
.underlined {
/* font-family: "Arial Black", Gadget, sans-serif; */
border-bottom: 3px solid #222;
font-size: 210%;
/* letter-spacing: 0.2em; */
/* text-align: center; */
}
.center{
text-align: center;
}
.task,
.info,
.project,
.quiz {
background-color: #fff;
padding: 0em 1em 0em 1em;
border-radius: 10px;
margin: 0em 0em 1em 0em;
border: 1px solid #bbb;
}
#titlemain {
font-size: 400%;
font-weight: 600;
text-align: center;
letter-spacing: -0.1em;
margin: 0em 0em 0em 0em;
}
.title2 {
/* color: #ddd; */
text-align: center;
font-size: 140%;
/* letter-spacing: 0.2em; */
margin: -0.5em 0em 0.5em 0em;
}
.shadow{
text-shadow: 3px 3px 4px rgba(0, 0, 0, 0.3);
}
.listoflinks {
line-height: 2;
}
/* navigation bar____________________________ */
.navigation {
/* background-color: #f7f7f7; */
margin: 0em -1em;
list-style: none;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-flex-flow: row wrap;
justify-content: space-around;
}
.navigation li a {
font-weight: bold;
display: block;
padding: 0;
margin: 1em;
font-size: 1em;
/* letter-spacing: 0.2em; */
}
.navigation li a:hover {
text-decoration: none;
}
/*the element for underlines on the navbar */
.border {
position: relative;
}
.border:hover::after {
content: '';
position: absolute;
width: 100%;
height: 0;
left: 0;
bottom: -5px;
/*Change this to increase/decrease distance*/
border-bottom: 5px solid #f16;
}
.draw-lines {
stroke-dasharray: 260;
stroke-dashoffset: 260;
animation: dash 5s ease-in forwards;
/* animation: dash 4s ease-in alternate infinite; */
}
@keyframes dash {
to {
stroke-dashoffset: 0;
}
}
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
(function canvasSetup(){
ctx.canvas.width = window.innerWidth;
ctx.canvas.height = window.innerHeight;
ctx.globalCompositeOperation = 'lighter';
})();
window.onresize = function() {
canvasSetup();
};
var addStar = 0;
var stars = [];
var totalStars = 0; // spawns stars at start
var mousePos = {
x: canvas.width * 0.5,
y: canvas.height * 0.5
};
var friction = 0.996
//adds a new star objects to array stars
function pushStar() {
stars.push({
x: mousePos.x + 20 * (Math.random() - 0.5),
y: mousePos.y + 20 * (Math.random() - 0.5),
Vx: 0,
Vy: 0,
r: 35 * Math.random() + 3, //random size
color: '#' + Math.floor(Math.random() * 16777216).toString(16) //random hexadecimal color
});
}
//spawns stars
for (var i = 0; i < totalStars; i++) {
pushStar();
}
//push away if mouse down
document.addEventListener("mousedown", function() {
addStar = 1;
for (var i = 0; i < stars.length; i++) {
stars[i].Vx += 3 * Math.cos(Math.atan2(stars[i].y - mousePos.y, stars[i].x - mousePos.x));
stars[i].Vy += 3 * Math.sin(Math.atan2(stars[i].y - mousePos.y, stars[i].x - mousePos.x));
}
});
// waits for mouse move and then updates position
document.addEventListener('mousemove', function(evt) {
mousePos = {
x: evt.clientX,
y: evt.clientY
};
}, false);
//recursive draw function
function draw() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
for (var i = 0; i < stars.length; i++) {
//draw a circle
ctx.beginPath();
ctx.arc(stars[i].x, stars[i].y, stars[i].r, 0, 2 * Math.PI, true);
ctx.fillStyle = stars[i].color;
ctx.fill();
//bounce off walls
if (stars[i].x > canvas.width - stars[i].r) {
stars[i].Vx *= -friction;
stars[i].x = canvas.width - stars[i].r;
} else if (stars[i].x < stars[i].r) {
stars[i].Vx *= -friction;
stars[i].x = stars[i].r;
}
if (stars[i].y > canvas.height - stars[i].r) {
stars[i].Vy *= -friction;
stars[i].y = canvas.height - stars[i].r;
} else if (stars[i].y < stars[i].r) {
stars[i].Vy *= -friction;
stars[i].y = stars[i].r;
}
// attraction to the mouse
stars[i].Vx += -0.03 * Math.cos(Math.atan2(stars[i].y - mousePos.y, stars[i].x - mousePos.x));
stars[i].Vy += -0.03 * Math.sin(Math.atan2(stars[i].y - mousePos.y, stars[i].x - mousePos.x));
//change position, velocity, size of object elements for each location in array
stars[i].x += stars[i].Vx;
stars[i].y += stars[i].Vy;
//friction slows velocity
stars[i].Vx *= friction;
stars[i].Vy *= friction;
}
if (addStar == 1) {
pushStar();
addStar = 0;
} else if (addStar == -1) {
stars = [];
}
requestAnimationFrame(draw);
}
requestAnimationFrame(draw);
Also see: Tab Triggers