Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Pascal - Grafica
Forum - Pascal - Grafica

Avatar
Vrael (Normal User)
Newbie


Messaggi: 4
Iscritto: 07/02/2007

Segnala al moderatore
Postato alle 13:32
Mercoledì, 07/02/2007
ciao ragazzi....ho un problema, chi mi può dire come si fa a creare un programma in cui si vedono due sfere che si muovono in linea retta e si urtano tornando indietro???

Nel senso:

SFERA===><===SFERA.......si urtano e tornano indietro......:-|

PM Quote
Avatar
nikipe_silver (Founder Member)
Expert


Messaggi: 339
Iscritto: 20/09/2005

Segnala al moderatore
Postato alle 16:33
Mercoledì, 07/02/2007
leggiti qualcosa sulla libreria graph...

PM Quote
Avatar
Maury91 (Member)
Expert


Messaggi: 531
Iscritto: 18/09/2006

Segnala al moderatore
Postato alle 16:55
Mercoledì, 07/02/2007
Dipende, se vuoi vedere due sfere o ti accontenti di 2 cerchi.

Perchè il vecchio pascal che io sappia non ha liberie per il 3d ma solo per il 2d.
Potresti usare la liberia Graph.
fai cosi, negli uses aggiungi "graph".
alle variabili aggiungi : dr,md : integer;
poi quando vuoi che parta la grafica inserisci nel programma :

dr := detect;
initgraph(dr,md,'');

per disegnare un cerchio puoi usare :
circle(x,y,raggio);

P.S. :
Vedi di mettere i driver nella stessa directory che stai usando. (I file *.bgi)

PM Quote
Avatar
Il Totem (Admin)
Guru^2


Messaggi: 3635
Iscritto: 24/01/2006

Segnala al moderatore
Postato alle 18:26
Mercoledì, 07/02/2007
Guarda questo programma, sulla grafica: fa muovere una palla in molti modi, tra cui rimbalzare.
Codice sorgente - presumibilmente Delphi

  1. program palla;
  2. uses crt,graph,giobe;
  3. var Gd,Gm:integer;
  4.     I,X,Y,x1,y1,x2,y2:integer;
  5.     R1,R2,L1,L2,R3,L3,R4,L4:integer;
  6.     R5,R6,R7,R8,L5,L6,L7,L8:integer;
  7.  
  8. procedure giu(G:integer);
  9. begin
  10.     repeat
  11.     SetColor(0);
  12.     Circle(X,Y,30);
  13.     Y:=Y+1;
  14.     SetColor(3);
  15.     Circle(X,Y,30);
  16.     delay(800);
  17.     until Y=G;
  18. end;
  19.  
  20. procedure su(G:integer);
  21. begin
  22.     repeat
  23.     SetColor(0);
  24.     Circle(X,Y,30);
  25.     Y:=Y-1;
  26.     SetColor(3);
  27.     Circle(X,Y,30);
  28.     delay(800);
  29.     until Y=G;
  30. end;
  31.  
  32. begin
  33.     clrscr;
  34.     VIAcur;
  35.     gotoxy(60,10);
  36.     write('Premere invio per iniziare');
  37.     InitGraph(Gd,Gm,'');
  38.     if GraphResult <> grOk then
  39.       Halt(1);
  40.     SetColor(3);
  41.     X:=200;
  42.     Y:=100;
  43.     Line(100,331,300,331);
  44.     Circle(X,Y,30);
  45.     delay(100);
  46.     Line(400,100,600,100);
  47.     Line(400,300,600,300);
  48.     Line(400,100,400,300);
  49.     Line(600,100,600,300);
  50.     readln;
  51.     giu(300);
  52.     su(100);
  53.     I:=100;
  54.     repeat                           (*Fase 1*)
  55.     I:=I+20;
  56.     giu(300);
  57.     su(I);
  58.     until (I>=280) or (keypressed);
  59.     giu(300);                          (*Fase 2*)
  60.     su(200);
  61.     repeat
  62.     SetColor(0);
  63.     Circle(X,Y,30);
  64.     X:=X-1;
  65.     SetColor(3);
  66.     Circle(X,Y,30);
  67.     delay(800);
  68.     until X=150;
  69.     x1:=100; x2:=300;
  70.     y1:=331; y2:=331;
  71.     repeat
  72.     SetColor(0);
  73.     Line(x1,y1,x2,y2);
  74.     x1:=x1+1;
  75.     x2:=x2+2;
  76.     SetColor(3);
  77.     Line(x1,y1,x2,y2);
  78.     Delay(800);
  79.     until x2=400;
  80.     repeat
  81.     SetColor(0);
  82.     Line(x1,y1,x2,y2);
  83.     y1:=y1-1;
  84.     y2:=y2-1;
  85.     SetColor(3);
  86.     Line(x1,y1,x2,y2);
  87.     delay(800);
  88.     until y2=300;
  89.     repeat
  90.     SetColor(0);
  91.     Line(x1,y1,x2,y2);
  92.     y1:=y1-1;
  93.     SetColor(3);
  94.     Line(x1,y1,x2,y2);
  95.     delay(800);
  96.     until y1=231;
  97.     x1:=400; x2:=400;
  98.     y1:=200; y2:=300;
  99.     repeat
  100.     SetColor(0);
  101.     Line(x1,y1,x2,y2);
  102.     x2:=x2-2;
  103.     y2:=y2-1;
  104.     SetColor(3);
  105.     Line(x1,y1,x2,y2);
  106.     delay(800);
  107.     until x2=200;
  108.     repeat
  109.     SetColor(0);
  110.     Line(x1,y1,x2,y2);
  111.     y2:=y2-1;
  112.     SetColor(3);
  113.     Line(x1,y1,x2,y2);
  114.     delay(800);
  115.     until y2=131;
  116.     repeat
  117.     SetColor(0);
  118.     Circle(X,Y,30);
  119.     X:=X+4;
  120.     Y:=Y+1;
  121.     SetColor(3);
  122.     Circle(X,Y,30);
  123.     delay(1100);
  124.     until Y=270;
  125.     Y:=269; X:=400+29;
  126.     x1:=150; x2:=400;
  127.     y1:=231; y2:=300;
  128.     repeat
  129.     SetColor(0);
  130.     Line(x1,y1,x2,y2);
  131.     y1:=y1+1;
  132.     SetColor(3);
  133.     Line(x1,y1,x2,y2);
  134.     delay(800);
  135.     until y1=300;
  136.     repeat
  137.     PutPixel(x1,y1,0);
  138.     x1:=x1+1;
  139.     PutPixel(x1,y1,0);
  140.     delay(800);
  141.     until x1=400;
  142.     x1:=400; x2:=200;
  143.     y1:=200; y2:=131;
  144.     repeat
  145.     SetColor(0);
  146.     Line(x1,y1,x2,y2);
  147.     y2:=y2+1;
  148.     SetColor(3);
  149.     Line(x1,y1,x2,y2);
  150.     delay(800);
  151.     until y2=300;
  152.     repeat
  153.     SetColor(0);
  154.     Line(x1,y1,x2,y2);
  155.     x2:=x2+1;
  156.     SetColor(3);
  157.     Line(x1,y1,x2,y2);
  158.     delay(800);
  159.     until x2=400;
  160.     I:=0;                      (*Fase 3*)
  161.     repeat
  162.       I:=I+1;
  163.       repeat
  164.       SetColor(0);
  165.       Circle(X,Y,30);
  166.       X:=X+1;
  167.       SetColor(3);
  168.       Circle(X,Y,30);
  169.       delay(800);
  170.       until X=600-31;
  171.       Line(400,100,400,300);
  172.       repeat
  173.       SetColor(0);
  174.       Circle(X,Y,30);
  175.       Y:=Y-1;
  176.       SetColor(3);
  177.       Circle(X,Y,30);
  178.       delay(800);
  179.       until Y=131;
  180.       repeat
  181.       SetColor(0);
  182.       Circle(X,Y,30);
  183.       X:=X-1;
  184.       SetColor(3);
  185.       Circle(X,Y,30);
  186.       delay(800);
  187.       until X=431;
  188.       repeat
  189.       SetColor(0);
  190.       Circle(X,Y,30);
  191.       Y:=Y+1;
  192.       SetColor(3);
  193.       Circle(X,Y,30);
  194.       delay(800);
  195.       until Y=300-31;
  196.     until I=2;
  197.     x1:=400; x2:=600;
  198.     y1:=100; y2:=100;
  199.     repeat
  200.     SetColor(0);
  201.     Line(x1,y1,x2,y2);
  202.     y1:=y1-1;
  203.     y2:=y2-1;
  204.     SetColor(3);
  205.     Line(x1,y1,x2,y2);
  206.     delay(800);
  207.     until y1=1;
  208.     repeat
  209.     x1:=x1-1;
  210.     x2:=x2+1;
  211.     if x1>0 then
  212.       PutPixel(x1,y1,3);
  213.     if x2<GetMaxX then
  214.       PutPixel(x2,y2,3);
  215.       delay(800);
  216.     until x1=1;
  217.     x1:=400; x2:=600;
  218.     y1:=300; y2:=300;
  219.     repeat
  220.     SetColor(0);
  221.     Line(x1,y1,x2,y2);
  222.     y1:=y1+1;
  223.     y2:=y2+1;
  224.     SetColor(3);
  225.     Line(x1,y1,x2,y2);
  226.     delay(800);
  227.     until y1=GetMaxY;
  228.     repeat
  229.     x1:=x1-1;
  230.     x2:=x2+1;
  231.     if x1>0 then
  232.       PutPixel(x1,y1,3);
  233.     if x2<GetMaxX then
  234.       PutPixel(x2,y2,3);
  235.     delay(800);
  236.     until x1=1;
  237.     x1:=400; x2:=400;
  238.     y1:=100; y2:=300;
  239.     repeat
  240.     SetColor(0);
  241.     Line(x1,y1,x2,y2);
  242.     x1:=x1-1;
  243.     x2:=x2-1;
  244.     SetColor(3);
  245.     Line(x1,y1,x2,y2);
  246.     delay(800);
  247.     until x1=1;
  248.     x1:=1;
  249.     repeat
  250.     y1:=y1-1;
  251.     y2:=y2+1;
  252.     if y1>0 then
  253.       PutPixel(x1,y1,3);
  254.     if y2<GetMaxY then
  255.       PutPixel(x2,y2,3);
  256.     delay(800);
  257.     until y2=GetMaxY;
  258.     x1:=600; x2:=600;
  259.     y1:=100; y2:=300;
  260.     repeat
  261.     SetColor(0);
  262.     Line(x1,y1,x2,y2);
  263.     x1:=x1+1;
  264.     x2:=x2+1;
  265.     SetColor(3);
  266.     Line(x1,y1,x2,y2);
  267.     delay(800);
  268.     until x1=GetMaxX;
  269.     repeat
  270.     y1:=y1-1;
  271.     y2:=y2+1;
  272.     if y1>0 then
  273.       PutPixel(x1,y1,3);
  274.     if y2<GetMaxY then
  275.       PutPixel(x2,y2,3);
  276.     delay(800);
  277.     until y2=GetMaxY;
  278.     repeat
  279.     SetColor(0);
  280.     Circle(X,Y,30);
  281.     X:=X-1;
  282.     SetColor(3);
  283.     Circle(X,Y,30);
  284.     delay(800);
  285.     until X=GetMaxX div 2;
  286.     repeat
  287.     SetColor(0);
  288.     Circle(X,Y,30);
  289.     Y:=Y-1;
  290.     SetColor(3);
  291.     Circle(X,Y,30);
  292.     delay(800);
  293.     until Y=GetMaxY div 2;
  294.     R1:=0; L1:=1;
  295.     repeat
  296.     R1:=R1+1;
  297.     PutPixel(R1,L1,0);
  298.     delay(800);
  299.     until R1=GetMaxX;
  300.     repeat
  301.     L1:=L1+1;
  302.     PutPixel(R1,L1,0);
  303.     delay(800);
  304.     until L1=GetMaxY;
  305.     repeat
  306.     R1:=R1-1;
  307.     PutPixel(R1,L1,0);
  308.     delay(800);
  309.     until R1=1;
  310.     repeat
  311.     L1:=L1-1;
  312.     PutPixel(R1,L1,0);
  313.     delay(800);
  314.     until L1=1;
  315.     R1:=X; L1:=Y;
  316.     R2:=X; L2:=Y;                      (*Fase 4*)
  317.     repeat
  318.     SetColor(0);
  319.     Circle(R1,L1,30);
  320.     Circle(R2,L2,30);
  321.     R1:=R1+1;
  322.     R2:=R2-1;
  323.     SetColor(3);
  324.     Circle(R1,L1,30);
  325.     Circle(R2,L2,30);
  326.     delay(800);
  327.     until R1=GetMaxX-31;
  328.     repeat
  329.     SetColor(0);
  330.     Circle(R1,L1,30);
  331.     CIrcle(R2,L2,30);
  332.     L1:=L1-1;
  333.     L2:=L2+1;
  334.     SetColor(3);
  335.     Circle(R1,L1,30);
  336.     Circle(R2,L2,30);
  337.     delay(800);
  338.     until L2=GetMaxY-31;
  339.     repeat
  340.     SetColor(0);
  341.     Circle(R1,L1,30);
  342.     CIrcle(R2,L2,30);
  343.     R1:=R1-1;
  344.     R2:=R2+1;
  345.     SetColor(3);
  346.     Circle(R1,L1,30);
  347.     Circle(R2,L2,30);
  348.     delay(800);
  349.     until R2=GetMaxX div 2;
  350.     PutPixel(1,L2,3);
  351.     repeat
  352.     SetColor(0);
  353.     Circle(R1,L1,30);
  354.     CIrcle(R2,L2,30);
  355.     L1:=L1+1;
  356.     L2:=L2-1;
  357.     SetColor(3);
  358.     Circle(R1,L1,30);
  359.     Circle(R2,L2,30);
  360.     PutPixel(R1,GetMaxY,3);
  361.     PutPixel(R2,GetMaxY,3);
  362.     delay(800);
  363.     until L2=GetMaxY div 2;
  364.     X:=GetMaxX div 2; Y:=GetMaxY div 2;
  365.     R1:=X; R2:=X; R3:=X; R4:=X;
  366.     L1:=Y; L2:=Y; L3:=Y; L4:=Y;                     (*Fase 5*)
  367.     repeat
  368.     setColor(0);
  369.     Circle(R1,L1,30);  Circle(R2,L2,30);
  370.     Circle(R3,L3,30);  Circle(R4,L4,30);
  371.     if L1>1 then
  372.       begin
  373.       L1:=L1-1; L3:=L3+1;
  374.       end
  375.     else
  376.       begin
  377.       L1:=1; L3:=1;
  378.       end;
  379.     R2:=R2+1; R4:=R4-1;
  380.     SetColor(3);
  381.     Circle(R1,L1,30); Circle(R2,L2,30);
  382.     Circle(R3,L3,30); Circle(R4,L4,30);
  383.     delay(800);
  384.     until R2=GetMaxX-31;
  385.     SetColor(0);
  386.     Y:=0; X:=1;                          (*Fase Finale*)
  387.     repeat
  388.     Y:=Y+1;
  389.     Line(X,Y,GetMaxX,Y);
  390.     until Y=GetMaxY;
  391.     SetColor(3);
  392.     x1:=1; y1:=GetMaxY;
  393.     x2:=1; y2:=1;
  394.     Line(x1,y1,x2,y2);
  395.     repeat
  396.     x2:=x2+1;
  397.     Line(x1,y1,x2,y2);
  398.     delay(800);
  399.     until x2=GetMaxX;
  400.     repeat
  401.     y2:=y2+1;
  402.     Line(x1,y1,x2,y2);
  403.     delay(800);
  404.     until y2=GetMaxY;
  405.     CloseGraph;
  406.     RestoreCrtMode;
  407.     write('Fine.');
  408.     readln
  409. end.


PM Quote