Computer science is the study of information processes. A process is a sequence of steps. Each step changes the state of the world in some way.
To program computers, we need tools that allow us to describe processes precisely and succintly. Since the procedures are carried out by a machine, every step needs to be described completely. Because the computer cannot "think," we need mechanical procedures that can be followed without any thinking.
A programming language is a formal language designed to communicate instructions to a machine, particularly a computer. These languages provide a set of rules and syntax that allow programmers to create sequences of instructions that the computer can execute. Think of a programming language as a specialized language that bridges the gap between human-readable instructions and the machine-readable code that computers can understand. By using a programming language, we can precisely define the steps involved in a process, ensuring that the computer carries out the instructions correctly and consistently.
There are many programming languages out there. C, C++, C#, Python, Java, Rust, Haskell are just a few examples of the many different languages in use today. When you are starting your journey into computer programming, I think most languages are a fine place to start. For this class, we will be using the language called Javascript.
I am choosing Javascript for this class for a few reasons. One, the instructions you write in Javascript are supported basically by all modern web browsers, making it easy for you to distribute and share your work with others. Two, since it is so widely used on the web, you will gain a highly practical skill if you want to pursue CS further as a career.
The third reason is because I want to use the p5.js programming library. What is p5.js? p5.js is a JavaScript library that simplifies the process of creating interactive graphics and animations. It's designed with artists, designers, and beginners in mind, making it easy to learn and use. I want us to be able to visually see the results of our computer programs. This makes the activity more artful and gives us more feedback on our code-writing.
To write our computer programs, I want us to use a text-editing program that understands the code we are writing. One of the main benefits of this is that it will color the text we write so that it makes it easier to understand. The program I want us to use is called Visual Studio Code by Microsoft. Please download it onto your computer and install it.
Afterwards, open VS Code and install the "Live Preview" extension, and the "p5.vscode" extension. Use the p5.vscode extension to create a starter project. Open the index.html file that it gives you and press the Live Preview button to get live feedback on your coding.
function setup() {
createCanvas(400, 300)
background(100, 100, 200);
}
function draw() {
stroke(0);
fill(130, 255, 100);
circle(300, 100, 50);
fill(255, 0, 0);
rect(50, 220, 300, 50);
stroke(0,0,255);
line(30, 180, 240, 70);
}
// I declare the variable t here.
// This is what I am using to hold my "time"
let t = 0;
function setup() {
createCanvas(400, 300);
background(100);
};
function draw() {
background(100);
// This circle moves forward with time
circle(t, 100, 50);
// This circle moves back and forth because of the sine function
circle(
100 * Math.sin(t * 0.1) + 200,
180,
50
);
// This circle will follow the mouse,
// using the special variables mouseX and mouseY
circle(
mouseX,
mouseY,
50
);
// This circle will appear in the middle of the screen
circle(
width/2,
height/2,
25
);
// This variable increments up by 1 at every frame drawn
// This is how I am implementing the idea of "time" in my sketch
t += 1;
};
let xvel = Math.random() * 5;
let yvel = Math.random() * 5;
let xpos = 100;
let ypos = 100;
function setup() {
createCanvas(400, 300);
background(50,150,250);
}
function draw() {
background(50,150,250);
circle(xpos, ypos, 50);
text("DVD", xpos - 12, ypos - 3);
text("VIDEO", xpos - 18, ypos + 9);
xpos = xpos + xvel;
ypos = ypos + yvel;
if (xpos > width - 25) {
xvel = -xvel;
}
if (xpos < 25) {
xvel = -xvel;
}
if (ypos > height - 25) {
yvel = -yvel;
}
if (ypos < 25) {
yvel = -yvel;
}
}
function setup() {
createCanvas(400, 300);
background(100, 100, 200);
}
function draw() {
colorMode(RGB);
background(0,0,0,10);
colorMode(RGB);
stroke(255,255,0);
fill(255, 100, 100);
square(10, 10, 30);
colorMode(HSB);
stroke(255,255,0);
fill(255, 100, 100);
square(10, 10 + 40, 30);
colorMode(RGB);
stroke(255,255,0);
noFill();
square(10, 10 + 100, 30);
noStroke();
fill(255,255,0);
square(10, 10 + 140, 30);
strokeWeight(mouseY / 20)
stroke(255,255,0);
noFill();
square(10, 10 + 230, 30);
// The HSB color mode lets me easily range over all hues
colorMode(HSB);
stroke(
(atan2(mouseX - width/2, mouseY - height/2) + PI) / (2*PI) * 360,
255,
255,
);
strokeWeight(2)
line(width/2, height/2, mouseX, mouseY);
}