All that for something barely anyone saw

One of the problems of providing an RSS feed (Really Simple Syndication) [1] is that most of my readers read it and not the site here, thus the format change I did for April 1^st was lost, along with most of my AdSense [2] revenue (one of the few things I can report about is my gross earnings from Google [3], which to the nearest cent is $0.00)—I suppose I may get more revenue if I inline the ads, such as:

But I don't really want to do that (nor add ads to my RSS (Really Simple Syndication) feed, so don't worry—well, except possibly for this entry but that depends on if your RSS agregator filters out the <SCRIPT> tag (it'll be interesting to see).

Anyway …

Last year's April Fools theme was greenbar printer paper, where (through the wonders of CSS (Cascading Style Sheets)) it appeared as if this was being printed out (in all caps no less) and it took me quite a while to find an appropriate image of greenbar paper for the background. This years idea was to do an old fasion monochrome monitor (green on black) with a slight resync problem (you can see a bright green line of the electron gun being swept across the screen). A bit easier to munge up than last year's imagry and one I could make myself.

At first I tried a paint program, but it was a rather primitive paint program and I had problems trying to do the 2048x100 image (2048 pixels wide to make sure it was wide enough not to repeat for anyone). Too many problems using the program, leading it to taking way too long.

It was then I remembered I had the GD library [4] installed.

Trivial!

How trivial?

>
```
#include <stdio.h>
#include <stdlib.h>
#include "gd.h"
int main(void)
{
FILE *fpout;
gdImagePtr imout;
int background;
int line[3];
imout = gdImageCreate(2048,100);
background = gdImageColorAllocate(imout,16, 32,16);
line[0] = gdImageColorAllocate(imout,16, 64,16);
line[1] = gdImageColorAllocate(imout,16, 96,16);
line[2] = gdImageColorAllocate(imout,16,128,16);
gdImageLine(imout,0,13,2047,23,line[0]);
gdImageLine(imout,0,14,2047,24,line[1]);
gdImageLine(imout,0,15,2047,25,line[2]);
gdImageLine(imout,0,16,2047,26,line[1]);
gdImageLine(imout,0,17,2047,27,line[0]);
fpout = fopen("vidline.png","wb");
gdImagePng(imout,fpout);
fclose(fpout);
gdImageDestroy(imout);
return(EXIT_SUCCESS);
}
```

A crude attempt at anti-aliasing a beam across the page. Very poor results no matter how I did it. It was then I remembered my Foley-van Dam book (Computer Graphics: Principles and Practice [5] by Foley, van Dam, Feiner and Hughes, 2^nd Edition)—surely it must have a section on anti-aliasing lines. Indeed, § 3.17 had just what I wanted—code for drawing anti-aliased lines. A few minutes typing in the code (a page's worth) and I had myself one nice anti-aliased beam across the page.

>
```
int g_brightness[100];
/********************/
void init_colors(gdImagePtr img)
{
int i;
for (i = 0 ; i < 100 ; i++)
g_brightness[i] = gdImageColorAllocate(img,16,132-i,16);
}
/******************/
void pset(gdImagePtr img,int x,int y,double dist)
{
int intensity;
intensity = (int)(fabs(dist) / 1.5 * 100.0);
gdImageSetPixel(img,x,y,g_brightness[intensity]);
}
/***********************/
void line(gdImagePtr img,int x1,int y1,int x2,int y2)
{
int dx;
int dy;
int incrE;
int incrNE;
int d;
int x;
int y;
int two_v_dx;
double invDenom;
double two_dx_invDenom;
dx = x2 - x1;
dy = y2 - y1;
d = 2 * dy - dx;
incrE = 2 * dy;
incrNE = 2 * (dy - dx);
two_v_dx = 0;
invDenom = 1.0 / (2.0 * sqrt(dx*dx + dy+dy));
two_dx_invDenom = 2.0 * (double)dx * invDenom;
x = x1;
y = y1;
pset(img,x,y ,0.0);
pset(img,x,y + 1,two_dx_invDenom);
pset(img,x,y - 1,two_dx_invDenom);
while(x < x2)
{
if (d < 0)
{
two_v_dx = d + dx;
d += incrE;
x++;
}
else
{
two_v_dx = d - dx;
d += incrNE;
x++;
y++;
}
pset(img,x,y ,two_v_dx * invDenom);
pset(img,x,y + 1,two_dx_invDenom - two_v_dx * invDenom);
pset(img,x,y - 1,two_dx_invDenom + two_v_dx * invDenom);
}
}
```

See what I go through for stuff nobody will see?

Sigh.

(If you are curious to see the styles, and you are using Firefox [6], you can use the menu View/Page Style to select which style you want).

[1] https://boston.conman.org/bostondiaries.rss

[2] http://www.google.com/ads/

[3] http://www.google.com/

[4] http://www.boutell.com/gd/

[5] http://www.amazon.com/exec/obidos/ASIN/0201848406/conmanlaborat-20

[6] http://www.mozilla.org/products/firefox/central.html

Gemini Mention this post

Contact the author