Rosio Pavoris a blog

Bézier curves are pretty

If you’ve ever used a vector drawing program you’ve probably come across them. It turns out they’re conceptually a lot simpler than I expected them to be.
Wikipedia has great pictures that should be self-explanatory:

This is a linear “curve”, with only two guide points:

A quadratic curve has three guide points:

A cubic curve has four:

And a quartic curve has five:

Most vector graphic applications only go up to cubic, and represent more complicated curves as grafts of simpler ones.
My last exam was yesterday, though, so I had some free time, and I’ve been playing with Allegro recently, so I thought I’d write something that draws Bézier curves of arbitrary complexity. Behold.

First line is how you compile it on a typical system. You’ll need Allegro, obviously, which for Debian/Ubanto users is the liballegro-dev package. Others can get it here.

The guide points it uses are passed as command line arguments, with the first argument being the x coordinate of the first point, the second being the y coordinate of the first point, the third being the x coordinate of the second point, &c.
The origin (0, 0) is at the top left of the screen.

./bezier 10 10 50 320 310 230 200 10

This should give you something like:

The program will pause after drawing your curve, until you press a key. If that key is s, it will save the screen to a .pcx file, the name of which you can change in the #defines (default bezier.pcx; if you don’t like .pcx, Allegro also supports .bmp and .tga, and will determine file type based on the extension).

Other things you can customise should mostly be obvious. If LINES is 0 (or undefined), it will just draw pixels instead of trying to connect points with lines. If GUIDES is 1 it will mark the guide points in the color specified by GUIDECOL. GUIDECOL, FOREGROUND, and BACKGROUND are just RGB values in the range 0-255.
WIDTH and HEIGHT are the dimensions of the drawing field. This doesn’t have to be your resolution, but probably shouldn’t be higher. If you want a 100×100 image, 100 and 100 are perfectly legal values.
GRAIN is how often divide() recurses while trying to divide lines into sections. Higher values should give more accurate representations, but usually aren’t needed. STEPS is how many points this will actually give you. Don’t touch STEPS.

This isn’t hugely interesting, but it’s a nice enough toy that I thought I’d share it.

Permalink 3 Comments

$ php -r "echo 0.15-0.05;"
0.0:

The actual result is 0.09999999999999999167332731531132594, courtesy of IEEE, but since PHP is user-friendly, it rounds before display.

ASCII round

Permalink 11 Comments

Democracy!

Regional and European elections were yesterday. Results weren’t as disappointing as the federal elections in 2007 in that they likely won’t turn out as abysmally, but they’re still pretty sad in what they say about the Flemish voter.
First, the regional results. VRT always makes nice graphs, so let’s steal them:

That’s just the Flemish elections, because obviously I don’t live in Wallonia or Brussels or the German canton so I don’t have as much to say about them.
For our American viewers, this is roughly how they compare to the US Democrats and GOP, insofar as a political party can be reduced to a single dimension. Lijst Dedecker may be unfairly placed, because obviously the only LDD member who knows anything about the LDD platform is the guy who wrote it in the first place. And that’s not even Jean-Marie Dedecker.

Some of the denser political commentators seem to be baffled by the “paradox” of people preferring the “stability” of CD&V while also yearning for “change” by voting for N-VA and Lijst Dedecker.
To be absolutely clear, this is why people voted for Lijst Dedecker:

Jewdo Gold

And this is why people voted for N-VA:



And this is why people keep voting for CD&V:

Their respective platforms don’t have shit to do with anything.
I’m just glad that the people shallow enough to vote for a party because their public face who wasn’t even on the list in four of the five provinces is a jolly fat guy on the whole also seem to be the people idiotic enough to vote for Vlaams Belang in the past election. Plus my mom.

I suppose it’s good enough news. Lijst Dedecker got more votes than they deserved, but still not so many that anyone would be inclined to take them seriously, and while N-VA is dumbfuck rightwingery, they’re infinitely preferable over Vlaams Belang.
Vlaams Belang, which lost eleven of its seats in the Flemish parliament (of the 32 they had), and half of its seats in the Brussels Capital Region parliament (down to three, from six).

N-VA keeps getting votes for reasons unrelated to their platform, though, and thinking that means their Flemish independence twattery is gaining legitimacy among the people. Last election they were in a cartel with CD&V and piggy-backed on Leterme’s inexplicable popularity, and this time it’s De Wever being lol fny on the picture box.

I’d hope most N-VA members also realise Flemish independence is at best a pipe dream and at most realistic a diversion from real problems that they’re cynically exploiting. I’d rather have cynics than dipshits.

Incidentally, guess which canton is the most socialist in Flanders?
I voted for them because the alternatives were worse, but they really, really didn’t deserve it. I don’t think they could have put together a more obnoxious line-up for Vlaams Brabant if they tried. If this keeps happening I’m renouncing my membership.
Or moving to Zottegem.

By the way, an honorable mention goes to PVDA+, our beloved Trotskyists. Their clown campaign is responsible for one of the largest (relative) gains in these elections: they went from 0.6% of the vote to 1%. By the end of the century, they may even make the eligibility threshold!

Comedy!

Anyway.
The European election results aren’t world-shaking. Vlaams Belang lost a seat and gave it to Lijst Dedecker (even though Dedecker said he has no interest in Europe, of course; his “base” is as brain-damaged as he is), and that’s all that changed for Flanders. The greens gained a lot in the Walloon regional elections, so no surprises there either. The Germans get to vote on one MEP (and are as such overrepresented, but fine), and voted for a Christian Democrat again.
I’m told “the right is on the march” in Europe in general (it has been for years), but right now I don’t particularly care.

Regardless of your political convictions, I think everyone can agree the most important thing is that Vlaams Belang got its ass handed to it. Even if Antwerp still sucks.

Edit: Also:

Yeah.

Permalink 3 Comments