SHARE
TWEET

Untitled

a guest Dec 9th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. color red,green,blue;
  2. int textX=800,stage;
  3. class ball
  4. {
  5.   int x,y,speedX=0,speedY=0,Width=(int)random(200,300),iFrames;
  6.   color fill;
  7.   void movement()
  8.   {
  9.     if(iFrames==0)
  10.     {
  11.     if(y >= height-(Width/2) ||y <=0+(Width/2))speedY=-speedY;
  12.     if(x >= width-(Width/2) ||x <=0+(Width/2))speedX=-speedX;
  13.     }
  14.     else iFrames--;
  15.    
  16.     x=x+speedX;
  17.     y=y+speedY;
  18.   }
  19.   void render()
  20.   {
  21.     fill(fill);
  22.     ellipse(x,y,Width,Width);
  23.   }
  24. }
  25.  
  26. ball a = new ball();
  27. ball b = new ball();
  28. ball c = new ball();
  29. ball d = new ball();
  30.  
  31. void setup()
  32. {
  33.   size(1000,800);
  34.   red=(int)random(255);
  35.   green=(int)random(255);
  36.   blue=(int)random(255);
  37.   a.x=200;
  38.   a.y=200;
  39.   b.x=600;
  40.   b.y=200;
  41.   c.x=200;
  42.   c.y=600;
  43.   d.x=600;
  44.   d.y=600;
  45. }
  46.  
  47. void draw()
  48. {
  49.   background(red,green,blue);
  50.   fill(255);
  51.   text("julius janeliunas",textX,10);
  52.   if(stage==0)
  53.   {
  54.   if(textX>0)textX=textX-5;
  55.   else stage++;
  56.   println(stage);
  57.   }
  58.   if(stage==1)
  59.   {
  60.     a.movement();
  61.     a.render();
  62.     b.movement();
  63.     b.render();
  64.     c.movement();
  65.     c.render();
  66.     d.movement();
  67.     d.render();
  68.   }
  69.   if(dist(a.x,a.y,b.x,b.y)<a.Width/2+b.Width/2)
  70.   {
  71.     a.speedX=-a.speedX;
  72.     a.speedY=-a.speedY;
  73.     b.speedX=-b.speedX;
  74.     b.speedY=-b.speedY;
  75.     a.iFrames=10;
  76.   }
  77.   if(dist(a.x,a.y,c.x,c.y)<a.Width/2+c.Width/2)
  78.   {
  79.     a.speedX=-a.speedX;
  80.     a.speedY=-a.speedY;
  81.     c.speedX=-c.speedX;
  82.     c.speedY=-c.speedY;
  83.   }
  84.   if(dist(a.x,a.y,d.x,d.y)<a.Width/2+d.Width/2)
  85.   {
  86.     a.speedX=-a.speedX;
  87.     a.speedY=-a.speedY;
  88.     d.speedX=-d.speedX;
  89.     d.speedY=-d.speedY;
  90.   }
  91. }
  92.  
  93. void keyPressed()
  94. {
  95.   if(key=='b')
  96.   {
  97.   a.fill=#FF0000;
  98.   b.fill=#FFFF00;
  99.   c.fill=#FFFFFF;
  100.   d.fill=#000000;
  101.   }
  102.   if(keyCode==115)
  103.   {
  104.   a.speedX=(int)random(5,15);
  105.   b.speedX=(int)random(5,15);
  106.   c.speedX=(int)random(5,15);
  107.   d.speedX=(int)random(5,15);
  108.   a.speedY=(int)random(5,15);
  109.   b.speedY=(int)random(5,15);
  110.   c.speedY=(int)random(5,15);
  111.   d.speedY=(int)random(5,15);
  112.   }
  113. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top