Asymptote language preview
1. A smooth curve through control points
Bézier path construction with the ..controls.. operator
horizon-dark
import graph;
size(200);
path g = (0,0)..controls (1,2) and (3,2)..(4,0);
draw(g, blue+linewidth(1.2));
dot((0,0));
dot((4,0));
label("start", (0,0), S);
label("end", (4,0), S);
atom-one-dark
import graph;
size(200);
path g = (0,0)..controls (1,2) and (3,2)..(4,0);
draw(g, blue+linewidth(1.2));
dot((0,0));
dot((4,0));
label("start", (0,0), S);
label("end", (4,0), S);
github-dark
import graph;
size(200);
path g = (0,0)..controls (1,2) and (3,2)..(4,0);
draw(g, blue+linewidth(1.2));
dot((0,0));
dot((4,0));
label("start", (0,0), S);
label("end", (4,0), S);
dracula
import graph;
size(200);
path g = (0,0)..controls (1,2) and (3,2)..(4,0);
draw(g, blue+linewidth(1.2));
dot((0,0));
dot((4,0));
label("start", (0,0), S);
label("end", (4,0), S);
nord
import graph;
size(200);
path g = (0,0)..controls (1,2) and (3,2)..(4,0);
draw(g, blue+linewidth(1.2));
dot((0,0));
dot((4,0));
label("start", (0,0), S);
label("end", (4,0), S);
github
import graph;
size(200);
path g = (0,0)..controls (1,2) and (3,2)..(4,0);
draw(g, blue+linewidth(1.2));
dot((0,0));
dot((4,0));
label("start", (0,0), S);
label("end", (4,0), S);
2. A struct for reusable geometry
declaring a struct and drawing labeled points from it
horizon-dark
struct Point {
real x, y;
string name;
}
Point[] points = {
Point(0, 0, "A"),
Point(2, 1, "B"),
Point(4, 0, "C"),
};
for (int i = 0; i < points.length; ++i) {
pair p = (points[i].x, points[i].y);
dot(p);
label(points[i].name, p, N);
}
atom-one-dark
struct Point {
real x, y;
string name;
}
Point[] points = {
Point(0, 0, "A"),
Point(2, 1, "B"),
Point(4, 0, "C"),
};
for (int i = 0; i < points.length; ++i) {
pair p = (points[i].x, points[i].y);
dot(p);
label(points[i].name, p, N);
}
github-dark
struct Point {
real x, y;
string name;
}
Point[] points = {
Point(0, 0, "A"),
Point(2, 1, "B"),
Point(4, 0, "C"),
};
for (int i = 0; i < points.length; ++i) {
pair p = (points[i].x, points[i].y);
dot(p);
label(points[i].name, p, N);
}
dracula
struct Point {
real x, y;
string name;
}
Point[] points = {
Point(0, 0, "A"),
Point(2, 1, "B"),
Point(4, 0, "C"),
};
for (int i = 0; i < points.length; ++i) {
pair p = (points[i].x, points[i].y);
dot(p);
label(points[i].name, p, N);
}
nord
struct Point {
real x, y;
string name;
}
Point[] points = {
Point(0, 0, "A"),
Point(2, 1, "B"),
Point(4, 0, "C"),
};
for (int i = 0; i < points.length; ++i) {
pair p = (points[i].x, points[i].y);
dot(p);
label(points[i].name, p, N);
}
github
struct Point {
real x, y;
string name;
}
Point[] points = {
Point(0, 0, "A"),
Point(2, 1, "B"),
Point(4, 0, "C"),
};
for (int i = 0; i < points.length; ++i) {
pair p = (points[i].x, points[i].y);
dot(p);
label(points[i].name, p, N);
}
3. A filled shape with a pen mix
combining pens with + and clipping a filled region
horizon-dark
size(150);
path square = (0,0)--(2,0)--(2,2)--(0,2)--cycle;
fill(square, red+opacity(0.3));
draw(square, black+linewidth(1));
clip(unitcircle scaled 2 shifted (1,1));
atom-one-dark
size(150);
path square = (0,0)--(2,0)--(2,2)--(0,2)--cycle;
fill(square, red+opacity(0.3));
draw(square, black+linewidth(1));
clip(unitcircle scaled 2 shifted (1,1));
github-dark
size(150);
path square = (0,0)--(2,0)--(2,2)--(0,2)--cycle;
fill(square, red+opacity(0.3));
draw(square, black+linewidth(1));
clip(unitcircle scaled 2 shifted (1,1));
dracula
size(150);
path square = (0,0)--(2,0)--(2,2)--(0,2)--cycle;
fill(square, red+opacity(0.3));
draw(square, black+linewidth(1));
clip(unitcircle scaled 2 shifted (1,1));
nord
size(150);
path square = (0,0)--(2,0)--(2,2)--(0,2)--cycle;
fill(square, red+opacity(0.3));
draw(square, black+linewidth(1));
clip(unitcircle scaled 2 shifted (1,1));
github
size(150);
path square = (0,0)--(2,0)--(2,2)--(0,2)--cycle;
fill(square, red+opacity(0.3));
draw(square, black+linewidth(1));
clip(unitcircle scaled 2 shifted (1,1));