# Stardust

Under Construction

How would you draw a meteor shower on a computer?

## $\lambda$ Domain and Range

Have you ever looked up at a sky full of stars? If you can find a spot free of light pollution you may even be able to observe our galaxy in all its splendor. The sight is truly awesome and it raises some big questions.

Are we alone in the cosmos? Will we ever travel to another star system? And just how full is the sky, anyway? Let’s start with that last one.

### Discrete

You’ve probably drawn countless graphs in math classes over the years. About the simplest thing you could draw is a single, solitary point like the one below.

How much of the graph does the point take up? Certainly not much. To be precise, the point only takes up, well, a single point. Looking from left to right, it appears the $x$-values, or domain, of the graph is just $\{2\}$. The $y$-values, or range, is just $\{6\}$.

Let’s expand the graph a little.

It appears our domain and range have both grown! The domain is now $\{2, 4\}$ and the range is $\{6, 7\}$. Graphs that are comprised of collections, or sets, of individual points are known as discrete graphs.

What happens when we connect the dots?

### Continuous

The graph below connects the points $(2, 6)$ and $(4, 7)$ with a straight line.

If you zoom in and move from left to right, you would find that the graph is filled in somewhere at every $x$-value between $2$ and $4$. You could do the same from top to bottom. When a graph’s domain and range take on every value in a given interval, we say it is continuous. In this case, the domain is $2 \leq x \leq 4$ and the range is $6 \leq y \leq 7$.

### Constellation

The sky is full of more stars than you could hope to count. Take a walk outside tonight and try to spot a constellation.

How would you describe the constellation’s position? You might start by saying, “Well, it’s in the sky over there, and I know the stars are really in outer space.”

A mathematician would look at the situation and say something like, “I know the photons from those stars just arrived at my eye after traveling for a long time. From my perspective, the stars appear to be arranged in such-and-such shape. I bet I could describe each star’s position precisely—let me get a pencil.”

The sketch below gives an example of drawing the Orion’s Belt. The statement let x = 5; declares that you’d like to use a variable named x and assign it the value $5$.

Protip: Good variable names can make it much easier to understand what’s happening in your code.

function setup() {
createCanvas(400, 400);
}

function draw() {
background(0);
stroke(255);

let alnitakX = 100;
let alnitakY = 250;
let alnilamX = 200;
let alnilamY = 175;
let mintakaX = 300;
let mintakaY = 100;

strokeWeight(5);
point(alnitakX, alnitakY);
point(alnilamX, alnilamY);
point(mintakaX, mintakaY);

strokeWeight(1);
// look up "line" in the p5.js reference
line(alnitakX, alnitakY, alnilamX, alnilamY);
line(alnilamX, alnilamY, mintakaX, mintakaY);
}


Map out your own constellation on paper then in code. Research the proper names of the stars or come up with new ones.

### Domain and Range Review

What are the domain and range of the stars in your constellation? How about when you connect them?

## Variables

Take another walk outside tomorrow afternoon. Depending on your location and the weather, you may enjoy the sunshine on your face. Close your eyes and compare the feeling with the previous evening.

With some exceptions, you’d probably notice it’s cooler at night than in the daytime. Our sensations of heat and cold depend primarily on the temperature of the air, how much radiation we absorb from the sun, and the wind.

But why male models?

— Derek Zoolander

A mathematician would look at the situation and develop a general description, or model. She would say something like the following: “My sensation of heat changes and it depends on temperature, radiation, and wind.”

### Mathematics

Sensations and other quantities that change are known as variables. You may be acquainted with variables like $x$ and $y$ from solving equations or graphing points and lines. Try to think of variables as containers, or buckets, or boxes—as you prefer. The big idea is that they hold values that can change, or vary.

Math students often have trouble distinguishing between variables and the values they represent. $x$ may represent the number $5$ at a particular point along the graph of a line, so it’s easy to conclude (incorrectly) that $x=5$, now and always.

In our model of sensation, heat is dependent upon the values of three variables that are independent, or taken as an input to the model. A mathematician would represent the heat model as a function using notation like $h(t, r, w)$.

### Computation

At some point, you may have been asked to read a brief scenario and make up, or formulate, a model.

Perhaps you were in science class and formulated a model like $d(v,t)=vt$ describing an object’s displacement with respect to velocity and time. If you ran in a straight line at $5$ meters per second for $10$ seconds, you would find yourself $5\times10=50$ meters away from your starting position.

You could define the corresponding function in JavaScript like so.

function d(v, t) {
return v*t;
}


v and t are part of our function definition, called parameters. If we called d(5, 10) somewhere in the sketch, the argument $5$ would be assigned to the parameter v and $10$ would be assigned to the parameter t.

Parameters don’t change; the arguments we assign to them do.

The following sketch of a meteor declares the variable x and assigns it the value $0$. This statement is like asking JavaScript to create a new box labelled “x” and put a $0$ in it to start.

x is increased, or incremented, by $1$ when draw() executes. You could imagine this statement as taking the value held in the “x” box, adding $1$ to it, and putting the new value back in the box.

The print() function is used to keep a running log of the current value of x.

Protip: Printing values is a useful technique for debugging.

// Variables you declare up here can be used
// throughout the sketch.
let x = 0;

function setup() {
createCanvas(400, 400);
}

function draw() {
background(0, 25);
stroke(255);
fill(255);

print(x);

x += 1;
let y = 200;
circle(x, y, 10);
}


Look up fill() and circle() in the p5.js reference.

### Variables Review

What are variables? Describe how they relate to arguments and parameters.

## $\lambda$ Linear Functions

The meteor’s trajectory is a little flat at the moment. It’d be neat to give it give it some sort of orientation. Looking back at our code, the variable y seems to be held constant. Let’s tweak that.

### Functions

// Variables you declare up here can be used
// throughout the sketch.
let x = 0;

function setup() {
createCanvas(400, 400);
}

function draw() {
background(0, 25);
stroke(255);
fill(255);

print(x);

x += 1;
circle(x, f(x), 10);
}

function f(x) {
return 2 * x + 100;
}


## Project Ideas

Extension Add another meteor (or two).

Animation Make the meteor glow red as it enters the atmosphere.