Programming Notes
Programming Notes
Table of Contents
Part 1: Intro to Programming
Chapter 1: Making drawings with code
2 Lessons
3 Tips
Learn how to make shapes with code
Chapter 2: Coloring
2 Lessons
1 Tip
Learn how to color shapes and backgrounds with code.
Chapter 3: Variables
2 Lessons
1 Review
Learn to apply variables to your code
Lines:
Use: To draw lines
Lines have 4 parameters
1st and 2nd parameter control starting point of the line
3rd and 4th parameter control ending point of the line
Things to remember:
Tip 2: Comments
Single line comments always start with two slashes (//) then a bit of text to help
humans understand what the code does,
but Multi-line comments start with "/*" and end with "*/".
Chapter 2: Coloring
Lesson 1: Coloring with code
Stroke
Use: Changes the color of the outline and turns noStroke off.
Stroke has 3 parameter
RGB
1st parameter controlls how red the color is (R)
2nd parameter controlls how green the color is (G)
3rd parameter controlls how blue the color is (B)
noStroke
Use: Turns off outlines entirely for a shape(must be before all command you want to
have no outline)
Chapter 3: Variables
Lesson 1: Intro to variables
Variable
Use: To change two or more parameter with just changing one number.
How to make variables: Type "var", space then name of the variable(it should
describe the variable will hold) equal sign then the parameter.
Equal sign means assignment. That means the parameter will be assigned to the
name of the variable.
If youcome across a equal sign say gets instead of equals.
Remember: Variable must be defined before being used.
// face
fill(255, 255, 0);
ellipse(x, 208, 300, 300);
// eyes
fill(46, 46, 41);
ellipse(x - 50, 151, eyeSize, eyeSize);
ellipse(x + 100, 142, eyeSize, eyeSize);
// mouth
fill(252, 65, 65);
ellipse(x + 50, 240, 120, 136);
Review: Variables
A variable is a way to store values. To use a variable, we must both declare it—to
let the program know about the variable—and then assign it—to let the program know
what value we are storing in the variable.
Here's how we would declare a variable named "xPos":
var xPos;
xPos = 10;
If we want to—and we often do!—we can declare and assign in one statement:
var xPos = 10;
If, for some reason, we want to change the value of a variable later, we can re-
assign it:
We'll soon see why re-assignment can be useful when we want to animate our
drawings.
How can we pick names for our variables? For variables in JavaScript, follow these
rules:
Variable names can begin with letters, or the symbols $ or _. They can only contain
letters, numbers, $ and _.
They cannot begin with a number. "myVariable", "leaf_1", and "$money3" are all
examples of valid variable names.
Variable names are case sensitive, which means that "xPos" is different from
"xpos", so make sure you are consistent.
Variable names can't be the same as existing variable names, and there are a lot in
our ProcessingJS programming environment.
If you ever see an error pop up like "Read only!", try changing your variable name.
Variable names should be clear and meaningful; for example, instead of "ts", use
"toothSize".
Variable names should use camel case for multiple words, like "toothSize" instead
of "toothsize" or "tooth_size".