xxxxxxxxxx
121
let cur_sw = 1.0;
let realStrokeWeight;
function fakeStrokeWeight(w) {
cur_sw = w;
realStrokeWeight(w);
}
function fakeEllipse(x1, y1, dx, dy) {
textFont( "Verdana" );
textSize(16);
let str = "ellipse( " + x1 + ", " + y1 + ", " + dx + ", " + dy + " );";
let w = textWidth(str);
let h = textAscent();
// Assume dx = dy, i.e., circle! Real ellipses are too hard.
const peri = PI * dx;
for (let idx = 0; idx < str.length; ++idx) {
let c = str[idx];
if (c == " ") {
continue;
}
let ang = (TWO_PI * idx) / str.length;
push();
translate(x1 + (dx / 2) * cos(ang), y1 + (dx / 2) * sin(ang));
rotate(ang + HALF_PI);
scale(peri / w, cur_sw / h);
text(c, 0, h / 2);
pop();
}
}
function fakeLine(x1, y1, x2, y2) {
textFont( "Verdana" );
textSize(16);
let str = "line( " + x1 + ", " + y1 + ", " + x2 + ", " + y2 + " );";
let w = textWidth(str);
let h = textAscent();
push();
translate(x1, y1);
rotate(atan2(y2 - y1, x2 - x1));
scale(dist(x1, y1, x2, y2) / w, cur_sw / h);
text(str, 0, h/2);
pop();
}
function setup() {
createCanvas(512, 512);
line = fakeLine;
ellipse = fakeEllipse;
realStrokeWeight = strokeWeight;
strokeWeight = fakeStrokeWeight;
}
function draw() {
background(0, 0, 255);
fill(255, 255, 0);
strokeWeight(14);
line(0, 300, width, 300);
strokeWeight(10);
line(100, 300, 100, 200);
line(75, 200, 225, 200);
line(200, 200, 200, 300);
line(75, 200, 150, 120);
line(150, 120, 225, 200);
strokeWeight( 5 );
line( 120, 300, 120, 260 );
line( 120, 260, 140, 260 );
line( 140, 260, 140, 300 );
// noStroke();
// fill( 255 );
// rect( 0, 300, width,2 );
strokeWeight(10);
ellipse(width - 30, 30, 100, 100);
strokeWeight(12);
for (let idx = 0; idx < 5; ++idx) {
let ang = PI - (idx / 4) * HALF_PI;
if (frameCount % 100 > 50) {
ang -= PI / 32;
} else {
ang += PI / 32;
}
line(
int(width - 30 + 70 * cos(ang)),
int(30 + 70 * sin(ang)),
int(width - 30 + 180 * cos(ang)),
int(30 + 180 * sin(ang))
);
}
strokeWeight(8);
let x = map(frameCount % 200, 0, 200, -100, width + 100);
let y = 400;
line(x, y, x + 170, y);
line(x, y, x, y-30);
line(x + 170, y, x + 170, y-30);
line(x, y-30, x + 170, y-30);
line(x + 20, y-30, x + 30, y-60);
line(x + 30, y-60, x + 80, y-60);
line(x + 80, y-60, x + 120, y-30);
strokeWeight( 12 );
ellipse(x + 30, y, 40, 40);
ellipse(x + 140, y, 40, 40);
}
function keyPressed()
{
if( key == 'g' ) {
loop();
saveGif("output", 200, { units: "frames", delay: 0 });
}
}