Scratch art

by sonone, May 28, 2020, 7:16 PM

I was playing around with circle and the for(...){...} function and got some nice results.
I will post a lot of examples in this post by editing, so don't forsake this post!

$P_i\to P_{i^2}$
[asy]
size(600);
dotfactor=1;
for(int j=1; j<=4; ++j){
for(int i=1; i<=360/j; ++i){
dot((2*j,0)+dir(j*i));
draw((2*j,0)+dir(j*i)--(2*j,0)+dir(j*i^2));
}}
[/asy]

$P_i\to P_{i^3}$
[asy]
size(600);
dotfactor=1;
for(int j=1; j<=4; ++j){
for(int i=1; i<=360/j; ++i){
dot((2*j,0)+dir(j*i));
draw((2*j,0)+dir(j*i)--(2*j,0)+dir(j*i^3));
}}
[/asy]

$(\cos x,\sin x)\to(\sin x,\cos x)$
[asy]
size(600);
dotfactor=1;
for(int j=1; j<=4; ++j){
for(int i=1; i<=360/j; ++i){
draw((2*j,0)+(cos(i),sin(i))--(2*j,0)+(sin(i),cos(i)));
}}
[/asy]

$P_i\to P_{(-1)^i2i}$
[asy]
size(600);
dotfactor=1;
for(int j=1; j<=4; ++j){
for(int i=1; i<=360/j; ++i){
dot((2*j,0)+dir(j*i));
draw((2*j,0)+dir(j*i)--(2*j,0)+dir((-1)^i*2*j*i));
}}
[/asy]
This post has been edited 1 time. Last edited by sonone, May 29, 2020, 8:10 PM

Comment

4 Comments

The post below has been deleted. Click to close.
This post has been deleted. Click here to see post.
In your last example, why did you define dotfactor, since you never actually used a dot?

by G.G.Otto, May 29, 2020, 4:10 AM

The post below has been deleted. Click to close.
This post has been deleted. Click here to see post.
Just-in-case precaution :)

by sonone, May 29, 2020, 7:56 PM

The post below has been deleted. Click to close.
This post has been deleted. Click here to see post.
I think I've found the best asymptote grapher. It's called AutoGraph and was developed by PythonNut. See here. There are lots of different versions, the latest one that works on AoPS is V-5.

[asy]
/*
AUTO-GRAPH V-5 alpha by PythonNut. Please do not plagerize, it's illegal :)
Customizations: feel free to edit

graph function */
real f(real x){
   return 2x^3-9x^2+12x+1;} // type function to be graphed here

/* x maximum and minimum */
int X_max = 10; int X_min = -10;
/* y maximum and minimum */
int Y_max = 10; int Y_min = -10;

/* toggle features */
bool mark_lattice = true;
bool show_grid = false;
bool mark_solutions = true;
bool integral = false;
bool maxima_and_minima = true;
bool derivative = true; real[] Dpoints = {0.9,1.5,2.1,2.2,2.3};

/* other options */
int size = 500; real line_width = 0.75;
pen color = heavygreen; pen opacity = opacity(0.9);
real X_density = 1; real Y_density = 1; real ratio = 1;
real res = 0.00005; pen fill = palegreen+linewidth(0.75)+opacity(0.8);
pen aux  = linewidth(0.75)+opacity(0.9);
pen[] colors = {blue,red,green,pink,yellow,purple,orange};
real Dres = 0.00000001;

/* The Code. Do not disturb unless you know what you are doing */
import math;import graph;
size(size);unitsize(size*ratio,size);Label l;l.p=fontsize(6);path s=(X_max,0)--(X_min,0);
pen GRAPH = opacity+color+linewidth(line_width);real temp = X_min;
while (! (f(temp) <= Y_max && f(temp) >= Y_min && temp < X_max)){temp += res;}
if (integral){if (f(temp-res) > Y_max){
filldraw( (X_min,0)--(X_min,Y_max)--(temp,Y_max)--(temp,0)--cycle , fill,fill);}if (f(temp-res) < Y_min){
filldraw( (X_min,0)--(X_min,Y_min)--(temp,Y_min)--(temp,0)--cycle , fill,fill);}}real max = temp;
while (f(max) <= Y_max && f(max) >= Y_min && max < X_max){max += res;}real min = temp;
while (f(min) <= Y_max && f(min) >= Y_min && min > X_min){min -= res;}
path graph = graph(f,min,max,n=2400);if (integral){
filldraw((min,0)--graph--(max,0)--cycle,fill,fill);}draw(graph,GRAPH,Arrows);temp = max+res;
while (temp <= X_max){max=temp;
while (! (f(temp) <= Y_max && f(temp) >= Y_min) && temp < X_max){
temp += res;}if (integral){if (f(temp-res) > Y_max){
filldraw( (max,0)--(max,Y_max)--(temp,Y_max)--(temp,0)--cycle , fill,fill);}
if (f(temp-res) < Y_min){
filldraw( (max,0)--(max,Y_min)--(temp,Y_min)--(temp,0)--cycle , fill,fill);
}}real max = temp;
while (f(max) <= Y_max && f(max) >= Y_min && max < X_max){max += res;}real min = temp;
while (f(min) <= Y_max && f(min) >= Y_min && min > X_min){
min -= res;}if (max <= X_max){path graph = graph(f,min,max,n=2400);
if (integral){filldraw((min,0)--graph--(max,0)--cycle,fill,fill);}draw(graph,GRAPH,Arrows);}
if (mark_solutions){dot(intersectionpoints(s,graph),green);}temp = max+res;continue;}
if (integral){if (f(temp-res) > Y_max){
filldraw( (temp,0)--(temp,Y_max)--(X_max,Y_max)--(X_max,0)--cycle , fill,fill);}
if (f(temp-res) < Y_min){
filldraw( (temp,0)--(temp,Y_min)--(X_max,Y_min)--(X_max,0)--cycle , fill,fill);}}temp = X_max;
while (f(temp) <= Y_max && f(temp) >= Y_min && temp >= X_min){temp -= res;}
if (f(X_max) <= Y_max && f(X_max) >= Y_min){
path graph2 = graph(f,temp,X_max,n=2400);if (integral){
filldraw( (temp,0)--graph2--(X_max,0)--cycle,fill,fill );}draw(graph2,GRAPH,Arrows);
if (mark_solutions){dot(intersectionpoints(s,graph2),green);}}
if (mark_lattice){for (real temp = X_min; temp <= X_max; ++temp){
if (f(temp)%1==0 && f(temp)<=Y_max && f(temp)>=Y_min){
dot((temp,f(temp)),color+linewidth(line_width*4));}}}if (maxima_and_minima){
real temp = X_min;real min  = X_max;real max  = X_min;while (temp <= X_max){
if (f(temp) >= max){max=f(temp);}if (f(temp) <= min){min=f(temp);}temp+=res;}
if (max < X_max && max > X_min){draw((X_min,max)--(X_max,max),aux+blue);}
if (min > X_min && min < X_max){draw((X_min,min)--(X_max,min),aux+blue);}}
if (derivative){for (int i = 0; i < Dpoints.length; ++i){real Dpoint=Dpoints[i];
real h(real x){real temp = -(f(Dpoint)-f(Dpoint+Dres))/Dres*x;
temp += (f(Dpoint)-f(Dpoint+Dres))/Dres*Dpoint;temp += f(Dpoint);return temp;}
dot((Dpoint,f(Dpoint)),linewidth(3)+colors[i%colors.length]);
draw(graph(h,X_min-0.2,X_max+0.2),aux+colors[i%colors.length]);
draw((Dpoint,f(Dpoint))--(Dpoint,0),darkgrey+dashed);}}
clip((X_min-0.2,Y_min-0.2)--(X_min-0.2,Y_max+0.2)--(X_max+0.2,Y_max+0.2)--(X_max+0.2,Y_min-0.2)--cycle);
dot((0,0));picture main;xaxis("$x$",X_min,X_max,Ticks(l,X_density,(X_density/2),NoZero),Arrows);
yaxis("$y$",Y_min,Y_max,Ticks(l,Y_density,(Y_density/2),NoZero),Arrows);
if (show_grid){add(shift(X_min,Y_min)*grid(X_max-X_min,Y_max-Y_min));}
add(main);/* Property of "PythonNut" 2011*/
[/asy]

Now all your writing problems will be a lot easier! It's also very customizable and has a ton of features, look at the code!

[asy]
/*
AUTO-GRAPH V-5 alpha by PythonNut. Please do not plagerize, it's illegal :)
Customizations: feel free to edit

graph function */
real f(real x){
   return sin(x)-9x^2+12x+1;} // type function to be graphed here

/* x maximum and minimum */
int X_max = 10; int X_min = -10;
/* y maximum and minimum */
int Y_max = 10; int Y_min = -10;

/* toggle features */
bool mark_lattice = true;
bool show_grid = false;
bool mark_solutions = true;
bool integral = true;
bool maxima_and_minima = true;
bool derivative = true; real[] Dpoints = {0.9,1.5};

/* other options */
int size = 500; real line_width = 0.95;
pen color = heavygreen; pen opacity = opacity(0.9);
real X_density = 2; real Y_density = 2; real ratio = 1;
real res = 0.00005; pen fill = palegreen+linewidth(0.75)+opacity(0.8);
pen aux  = linewidth(0.75)+opacity(0.9);
pen[] colors = {blue,red,green,pink,yellow,purple,orange};
real Dres = 0.00000001;

/* The Code. Do not disturb unless you know what you are doing */
import math;import graph;
size(size);unitsize(size*ratio,size);Label l;l.p=fontsize(6);path s=(X_max,0)--(X_min,0);
pen GRAPH = opacity+color+linewidth(line_width);real temp = X_min;
while (! (f(temp) <= Y_max && f(temp) >= Y_min && temp < X_max)){temp += res;}
if (integral){if (f(temp-res) > Y_max){
filldraw( (X_min,0)--(X_min,Y_max)--(temp,Y_max)--(temp,0)--cycle , fill,fill);}if (f(temp-res) < Y_min){
filldraw( (X_min,0)--(X_min,Y_min)--(temp,Y_min)--(temp,0)--cycle , fill,fill);}}real max = temp;
while (f(max) <= Y_max && f(max) >= Y_min && max < X_max){max += res;}real min = temp;
while (f(min) <= Y_max && f(min) >= Y_min && min > X_min){min -= res;}
path graph = graph(f,min,max,n=2400);if (integral){
filldraw((min,0)--graph--(max,0)--cycle,fill,fill);}draw(graph,GRAPH,Arrows);temp = max+res;
while (temp <= X_max){max=temp;
while (! (f(temp) <= Y_max && f(temp) >= Y_min) && temp < X_max){
temp += res;}if (integral){if (f(temp-res) > Y_max){
filldraw( (max,0)--(max,Y_max)--(temp,Y_max)--(temp,0)--cycle , fill,fill);}
if (f(temp-res) < Y_min){
filldraw( (max,0)--(max,Y_min)--(temp,Y_min)--(temp,0)--cycle , fill,fill);
}}real max = temp;
while (f(max) <= Y_max && f(max) >= Y_min && max < X_max){max += res;}real min = temp;
while (f(min) <= Y_max && f(min) >= Y_min && min > X_min){
min -= res;}if (max <= X_max){path graph = graph(f,min,max,n=2400);
if (integral){filldraw((min,0)--graph--(max,0)--cycle,fill,fill);}draw(graph,GRAPH,Arrows);}
if (mark_solutions){dot(intersectionpoints(s,graph),green);}temp = max+res;continue;}
if (integral){if (f(temp-res) > Y_max){
filldraw( (temp,0)--(temp,Y_max)--(X_max,Y_max)--(X_max,0)--cycle , fill,fill);}
if (f(temp-res) < Y_min){
filldraw( (temp,0)--(temp,Y_min)--(X_max,Y_min)--(X_max,0)--cycle , fill,fill);}}temp = X_max;
while (f(temp) <= Y_max && f(temp) >= Y_min && temp >= X_min){temp -= res;}
if (f(X_max) <= Y_max && f(X_max) >= Y_min){
path graph2 = graph(f,temp,X_max,n=2400);if (integral){
filldraw( (temp,0)--graph2--(X_max,0)--cycle,fill,fill );}draw(graph2,GRAPH,Arrows);
if (mark_solutions){dot(intersectionpoints(s,graph2),green);}}
if (mark_lattice){for (real temp = X_min; temp <= X_max; ++temp){
if (f(temp)%1==0 && f(temp)<=Y_max && f(temp)>=Y_min){
dot((temp,f(temp)),color+linewidth(line_width*4));}}}if (maxima_and_minima){
real temp = X_min;real min  = X_max;real max  = X_min;while (temp <= X_max){
if (f(temp) >= max){max=f(temp);}if (f(temp) <= min){min=f(temp);}temp+=res;}
if (max < X_max && max > X_min){draw((X_min,max)--(X_max,max),aux+blue);}
if (min > X_min && min < X_max){draw((X_min,min)--(X_max,min),aux+blue);}}
if (derivative){for (int i = 0; i < Dpoints.length; ++i){real Dpoint=Dpoints[i];
real h(real x){real temp = -(f(Dpoint)-f(Dpoint+Dres))/Dres*x;
temp += (f(Dpoint)-f(Dpoint+Dres))/Dres*Dpoint;temp += f(Dpoint);return temp;}
dot((Dpoint,f(Dpoint)),linewidth(3)+colors[i%colors.length]);
draw(graph(h,X_min-0.2,X_max+0.2),aux+colors[i%colors.length]);
draw((Dpoint,f(Dpoint))--(Dpoint,0),darkgrey+dashed);}}
clip((X_min-0.2,Y_min-0.2)--(X_min-0.2,Y_max+0.2)--(X_max+0.2,Y_max+0.2)--(X_max+0.2,Y_min-0.2)--cycle);
dot((0,0));picture main;xaxis("$x$",X_min,X_max,Ticks(l,X_density,(X_density/2),NoZero),Arrows);
yaxis("$y$",Y_min,Y_max,Ticks(l,Y_density,(Y_density/2),NoZero),Arrows);
if (show_grid){add(shift(X_min,Y_min)*grid(X_max-X_min,Y_max-Y_min));}
add(main);/* Property of "PythonNut" 2011*/
[/asy]

-piphi

by piphi, Jun 3, 2020, 2:22 AM

The post below has been deleted. Click to close.
This post has been deleted. Click here to see post.
Thats really cool! Even though writing problem diagrams aren't that hard, I see what you mean!

by sonone, Jun 3, 2020, 7:36 PM

Old material is mostly Asymptote, new material is calculator programming

avatar

sonone
Archives
+ April 2023
+ August 2022
+ April 2021
+ August 2020
Shouts
Submit
  • I still exist as well.

    by G.G.Otto, Aug 11, 2023, 2:44 AM

  • hello I'm still here lol

    by player01, Aug 6, 2022, 6:24 PM

  • [REVIVAL] I will start posting more calculator relating posts very soon. Even though school has been busy, I have been programming my calculators a decent amount, so I have a lot to share...

    by sonone, Feb 18, 2022, 10:29 PM

  • wow its been like 2.5 years since geo class

    by pieMax2713, Feb 4, 2022, 8:38 PM

  • @violin21, I've been very busy with school lately and haven't been able to add another lesson. I will when i get a free moment

    by sonone, Aug 19, 2021, 12:45 AM

  • ORZ CODER

    by samrocksnature, Aug 9, 2021, 9:57 PM

  • Could you make more Asymptote lessons on your "How to do Asymptote" blog?

    by violin21, Aug 9, 2021, 7:26 PM

  • You can take it, just C&P the CSS into your CSS area

    by sonone, Apr 17, 2021, 10:08 PM

  • how can we take the CSS if we have permission to not take it?

    by GoogleNebula, Apr 17, 2021, 5:22 PM

  • That is awesome!

    by sonone, Apr 15, 2021, 10:09 PM

  • I modified your dodecahedron and got:
    [asy]
    import three;
    import solids;
    size(300);
    currentprojection=orthographic(0,1.3,1.2);
    light(0,5,10);

    real phi=(sqrt(6)+1)/3;
    real g=(phi-1)/2;
    real s=1/2;
    real a=sqrt(1-phi*phi/4-g*g)+phi/2;

    triple[] d;
    d[0]=(phi

    by Andrew2019, Mar 26, 2021, 12:15 AM

  • Not too many, just changing the color here and there. I really like your CSS!

    by sonone, Feb 2, 2021, 10:35 AM

  • Nice!

    I see you're making changes to the CSS. :)

    by G.G.Otto, Feb 1, 2021, 9:26 PM

  • I'm learning Java now!

    by sonone, Feb 1, 2021, 5:56 PM

  • And I took part of it from CaptainFlint and then added a ton of modifications. ;)

    by G.G.Otto, Dec 1, 2020, 8:56 AM

98 shouts
Tags
About Owner
  • Posts: 2106
  • Joined: Aug 20, 2016
Blog Stats
  • Blog created: Mar 28, 2020
  • Total entries: 61
  • Total visits: 4966
  • Total comments: 146
Search Blog
a