Search This Blog

Monday, May 21, 2007

example of Bresenham's line algorithm

it depends on gtk+-2.0,using function gdk_draw_point to draw points.I wrote this little program because the stupid Chinese education:they are still writing c programs compiled by turbo c and with a "graphic.h" to draw graphics.



#include <gdk/gdk.h>//in fact,I do not know whether I need this

#include <gtk/gtk.h>



void linebres(int xa, int ya, int xb, int yb,GtkWidget *widget,GdkDrawable *drawable)

{

int dx = abs(xa-xb), dy = abs(ya-yb);

int p;

int twody, twodx;

int x,y,xend,yend;

float k=dy/dx;

int temp;

if(k > 1|| k < -1){

temp = xa;

xa = ya;

ya = temp;

temp = xb;

xb = yb;

yb = temp;

}



p = 2 * dy - dx;

twody = 2 * dy;

twodx = 2 * dx;



if(xa - xb > 0){

x = xb;

y = yb;

xend=xa;

}

else{

x = xa;

y = ya;

xend = xb;

}



gdk_draw_point (drawable,widget->style->black_gc,x,y);



while(x < xend){

x++;

if(p < 0)

p += twody;

else{

y++;

p += (twody-twodx);

}

gdk_draw_point (drawable,widget->style->black_gc,x,y);

}

}





static void on_destroy (GtkWidget * widget, gpointer data)

{

gtk_main_quit ();

}



gint expose_callback(GtkWidget *widget, GdkEventAny *event, gpointer data)

{

GdkDrawable *drawable;

int i;

drawable=widget->window;

linebres (10,5,180,60,widget,drawable);

return 0;

}



int main(int argc, char **argv)

{

gtk_init ( &argc, &argv);



GdkWindowAttr attr;



GtkWidget *window;



GtkWidget *widget = gtk_drawing_area_new ();

gtk_drawing_area_size (GTK_DRAWING_AREA (widget),200,200);



window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

gtk_container_add (GTK_CONTAINER (window),widget);



g_signal_connect (G_OBJECT (window), "destroy",G_CALLBACK (on_destroy), NULL);



g_signal_connect (G_OBJECT(widget), "expose_event",GTK_SIGNAL_FUNC(expose_callback), NULL);



gtk_widget_show_all (window);



gtk_main ();



return 0;



}



Wednesday, May 16, 2007

trackpoint in gentoo

trackpoint will work fine in gentoo by the following steps:
1.enable "press to select"

echo -n 1 > /sys/devices/platform/i8042/serio1/press_to_select

2.to enable scrolling,put the following lines into xorg.conf's trackpoint section(it's an "InputDevice" section)

Option "Emulate3Buttons" "on"
Option "Emulate3TimeOut" "50"
Option "EmulateWheel" "on"
Option "EmulateWheelTimeOut" "200"
Option "EmulateWheelButton" "2"
Option "YAxisMapping" "4 5"
Option "XAxisMapping" "6 7"
Option "ZAxisMapping" "4 5"

now restart X,and enjoy the trackpoint.

Thursday, May 10, 2007

installed gentoo 2007.0 amd64

the new livecd of 2007.0(amd64) now bootable,so I installed a 64bit gentoo.
64bit firefox can use 32bit flash plugin now:

#emerge netscape-flash
#emerge nspluginwrapper

everything should be all right now,if not,execute the following command:

$nspluginwrapper -i /usr/lib32/nsbrowser/plugins/libflashplayer.so

Wednesday, May 09, 2007

usb cd writer howto

1.build a kernel supporting usb cd



Device Drivers --->

SCSI device support --->

[M] SCSI CDROM support

[ ] Enable vendor-specific extensions (for SCSI CDROM)

[M] SCSI generic support



2.install packages that do the cd burning



#emerge cdrtools



3.do the burning with cdrecord

say,I want to burn livecd-amd64-installer-2007.0.iso



#cdrecord -speed=4 dev=/dev/sr0 -v livecd-amd64-installer-2007.0.iso



and wait for it until finish burning

Monday, May 07, 2007

use wpa_supplicant

I choose WPA-PSK for my wireless router,so the corresponding configure is like following:

$wpa_passphrase ssid passphrase

where passphrase is the router's PSK pass,and it outputs a string which should be assigned to "psk" in wpa_supplicant.conf,like this:

network={
ssid="ssid"
proto=WPA
key_mgmt=WPA-PSK
pairwise=TKIP
group=TKIP
psk=psk
priority=2
}

Saturday, May 05, 2007

browse chinese bbs with urxvt in utf8

for most chinese bbs output gbk encoding,so the urxvt should be told that it is going to treat the stream as gbk,more than that,it should also be told that the input mothod works in a utf8 enviroment,so I start a urxvt to browse bbs like this:

LC_ALL=zh_CN.GBK urxvt -imlocale 'zh_CN.utf8' -fn '10x20,xft:AR PL
New Sung:antialias=false' -e screen

it looks perfect

ENTRY in *.S files

the gdt of a cpu is described like this:

ENTRY(cpu_gdt_table)
.quad 0x0000000000000000
...

while ENTRY is a macro defined in include/linux/linkage.h ike this:

#define ENTRY(name) \
.globl name; \
ALIGN; \
name:

so it means a globally visible label leading a memory of data(gdt)?hmmm