Skip to content

Commit e30d78b

Browse files
authored
Merge pull request #547 from zoyron/parameter
Added parametric equations' visualisation to 08_Math
2 parents 78b2aa0 + 0d4fe5a commit e30d78b

File tree

3 files changed

+132
-0
lines changed

3 files changed

+132
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* @name Parametric Equations
3+
* @description A parametric equation is where x and y
4+
* coordinates are both written in terms of another letter. This is
5+
* called a parameter and is usually given in the letter t or θ.
6+
* The inspiration was taken from the YouTube channel of Alexander Miller.
7+
*/
8+
9+
function setup(){
10+
createCanvas(720,400);
11+
}
12+
13+
// the parameter at which x and y depends is usually taken as either t or symbol of theta
14+
let t = 0;
15+
function draw(){
16+
background('#fff');
17+
translate(width/2,height/2);
18+
stroke('#0f0f0f');
19+
strokeWeight(1.5);
20+
//loop for adding 100 lines
21+
for(let i = 0;i<100;i++){
22+
line(x1(t+i),y1(t+i),x2(t+i)+20,y2(t+i)+20);
23+
}
24+
t+=0.15;
25+
}
26+
// function to change initial x co-ordinate of the line
27+
function x1(t){
28+
return sin(t/10)*125+sin(t/20)*125+sin(t/30)*125;
29+
}
30+
31+
// function to change initial y co-ordinate of the line
32+
function y1(t){
33+
return cos(t/10)*125+cos(t/20)*125+cos(t/30)*125;
34+
}
35+
36+
// function to change final x co-ordinate of the line
37+
function x2(t){
38+
return sin(t/15)*125+sin(t/25)*125+sin(t/35)*125;
39+
}
40+
41+
// function to change final y co-ordinate of the line
42+
function y2(t){
43+
return cos(t/15)*125+cos(t/25)*125+cos(t/35)*125;
44+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* @name Parametric Equations
3+
* @description A parametric equation is where x and y
4+
* coordinates are both written in terms of another letter. This is
5+
* called a parameter and is usually given in the letter t or θ.
6+
* The inspiration was taken from the YouTube channel of Alexander Miller.
7+
*/
8+
9+
function setup(){
10+
createCanvas(720,400);
11+
}
12+
13+
// the parameter at which x and y depends is usually taken as either t or symbol of theta
14+
let t = 0;
15+
function draw(){
16+
background('#fff');
17+
translate(width/2,height/2);
18+
stroke('#0f0f0f');
19+
strokeWeight(1.5);
20+
//loop for adding 100 lines
21+
for(let i = 0;i<100;i++){
22+
line(x1(t+i),y1(t+i),x2(t+i)+20,y2(t+i)+20);
23+
}
24+
t+=0.15;
25+
}
26+
// function to change initial x co-ordinate of the line
27+
function x1(t){
28+
return sin(t/10)*125+sin(t/20)*125+sin(t/30)*125;
29+
}
30+
31+
// function to change initial y co-ordinate of the line
32+
function y1(t){
33+
return cos(t/10)*125+cos(t/20)*125+cos(t/30)*125;
34+
}
35+
36+
// function to change final x co-ordinate of the line
37+
function x2(t){
38+
return sin(t/15)*125+sin(t/25)*125+sin(t/35)*125;
39+
}
40+
41+
// function to change final y co-ordinate of the line
42+
function y2(t){
43+
return cos(t/15)*125+cos(t/25)*125+cos(t/35)*125;
44+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* @name Parametric Equations
3+
* @description A parametric equation is where x and y
4+
* coordinates are both written in terms of another letter. This is
5+
* called a parameter and is usually given in the letter t or θ.
6+
* The inspiration was taken from the YouTube channel of Alexander Miller.
7+
*/
8+
9+
function setup(){
10+
createCanvas(720,400);
11+
}
12+
13+
// the parameter at which x and y depends is usually taken as either t or symbol of theta
14+
let t = 0;
15+
function draw(){
16+
background('#fff');
17+
translate(width/2,height/2);
18+
stroke('#0f0f0f');
19+
strokeWeight(1.5);
20+
//loop for adding 100 lines
21+
for(let i = 0;i<100;i++){
22+
line(x1(t+i),y1(t+i),x2(t+i)+20,y2(t+i)+20);
23+
}
24+
t+=0.15;
25+
}
26+
// function to change initial x co-ordinate of the line
27+
function x1(t){
28+
return sin(t/10)*125+sin(t/20)*125+sin(t/30)*125;
29+
}
30+
31+
// function to change initial y co-ordinate of the line
32+
function y1(t){
33+
return cos(t/10)*125+cos(t/20)*125+cos(t/30)*125;
34+
}
35+
36+
// function to change final x co-ordinate of the line
37+
function x2(t){
38+
return sin(t/15)*125+sin(t/25)*125+sin(t/35)*125;
39+
}
40+
41+
// function to change final y co-ordinate of the line
42+
function y2(t){
43+
return cos(t/15)*125+cos(t/25)*125+cos(t/35)*125;
44+
}

0 commit comments

Comments
 (0)