Advertisement
Guest User

Untitled

a guest
Jan 6th, 2013
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.     <meta charset="UTF-8">     
  5.         <title>...</title>
  6.         <script src="raphael.js" type="text/javascript" charset="utf-8"></script>
  7.     </head>
  8.    
  9.     <style>
  10.         canvas {border:1px solid #eee;}
  11.         .grey {background:#ccc; margin:2px; border:1px solid #aaa; padding:10px;}
  12.         #demo strong {font-size:0.8em; color:#333;}
  13.         #demo strong span {color:#663399}
  14.     </style>
  15.    
  16.     <body>
  17.         <canvas id="myCanvas" width="500" height="500" >
  18.             tresc alternatywna
  19.         </canvas>
  20.         <script>
  21.        
  22.         var canvas = document.getElementById('myCanvas');
  23.         var c = canvas.getContext('2d');
  24.         var kola = [];
  25.         var ilekul = 3;
  26.         function kolo(can, _x, _y, _speed, _id)
  27.         {
  28.             this.x = _x;
  29.             this.y = _y;
  30.             this.id = _id;
  31.             this.speed = _speed;
  32.             this.przex = _speed;
  33.             this.przey = _speed;
  34.            
  35.             this.drawkolo = function() {
  36.                 can.beginPath();
  37.                 can.fillStyle = 'black';
  38.                 can.arc(this.x, this.y, 40, 0, Math.PI * 2, true);
  39.                 can.closePath;
  40.                 can.fill();
  41.             }
  42.            
  43.                    
  44.            
  45.             this.ruch = function() {
  46.                
  47.                 kolizje(this); 
  48.                
  49.                 this.x += this.przex;
  50.                 this.y += this.przey;
  51.                 this.drawkolo();
  52.             }
  53.         }
  54.        
  55.         function kolizje(kol)
  56.         {
  57.                
  58.                
  59.                 /*  for (i=0; i<kola.length; i++) {            
  60.                         if( i != kol.id)
  61.                         {
  62.                             if(Math.sqrt(Math.pow(kol.x - kola[i].x , 2) + Math.pow(kol.y - kola[i].y , 2)) <= 80) {
  63.                                
  64.                                 kol.przex -= kola[i].przex;
  65.                             }
  66.                         }
  67.                            
  68.                    
  69.                    
  70.                     } */
  71.                
  72.                
  73.                
  74.  
  75.  
  76.                 if (kol.x < 40 || kol.x > 460) {
  77.                     kol.przex = -kol.przex;
  78.                 }
  79.                 if (kol.y < 40 || kol.y > 460) {
  80.                     kol.przey = -kol.przey;
  81.                 }
  82.  
  83.                
  84.         }              
  85.        
  86.        
  87.         function draw() {
  88.             c.clearRect(0, 0, 500, 500);
  89.             for (i=0; i<kola.length; i++) {            
  90.            
  91.                 kola[i].ruch();
  92.             }
  93.         }
  94.        
  95.  
  96.         for (i=0; i<ilekul; i++) {
  97.             var new_x = 40 + Math.random()*420;
  98.             var new_y = 40 + Math.random() * 420;
  99.             var new_speed = Math.round(1 + Math.random()*3);
  100.             kola.push(new kolo(c, new_x, new_y, new_speed, i));
  101.         }
  102.            
  103.             setInterval("draw()", 10);
  104.    
  105.         </script>
  106.     </body>
  107. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement