User:Tigerbw/Asymptote/graphing: Difference between revisions
Created page with "{{User:Tigerbw/Templates/header}} So basically, I was bored one day, and I wanted to do some stuff so I went to Desmos. I got bored again, so I thought to make Desmos in asymp..." |
|||
| (7 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
{{User:Tigerbw/Templates/header}} | {{User:Tigerbw/Templates/header}} | ||
So basically, I was | ====Graphing==== | ||
So basically, I was mewing one day, and I wanted to do some stuff so I went to Desmos. I got back to mewing again, so I thought to make Desmos in asymptote. This is what I got | |||
<asy> | <asy> | ||
real resolution, x_left, x_right, g_x_left, g_x_right, y_down, y_up; | real resolution, x_left, x_right, g_x_left, g_x_right, y_down, y_up; | ||
resolution = 0. | resolution = 0.001; | ||
x_left = -8; | x_left = -8; | ||
x_right = 8; | x_right = 8; | ||
| Line 25: | Line 26: | ||
} | } | ||
real f(real x){ | real f(real x){ // equation to graph | ||
return | if (x!=0) { // check for impossible case | ||
return 1/x; | |||
} | |||
else{ | |||
return y_up+1; | |||
} | |||
} | } | ||
| Line 33: | Line 39: | ||
bool prev = false; | bool prev = false; | ||
for (real i = g_x_left; i<=g_x_right; i+= resolution){ | for (real i = g_x_left; i<=g_x_right; i+= resolution){ | ||
if (f(i)<y_up && f(i) > y_down){ | |||
if (prev == true){ | |||
draw((i, f(i))--(i-resolution, f(i-resolution)), graph_pen); | |||
} | |||
prev = true; | |||
} | |||
else{ | |||
prev = false; | |||
} | |||
} | } | ||
} | } | ||
| Line 48: | Line 54: | ||
dotgraph(); | dotgraph(); | ||
</asy> | </asy> | ||
==Source Code== | |||
<syntaxhighlight lang="Asymptote" line> | <syntaxhighlight lang="Asymptote" line> | ||
/** | |||
* Graphing Remastered | |||
* | |||
* Made by tigerbw | |||
*/ | |||
real resolution, x_left, x_right, g_x_left, g_x_right, y_down, y_up; | real resolution, x_left, x_right, g_x_left, g_x_right, y_down, y_up; | ||
resolution = 0. | resolution = 0.001; | ||
x_left = -8; | x_left = -8; | ||
x_right = 8; | x_right = 8; | ||
| Line 73: | Line 86: | ||
} | } | ||
real f(real x){ | real f(real x){ // equation to graph | ||
if (x!=1) { // check for impossible case | |||
return x^2/((x-1)); | |||
} | |||
else{ | |||
return y_up+1; | |||
} | |||
} | } | ||
| Line 81: | Line 99: | ||
bool prev = false; | bool prev = false; | ||
for (real i = g_x_left; i<=g_x_right; i+= resolution){ | for (real i = g_x_left; i<=g_x_right; i+= resolution){ | ||
if (f(i)<y_up && f(i) > y_down){ | |||
if (prev == true){ | |||
draw((i, f(i))--(i-resolution, f(i-resolution)), graph_pen); | |||
} | |||
prev = true; | |||
} | |||
else{ | |||
prev = false; | |||
} | |||
} | } | ||
} | } | ||
| Line 95: | Line 113: | ||
grid(); | grid(); | ||
dotgraph(); | dotgraph(); | ||
<syntaxhighlight | </syntaxhighlight> | ||
Latest revision as of 18:10, 18 January 2025
Graphing
So basically, I was mewing one day, and I wanted to do some stuff so I went to Desmos. I got back to mewing again, so I thought to make Desmos in asymptote. This is what I got
Source Code
/**
* Graphing Remastered
*
* Made by tigerbw
*/
real resolution, x_left, x_right, g_x_left, g_x_right, y_down, y_up;
resolution = 0.001;
x_left = -8;
x_right = 8;
y_down = -8;
y_up = 8;
g_x_left = -8;
g_x_right = 8;
pen gray_pen = gray(.7);
pen graph_pen = 1+blue;
void grid(){
real[] arrx, arry;
for (real i = x_left+1; i < x_right; i+=1){
draw((i, y_down)--(i, y_up), gray_pen);
}
for (real i = y_down+1; i < y_up; i+=1){
draw((x_left, i)--(x_right, i), gray_pen);
}
draw((x_left, 0)--(x_right, 0),Arrows);
draw((0,y_down)--(0, y_up),Arrows);
}
real f(real x){ // equation to graph
if (x!=1) { // check for impossible case
return x^2/((x-1));
}
else{
return y_up+1;
}
}
void dotgraph(){
bool prev = false;
for (real i = g_x_left; i<=g_x_right; i+= resolution){
if (f(i)<y_up && f(i) > y_down){
if (prev == true){
draw((i, f(i))--(i-resolution, f(i-resolution)), graph_pen);
}
prev = true;
}
else{
prev = false;
}
}
}
grid();
dotgraph();