CharCode berfungsi untuk mengkonversi beberapa karakter menjadi sebuah karakter.
Berikut adalah contoh listing dari penggunaan CharCode:
Contoh listing dalam pembuatan Titik yang dapat di geser
?-
G_X1:=0,
G_X2:=G_X1,
G_Y1:=0,
G_Y2:=G_Y1,
P1:=0,
P2:=0,
window(_,_,win_func(),"Move",500,200,300,300).
win_func(key_down(39,_)):-
(G_X1 < 200 -> G_X2 := G_X1,
G_X1:=G_X1+1), draw2.
win_func(key_down(37,_)):-
(G_X1 < 200 -> G_X2 := G_X1,
G_X1:=G_X1-1), draw2.
win_func(key_down(38,_)):-
(G_Y1 < 300 -> G_Y2 := G_Y1,
G_Y1:=G_Y1-1), draw3.
win_func(key_down(40,_)):-
(G_Y1 < 300 -> G_Y2 := G_Y1,
G_Y1:=G_Y1+1), draw3.
win_func(paint):- draw.
draw:-
P1:=G_X1*3,
P2:=G_Y1*3,
ellipse(P1,P2,P1+10,P2+10).
draw2:-
update_window(_),
P1:=G_X1*3+10,
ellipse(P1,0,P1+10,10).
draw3:-
update_window(_),
P2:=G_Y1*3+10,
ellipse(0,P2,10,P2+10).
G_X1:=0,
G_X2:=G_X1,
G_Y1:=0,
G_Y2:=G_Y1,
P1:=0,
P2:=0,
window(_,_,win_func(),"Move",500,200,300,300).
win_func(key_down(39,_)):-
(G_X1 < 200 -> G_X2 := G_X1,
G_X1:=G_X1+1), draw2.
win_func(key_down(37,_)):-
(G_X1 < 200 -> G_X2 := G_X1,
G_X1:=G_X1-1), draw2.
win_func(key_down(38,_)):-
(G_Y1 < 300 -> G_Y2 := G_Y1,
G_Y1:=G_Y1-1), draw3.
win_func(key_down(40,_)):-
(G_Y1 < 300 -> G_Y2 := G_Y1,
G_Y1:=G_Y1+1), draw3.
win_func(paint):- draw.
draw:-
P1:=G_X1*3,
P2:=G_Y1*3,
ellipse(P1,P2,P1+10,P2+10).
draw2:-
update_window(_),
P1:=G_X1*3+10,
ellipse(P1,0,P1+10,10).
draw3:-
update_window(_),
P2:=G_Y1*3+10,
ellipse(0,P2,10,P2+10).
OUTPUT
Tidak ada komentar:
Posting Komentar