Guest User

Untitled

a guest
Apr 23rd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.73 KB | None | 0 0
  1. {$R-}
  2.  
  3. uses crt;
  4. type Palette = Array[0..256*3] of byte;
  5. procedure Pall(VAR p:palette); ASSEMBLER;
  6.  
  7.    ASM
  8.       MOV DX,3C8h
  9.       XOR AX,AX
  10.       OUT DX,AL
  11.       INC DX
  12.       MOV CX,768
  13.       PUSH DS
  14.       LDS SI,p
  15.    @@l:
  16.        OUTSB
  17.        LOOP @@l
  18.       POP DS
  19.    END;
  20.  
  21. procedure SetVga;assembler;
  22. asm
  23.      MOV     AX,13h
  24.      INT     10h
  25. end;
  26.  
  27. procedure testo;assembler;
  28. ASM
  29.    MOV     AX,3
  30.    INT     10h
  31. END;
  32.  
  33. procedure punto(x,y:integer;col:byte);assembler;
  34. asm
  35.         mov ax,$a000
  36.         mov es,ax
  37.         mov cx,y
  38.         shl y,8
  39.         shl cx,6
  40.         add cx,x
  41.         add cx,y
  42.         mov di,cx
  43.         mov al,col
  44.         stosb
  45. end;
  46.  
  47. procedure fireline;                                
  48. var i:integer;
  49.     delta:integer;
  50. begin
  51.      for i:=320 downto 0 do
  52.      begin
  53.           if random<0.1 then delta:=random(10)*190;
  54.           mem[$a000:i+64960]:=delta;
  55.           mem[$a000:i+64640]:=delta;
  56.      end;
  57. end;
  58.  
  59. Function getmed(x,y:integer):byte;
  60. var med:byte;
  61. begin
  62.      med:=(mem[$a000:x+1+y*320]+mem[$a000:x-1+y*320]+mem[$a000:x+(y+1)*320]) div 3;
  63.      if (not(med<1)) then                            {Faccio la media dei punti che stanno atorno a x,y}
  64.      getmed:=med-1                                   {e se è minore di 1 non la decremento}
  65.      else getmed:=med;
  66. end;
  67.  
  68.  
  69. procedure ret(x,y,x1,y1:integer);
  70. var i,j:longint;
  71.  
  72. begin
  73.      for j:=y1 downto y do
  74.      for i:=x to x1 do
  75.      punto(i,j,getmed(i,j));
  76. end;
  77.  
  78. Procedure PhongPal(rosso,verde,blu,luce,riflesso,ambiente:real);{Procedura che calcola le palette secondo la formula di phong}
  79. var tmp,i:real;                                          
  80.     d:integer;
  81.     col:palette;
  82. Function Pow(base:real;esponente:integer):real;                      {Funzione annidata che calcola la potenza di un numero}
  83. var i:integer;
  84.     p:real;
  85. begin
  86.      p:=base;
  87.      for i:=1 to esponente do p:=p*base;
  88.      pow:=p;
  89. end;
  90.  
  91. begin
  92.      for d:=0 to 255 do
  93.      begin
  94.           i:=cos((255-d)/512*3.14159);
  95.           tmp:=rosso*ambiente/63+rosso*i+pow(i,round(riflesso))*luce;
  96.           if tmp>63 then tmp:=63;
  97.           col[d*3]:=round(tmp);
  98.           tmp:=verde*ambiente/63+verde*i+pow(i,round(riflesso))*luce;
  99.           if tmp>63 then tmp:=63;
  100.           col[d*3+1]:=round(tmp);
  101.           tmp:=blu*ambiente/63+blu*i+pow(i,round(riflesso))*luce;
  102.           if tmp>63 then tmp:=63;
  103.           col[d*3+2]:=round(tmp);
  104.      end;
  105.     pall(col);
  106. end;
  107.  
  108. var i:integer;
  109.     t:char;
  110. begin
  111.     setvga;
  112.     phongpal(128,20,0,255,5,0);
  113.     repeat
  114.           fireline;
  115.           ret(0,150,320,202);
  116.           if keypressed then t:=readkey;
  117.     until t=#27;
  118.     t:='#';
  119.     testo;
  120. end.
  121.  
  122.  
  123. {Numa}
Add Comment
Please, Sign In to add comment