PostCard from Russia
From wiki.visual-prolog.com
Revision as of 22:29, 22 December 2007 by Victor Yukhtenko (talk | contribs)
To run the program please make the steps as follows:
Create the new project with the User Interface strategy Console In the created project replace the entire content of the file "main.pro" by the code shown below While building the project answer "Add All", when any dialog with proposals to include any packages to the project appears
/***************************************************************************** RSUH, Moscow Russian State University for Humanities Intelligent Systems Department visit us at http://www.rsuh.ru Best viewed in a console twice or more higher than the standart one. ******************************************************************************/ implement main open core, console, math, list, programControl constants className = "main". classVersion = "1.0". clauses classInfo(className, classVersion). class facts i : positive:= 0. xp : unsigned16:= 30. yp : unsigned16:= 37. phrase : string:= "". n : unsigned:= 4. class predicates ellipse : (integer Rx,integer Ry,integer XCent,integer YCent,string Symbol,positive Sleep). arc : (integer Rx,integer Ry,integer XCent,integer YCent,real Percent_Beg,real Percent_End,string Symb,positive Sleep). line : (location P1,location P2,string,positive Sleep). coord : (real X0, real Xspeed,real T,real Y0,real Yspeed, real G, string Symbol). firework : (boolean IsDrawing,real X0,real Y0,real G,positive Sleep,string Symbol). constants % Congratulation-phrases for random choice phraseList : string* = [ "Счастливого Нового Года и Рождества!", "ВСЕ УМЕЮ, ВСЕ МОГУ, Я - СТУДЕНТ РГГУ!", "Мы программисты!", "From Russia with love!", "We are the programmers, my friend!", "Vivat Visual Prolog!", "We wish you a Merry Christmas and a happy New Year!", "Joyeux Noёl et bonne Année!", "Frohe Weihnachten und ein gutes neues Jahr!", "Buon natale e felice anno nuovo!", "Feliz Navidad y Prospero Ano Nuevo!", "Glaedelig jul og godt nytår!", "Kurisumasu Omedeto!", "Natale hilareet Annum Faustum!" ]. % Symbols that will be randomly used for building a firework symbolList : string* = ["@","#","$","%","&","*","+","=","x","?"]. clauses % drawing an ellipse with the center in (XCent;YCent) ellipse(Rx,Ry,XCent,YCent,Symbol,Sleep):- arc(Rx,Ry,XCent,YCent,0,1,Symbol,Sleep). % drawing an arc with the center in (XCent;YCent) arc(Rx,Ry,XCent,YCent,Percent_Beg,Percent_End,Symbol,Sleep):- foreach X=std::fromTo(round(Percent_Beg*31),round(Percent_End*31)) do Angle=(2*pi)*(X/32), XCur=convert(unsigned16,XCent+round(Rx*cos(Angle))), YCur=convert(unsigned16,YCent-round(Ry*sin(Angle))), setLocation(location(XCur,YCur)), write(Symbol), sleep(Sleep) end foreach. % Drawing a horizontal line line(location(X,Y1),location(X,Y2),Symbol,Sleep):- !, foreach Y=std::fromTo(Y1,Y2) do setLocation(location(X, convert(unsigned16,Y))), write(Symbol), sleep(Sleep) end foreach. % Drawing a non-horizontal line line(location(X1,Y1),location(X2,Y2),Symbol,Sleep):- foreach X=std::fromTo(X1,X2) do Z1=X-X1, if Y2>=Y1 then Z2=Y2-Y1 else Z2=-1*(Y1-Y2) end if, Y=convert(unsigned16,round(Z1*Z2/(X2-X1)+Y1)), setLocation(location(convert(unsigned16,X),Y)), write(Symbol), sleep(Sleep) end foreach. /* Calculation of the trajectory of a thrown object (symbol) for forming a firework line. The object is thrown at certain angle and falls with free-fall acceleration G */ coord(X0,Xspeed,T,Y0,Yspeed,G,Symbol):- X=convert(unsigned16,round(X0+XSpeed*T)), Y=convert(unsigned16,round(Y0-(YSpeed*T-G*T^2/2))), setLocation(location(X,Y)), write(Symbol). % Drawing a firework using random symbols from the list firework(true,Xc,Yc,G,Sleep,_Symbol):- !, foreach I=std::fromTo(0,29) do coord(42-Xc,7,I*0.1,20+Yc,7,G,nth(convert(positive,random(10)),symbolList)), coord(38-Xc,-6,I*0.1,20+Yc,7,G,nth(convert(positive,random(10)),symbolList)), coord(42-Xc,4,I*0.1,18+Yc,9,G,nth(convert(positive,random(10)),symbolList)), coord(38-Xc,-3,I*0.1,18+Yc,9,G,nth(convert(positive,random(10)),symbolList)), coord(41-Xc,5,I*0.1,21+Yc,5,G,nth(convert(positive,random(10)),symbolList)), coord(39-Xc,-5,I*0.1,21+Yc,5,G,nth(convert(positive,random(10)),symbolList)), coord(39-Xc,-2,I*0.1,18+Yc,11,G,nth(convert(positive,random(10)),symbolList)), sleep(Sleep) end foreach. % Replacing the firework by that of blank spaces firework(_,Xc,Yc,G,Sleep,Symbol):- foreach I=std::fromTo(0,29) do coord(42-Xc,7,I*0.1,20+Yc,7,G,Symbol), coord(38-Xc,-6,I*0.1,20+Yc,7,G,Symbol), coord(42-Xc,4,I*0.1,18+Yc,9,G,Symbol), coord(38-Xc,-3,I*0.1,18+Yc,9,G,Symbol), coord(41-Xc,5,I*0.1,21+Yc,5,G,Symbol), coord(39-Xc,-5,I*0.1,21+Yc,5,G,Symbol), coord(39-Xc,-2,I*0.1,18+Yc,11,G,Symbol), sleep(Sleep) end foreach. clauses run():- init(), FSleep=15, setConsoleTitle("Happy New Year"), %A circle that will contain the characters ellipse(18,11,40,12,"*",0), vpi::alarm(2), % Three arc(5,4,40,7,-0.25,0.40,"$",FSleep), arc(7,5,40,16,-0.43,0.25,"$",FSleep), sleep(750), % Erasing 'three' % To erase something we replace it by the same figure formed by blank spaces arc(5,4,40,7,-0.25,0.40," ",FSleep), arc(7,5,40,16,-0.43,0.25," ",FSleep), vpi::alarm(2), % Two arc(7,4,40,7,-0.1,0.50,"$",FSleep), line(location(34,18),location(46,9),"$",FSleep), line(location(33,19),location(48,19),"$",FSleep), sleep(750), % Erasing 'two' arc(7,4,40,7,-0.1,0.50," ",0), line(location(34,18),location(46,9)," ",FSleep), line(location(33,19),location(48,19)," ",FSleep), vpi::alarm(2), % One line(location(33,11),location(43,5),"$",FSleep), line(location(43,6),location(43,19),"$$",FSleep), sleep(750), % Erasing 'one' line(location(33,11),location(43,5)," ",FSleep), line(location(43,6),location(43,19)," ",FSleep), vpi::alarm(2), % Zero ellipse(9,7,40,12,"$$",FSleep), sleep(200), % Erasing the initial circle ellipse(18,11,40,12," ",0), % Erasing 'zero' ellipse(9,7,40,12," ",0), LengthOfPhraseList = convert(unsigned,length(phraseList)), vpi::alarm(3), /* Infinite cycle that draws fireworks and writes random congratulation-phrases in a random place */ std::repeat(), Xc=random(11), Yc=random(5), G=4+random(3), /* The first time a congratulation-phrase appears (all in all one phrase exists during three fireworks) */ if i=0 then setLocation(location(xp,yp)), phrase:=nth(convert(positive,n),phraseList) end if, /* The last time the current phrase appears; it is replaced by a string of blank spaces. Then new random location is chosen and a new congratulation-phrase is written */ if i mod 3=0, i<>0 then setLocation(location(xp,yp)), write(string::create(55," ")), xp:=convert(unsigned16,random(50)), yp:=convert(unsigned16,random(42)), setLocation(location(xp,yp)), phrase:=nth(convert(positive,n),phraseList), write(phrase) % Not the first or the last time the current phrase appears else setLocation(location(xp,yp)), write(phrase) end if, i:=i+1, n:=random(LengthOfPhraseList), % Drawing a firework firework(true,Xc,Yc,G,30," "), % Erasing the firework firework(false,Xc,Yc,G,3," "), fail; _=readLine(), succeed(). end implement main goal mainExe::run(main::run).