Skip to content

Latest commit

 

History

History
335 lines (207 loc) · 7.85 KB

File metadata and controls

335 lines (207 loc) · 7.85 KB

ACS 1320 - Lesson 1 - JavaScript Basics

Class Learning Objectives

The goal of this class is to improve and develop your JavaScript skill, knowledge, and to further develop your skills in software development.

By the end of the class you should be able to:

  • Use functions and variables
  • Write for loops in JavaScript
  • Write if statements in JavaScript
  • Use Canvas to draw bitmap graphics
  • Describe program flow

Your Goals ⭐️

These are the two goals that will bring you success.

  • Building Portfolio Projects 🖼
  • Master Learning Objectives 🧠

Portfolio projects 🖼 are what get you noticed 👁. Your portfolio is often the reason people get invited to job interviews 🤝.

What are Learning Objectives?

Learning objectives are the concepts and ideas that you need to know to claim mastery of a subject. 🏫

Learning Objectives are often skills that are related to success at job interviews and on the job. 😎

When you understand a learning objective you will be able to explain it and put it into practice.

There will be learning objectives for each class. You should test your knowledge by explaining the concepts to someone else. 🤼‍♀️

If you are having trouble understanding a learning objective you need to take action.

  1. Discuss the topic with another student
  2. Talk with a TA
  3. Bring questions to class
  4. Talk to an instructor during lab or office hours.

Projects

The goal is to produce something that shows your skills.

  • Breakout - This is a JavaScript implementation of the arcade game Breakout
  • React Fundamentals Tutorial - This tutorial will get you started with React
  • Custom/Contractor Project with React - This will be a website built with React and is open to your ideas and input.

Start Breakout tutorial

The Breakout tutorial is a great JS practice project. It makes use of many of the core concepts found in every programming language.

  • Variables
  • Functions
  • Flow control
    • loops
    • if else
  • Arrays
  • Objects

After completing the tutorial you will improve the code by applying modern techniques and best practices. This will include:

  • Using ES6 JS ideas and syntax
  • Linting to professional standards
  • Using build systems and bundling

Contractor/Custom project

The Custom/Contractor project will be built with React.

Here you will put all of the things from the first project into something that is built using one of the most common and popular libraries in use today.

Break Out 🧱

  • What is Breakout?
  • How does the tutorial game work?
    • Draws with canvas
    • Use cartesian coordinates?

Breakout was invented by Atari in 1976!

atari-breakout

It looked like this.

Canvas

Canvas is a JS API that allows you to draw bitmapped graphics. Use it to draw pictures. It's good for games.

Canvas is a tag:

<canvas id="myCanvas"></canvas>

Think of canvas as the <img> tag with the ability to draw on it.

Like the <img> tag you should give <canvas> width and height.

<canvas id="myCanvas" width="480" height="320"></canvas>

Your game will look like this:

Breakout-0

You will draw your game on Canvas with JS.

Canvas allows you to draw shapes into a rectangular area.

Canvas is mapped in cartesian coordinates.

Breakout-1

Canvas is mapped in cartesian coordinates.

Breakout-2

You'll draw the ball from the center:

Breakout-3

You'll draw the rectangles from the upper left corner:

Breakout-4

To draw on canvas you need to get a canvas context.

const canvas = document.getElementById("myCanvas");
const ctx = canvas.getContext("2d");

ctx is the canvas context. You'll call on methods of this object to draw on the canvas.

  • Q: What's a method?
  • Q: What's an Object?

Draw on your canvas using the canvas API. The tutorial uses a few of the APIs methods.

Drawing with canvas generally follows these steps:

  1. begin a new path
  2. draw a shape with one of the drawing methods
  3. set the fill style
  4. set the stroke style
  5. fill and stroke your path

Here are a few examples...

Draw a rectangle

ctx.beginPath() // begins a new path
ctx.rect(x, y, width, height) // draws a rectangular path
ctx.fillStyle = "#0095DD" // sets the fill color
ctx.closePath() // closes the path
ctx.fill() // fills the current path
  • Q: How big is the rectangle?
  • Q: Where is it in the canvas?

Draw a circle

ctx.beginPath()
ctx.arc(x, y, radius, startAngle, endAngle)
ctx.fillStyle = "#0095DD"
ctx.fill()
ctx.closePath()
  • Q: How big is the circle?
  • Q: Where is the circle?
  • Q: What color is the circle?

Clear Rectangle

ctx.clearRect(x, y, width, height)
  • Q: What area of the screen is being cleared?

Million Dollar Homepage! Canvas Practice.

https://github.com/soggybag/canvas-practice -->

Break

Take a 10-minute break and measure the world in pixels.

Lab 60 mins

Start working on assignment 1 here.

This tutorial is 10 pages. At the end of every page is the completed source code. If you run into any problems you can check your code against the source.

While you work look for the things on this list:

  • Variables
  • Functions
  • Flow control
    • loops
    • if else
  • Arrays
  • Objects

Today in class your job is to start on the tutorial and identify the things on this list

The code in the tutorial is very naive. You will be updating the code to modern standards in the next assignment.

Come back to class at: ...

Review Breakout

  • Show progress
  • Review Objectives
  • Questions

Homework: Breakout Tutorial

Follow the instructions here

Additional Resources

  1. Types and Values
  2. Variables
  3. Defining functions
  4. Scope
  5. Arrays and Objects
  6. If else
  7. For loops
  8. Canvas