L'instruction «DRAW» qu'utilisait la plupart des langages BASIC des ordinateurs des années 1980 était un outil très rapide pour faire des dessins, il est tout a fait dommage que de nos jours cette connaissance ce soit perdu. En revanche, voici le code Turbo Pascal effectuant un dessin de «Boule» dans «Boule & Bill»:
- Program SamplesDraw;
-
- Uses Crt,Graph;
-
- Const
- DrawS:Integer=4;
- XL:Integer=160;
- YL:Integer=100;
-
- Var
- I:Byte;
- N:String;
- Mode:(_None_,_NoTrace_,_UnMove_);
- a,b:Integer;
- xc,yc:(NoMove,Add,Sub);
-
- Function ExtractNm(S:String):Integer;
- Var
- N:String;
- a,b:Integer;
- Begin
- N:='';
- While(I<=Length(S))and(S[I] in ['0'..'9'])do Begin
- N:=N+S[I];
- Inc(I);
- End;
- If N=''Then a:=1
- Else Val(N,a,b);
- ExtractNm:=a;
- End;
-
- Function ExtractNmV(S:String):Integer;Begin
- ExtractNmV:=ExtractNm(S)*(DrawS shr 2)
- End;
-
- Procedure Line2(X,Y:Integer);Begin
- If(Mode<>_NoTrace_)Then Begin
- Case(xc)of
- Add:Inc(X,XL);
- Sub:X:=XL-X;
- End;
- Case(yc)of
- Add:Inc(Y,YL);
- Sub:Y:=YL-Y;
- End;
- If(YL=Y)and(X<XL)Then Begin
- MoveTo(X,YL);
- LineTo(XL,Y);
- End
- Else
- Begin
- MoveTo(XL,YL);
- LineTo(X,Y);
- End;
- End;
- End;
-
- Procedure SetPos(X,Y:Integer);Begin
- Case(xc)of
- Add:Inc(X,XL);
- Sub:X:=XL-X;
- End;
- Case(yc)of
- Add:Inc(Y,YL);
- Sub:Y:=YL-Y;
- End;
- If(Mode<>_UnMove_)Then Begin
- XL:=X;
- YL:=Y;
- End;
- Mode:=_None_;
- xc:=NoMove;
- yc:=NoMove;
- End;
-
-
- Procedure BasicDraw(S:String);Begin
- I:=1;Mode:=_None_;
- While I<=Length(S)do Begin
- Inc(I);
- Case S[I-1]of
- 'B':Mode:=_NoTrace_;
- 'C':SetColor(ExtractNm(S));
- 'D':Begin
- a:=ExtractNmV(S);
- Line2(XL,YL+a);
- SetPos(XL,YL+a);
- End;
- 'E':Begin
- a:=ExtractNmV(S);
- Line2(XL+a,YL-a);
- SetPos(XL+a,YL-a);
- End;
- 'F':Begin
- a:=ExtractNmV(S);
- Line2(XL+a,YL+a);
- SetPos(XL+a,YL+a);
- End;
- 'G':Begin
- a:=ExtractNmV(S);
- Line2(XL-a,YL+a);
- SetPos(XL-a,YL+a);
- End;
- 'H':Begin
- a:=ExtractNmV(S);
- Line2(XL-a,YL-a);
- SetPos(XL-a,YL-a);
- End;
- 'L':Begin
- a:=ExtractNmV(S);
- Line2(XL-a,YL);
- SetPos(XL-a,YL);
- End;
- 'M':Begin
- If S[I]in['+','-']Then Begin
- If S[I]='+'Then xc:=Add else xc:=Sub;
- Inc(I);
- End;
- a:=ExtractNm(S);
- If S[I]=','Then Begin
- Inc(I);
- If S[I]in['+','-']Then Begin
- If S[I]='+'Then yc:=Add else yc:=Sub;
- Inc(I);
- End;
- b:=ExtractNm(S);
- End
- Else
- b:=YL;
- Line2(a,b);
- SetPos(a,b);
- End;
- 'N':Mode:=_UnMove_;
- 'R':Begin
- a:=ExtractNmV(S);
- Line2(XL+a,YL);
- SetPos(XL+a,YL)
- End;
- 'U':Begin
- a:=ExtractNmV(S);
- Line2(XL,YL-a);
- SetPos(XL,YL-a)
- End;
- ' ',';':;{C'est 2 caractŠres ne change rien en soit, donc...pas d'arrˆt!}
- Else Exit;
- End
- End
- End;
-
- Var
- PiloteGraph:Integer;
- ModeGraph:Integer;
-
- BEGIN
- PiloteGraph:=Detect;
- ModeGraph:=CGAC0;
- InitGraph(PiloteGraph,ModeGraph,'');
- xc:=NoMove;yc:=NoMove;
- BasicDraw('BM160,59M163,58M168,60M172,61M175,64M176,67M176,68M173,72 '+
- 'M168,75M164,76M160,77M156,75M152,73M150,72M149,68M151,63M157,59 '+
- 'M160,59');
- BasicDraw('BM174,69M176,72M177,76M176,78M175,80M173,83M169,78M165,85 '+
- 'M166,85M163,86M160,87M152,85M148,86M144,85M139,85M137,83');
- BasicDraw('BM150,72M148,77');
- BasicDraw('BM135,83M139,84BM135,80M139,81');
- BasicDraw('BM152,85M152,88M150,89M150,92');
- BasicDraw('BM148,77M147,72M144,70M141,67M137,62M134,63M139,68M141,70M144,71');
- BasicDraw('BM134,63M139,64BM138,62M131,66M130,64M135,59M133,59M129,61 '+
- 'M123,63M122,67M123,69M121,66M122,61BM118,64M117,66M120,70M122,71 '+
- 'M121,74M120,77M122,82M124,85M125,81M121,92M120,94M116,96M112,98 '+
- 'M108,100M104,102M102,104M99,107M97,111M97,114M98,116M100,120');
- BasicDraw('BM100,120M102,122M104,124M108,126M112,127M116,126M120,123 '+
- 'M123,120M124,116M126,112M128,104M129,96M130,91M129,90M128,85M130,83 '+
- 'BM129,90 M134,91M136,92M141,89M144,91M146,93M142,94M148,99');
- BasicDraw('BM148,99M152,95M157,93M156,91M151,92M146,93');
- BasicDraw('BM144,80M146,77BM144,77M146,74M144,73BM140,78M142,77BM141,78E0 '+
- 'BM140,76M142,76M141,75M139,74M139,76BM137,77M135,75');
- BasicDraw('BM141,75M139,72M136,71M134,71M133,72M134,73BM138,70M137,69 '+
- 'M138,67BM131,74M128,72M128,69M131,67M133,69M131,70M131,72M131,74');
- BasicDraw('BM138,90M139,92M138,97M135,101M132,107M130,109M130,113M133,117 '+
- 'M136,118M142,116M144,114M148,111');
- BasicDraw('BM148,99M147,103M147,106BM150,101M147,106M148,109M148,111 '+
- 'M152,113M155,112M153,108BM155,112M160,113M163,109M164,108BM157,93 '+
- 'M163,94M168,96');
- BasicDraw('BM168,96M166,100M164,99M163,109M168,112M171,112M174,108M175,102 '+
- 'M180,98M176,95M172,93M170,93M168,96BM175,107M179,112M182,115M183,120 '+
- 'M182,123M181,126M180,128');
- BasicDraw('BM179,98M180,101M177,102BM180,101M181,105M181,107M179,109M175,108');
- BasicDraw('BM176,123M175,123M175,124M177,124M178,122');
- BasicDraw('BM177,126M174,127M168,126M165,120M164,116M164,114');
- BasicDraw('BM151,113M152,115M151,120M150,123');
- BasicDraw('BM148,123M157,121M162,122M165,123M164,126M163,128M157,132 '+
- 'M172,129M177,130M180,133M176,139M167,142M160,144M146,141M144,138 '+
- 'M147,134M144,131M146,125M148,123');
- BasicDraw('BM177,136M172,132BM176,140M172,136');
- BasicDraw('BM145,128M141,126M143,123M141,125M141,120M140,125M139,120 '+
- 'M139,124M135,123M137,126M135,131M136,134M140,136M144,137');
- BasicDraw('BM182,123M185,124M184,126M182,127M187,130M187,133M183,137 M176,139');
- Repeat Until KeyPressed;
- END.
Voici en terminant un exemple du résultat de se petit programme :
Dernière mise à jour : Dimanche, le 17 janvier 2016