Advertisement
Guest User

Checkers processing

a guest
Jun 17th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.43 KB | None | 0 0
  1. import processing.svg.*;
  2.  
  3. int x = 0;
  4. int y = 0;
  5. int z = 0;
  6. color RED = color(255, 0, 0);
  7. color WHITE = color(255, 255, 255);
  8. color BLACK = color(0, 0, 0);
  9. int wr = 100;
  10. circle[] r1 = {new circle (wr/2 + wr, wr/2, wr, RED, BLACK),
  11.   new circle (wr/2 + wr*3, wr/2, wr, RED, BLACK),
  12.   new circle (wr/2 + wr*5, wr/2, wr, RED, BLACK),
  13.   new circle (wr/2 + wr*7, wr/2, wr, RED, BLACK)};
  14.  
  15. circle[] r2 = {new circle (wr/2, wr*1.5, wr, RED, BLACK),
  16.   new circle (wr/2 + wr*2, wr*1.5, wr, RED, BLACK),
  17.   new circle (wr/2 + wr*4, wr*1.5, wr, RED, BLACK),
  18.   new circle (wr/2 + wr*6, wr*1.5, wr, RED, BLACK)};
  19.  
  20. circle[] r3 = {new circle (wr/2 + wr, wr*2.5, wr, RED, BLACK),
  21.   new circle (wr/2 + wr*3, wr*2.5, wr, RED, BLACK),
  22.   new circle (wr/2 + wr*5, wr*2.5, wr, RED, BLACK),
  23.   new circle (wr/2 + wr*7, wr*2.5, wr, RED, BLACK)};    
  24.  
  25. circle[] b1 = {new circle (wr/2, wr*5.5, wr, BLACK, WHITE),
  26.   new circle (wr/2 + wr*2, wr*5.5, wr, BLACK, WHITE),
  27.   new circle (wr/2 + wr*4, wr*5.5, wr, BLACK, WHITE),
  28.   new circle (wr/2 + wr*6, wr*5.5, wr, BLACK, WHITE)};  
  29.  
  30. circle[] b2 = {new circle (wr/2 + wr, wr*6.5, wr, BLACK, WHITE),
  31.   new circle (wr/2 + wr*3, wr*6.5, wr, BLACK, WHITE),
  32.   new circle (wr/2 + wr*5, wr*6.5, wr, BLACK, WHITE),
  33.   new circle (wr/2 + wr*7, wr*6.5, wr, BLACK, WHITE)};
  34.  
  35. circle[] b3 = {new circle (wr/2, wr*7.5, wr, BLACK, WHITE),
  36.   new circle (wr/2 + wr*2, wr*7.5, wr, BLACK, WHITE),
  37.   new circle (wr/2 + wr*4, wr*7.5, wr, BLACK, WHITE),
  38.   new circle (wr/2 + wr*6, wr*7.5, wr, BLACK, WHITE)};
  39.  
  40.  
  41.  
  42.  
  43.  
  44. void setup() {
  45.   //TODO: ako size-a deleno na 8 ne dava int da ne se puska
  46.   background(WHITE);
  47.   size(800, 800);
  48.  
  49.   println(dist(r2[0].coorX, r2[0].coorY, r3[0].coorX, r3[0].coorY));
  50.  
  51.  
  52.  
  53.  
  54.   starting_table();
  55. }
  56. void draw () {
  57.   if (keyPressed && key == 'r') {
  58.     starting_table();
  59.   }
  60. }
  61. void mousePressed() {
  62.   r2[1].move_cherveni();
  63. }
  64.  
  65. class circle {
  66.   float coorX;
  67.   float coorY;
  68.   float radius;
  69.   color c;
  70.   color b;
  71.  
  72.   circle (float tempCoorX, float tempCoorY, float tempRadius, color tempC, color tempB ) {
  73.     coorX = tempCoorX;
  74.     coorY = tempCoorY;
  75.     radius = tempRadius;
  76.     c = tempC;
  77.     b = tempB;
  78.   }
  79.  
  80.   void draw_ellipse () {
  81.     fill(c);
  82.     stroke(b);
  83.     ellipse(coorX, coorY, radius, radius);
  84.   }
  85.  
  86.   void move_cherveni() {
  87.     /**println("X is:",coorX);
  88.      println("Yis:",coorY);
  89.      if (mousePressed && dist(mouseX,mouseY,coorX,coorY) < radius) {
  90.      println("ivan e pich");
  91.      println("ivan e golqm pich");
  92.      // fill(#ADADAD, 20);
  93.      
  94.      }**/
  95.     can_move();
  96.  
  97.     if (coorY == height - radius/2) {
  98.       fill(255, 255, 255);
  99.       ellipse(coorX, coorY, radius/2, radius/2);
  100.       nagore_dqsno();
  101.       nagore_lqvo();
  102.     }
  103.   }
  104.  
  105.   void nadolu_dqsno() {
  106.     if ( mouseX>coorX-radius/2+100 && mouseX<coorX+radius/2+100 && mouseY>coorY-radius/2+100 && mouseY<coorY+radius/2+100)
  107.     {
  108.       noStroke();
  109.       fill(0, 0, 0);
  110.       ellipse(coorX, coorY, radius, radius);
  111.       println(" raboti");
  112.       coorX +=100;
  113.       coorY+=100;
  114.       draw_ellipse();
  115.     }
  116.   }
  117.   void nadolu_lqvo() {
  118.     if ( mouseX>coorX-radius/2-100 && mouseX<coorX+radius/2-100 && mouseY>coorY-radius/2+100 && mouseY<coorY+radius/2+100)
  119.     {
  120.       noStroke();
  121.       fill(0, 0, 0);
  122.       ellipse(coorX, coorY, radius, radius);
  123.       println(" raboti");
  124.       coorX -=100;
  125.       coorY+=100;
  126.       draw_ellipse();
  127.     }
  128.   }
  129.   void nagore_dqsno() {
  130.     if (mouseX>coorX+radius/2 && mouseX<coorX +radius/2 + 100 && mouseY>coorY-radius/2 -100 && mouseY<coorY-radius/2) {
  131.       noStroke();
  132.       fill(0, 0, 0);
  133.       ellipse(coorX, coorY, radius, radius);
  134.       println(" raboti");
  135.       coorX +=100;
  136.       coorY-=100;
  137.       draw_ellipse();
  138.     }
  139.   }
  140.   void nagore_lqvo() {
  141.  
  142.  
  143.     if (mouseX>coorX-radius/2-100 && mouseX<coorX -radius/2 && mouseY>coorY-radius/2 -100 && mouseY<coorY-radius/2) {
  144.       noStroke();
  145.       fill(0, 0, 0);
  146.       ellipse(coorX, coorY, radius, radius);
  147.       println(" raboti");
  148.       coorX -=100;
  149.       coorY-=100;
  150.       draw_ellipse();
  151.     }
  152.   }
  153.  
  154.  
  155.   void can_move() {
  156.    
  157.          
  158.     for (int j =0; j <=2; j++) {
  159.        for (int i = 0; i <=3; i++){
  160.  
  161.         float [] red_coorsX = {r1[i].coorX,
  162.                                r2[i].coorX,
  163.                                r3[i].coorX};
  164.         float [] red_coorsY = {r1[i].coorY,
  165.                                r2[i].coorY,
  166.                                r3[i].coorY};
  167.        
  168.         if (//dist(coorX, coorY, red_coorsX[j], red_coorsY[j] ) > 142)
  169.      // red_coorsX[j] == coorX - 100 && red_coorsY[j] == coorY -100 ||
  170.       //red_coorsX[j] == coorX - 100 && red_coorsY[j] == coorY +100 ||
  171.      // red_coorsX[j] == coorX - 100 && red_coorsY[j] == coorY +100 ||
  172.       red_coorsX[2] != coorX + 100 && red_coorsY[2] != coorY +100)
  173.         {
  174.           nadolu_dqsno();
  175.          
  176.         }
  177.     }
  178.   }
  179. }
  180. }
  181.  
  182.  
  183.  
  184.  
  185.  
  186.   void starting_table() {
  187.     int wr=width/8;
  188.     background(WHITE);
  189.  
  190.     for ( x = 0; x<width; x+=wr) {
  191.       for (y = 0; y< height; y+= wr) {
  192.         if ((z) % 2 != 0) {
  193.           fill(BLACK);
  194.         } else {
  195.           fill(WHITE);
  196.         }
  197.         z++;
  198.         rect(x, y, wr, wr);
  199.       }
  200.       z++;
  201.     }
  202.  
  203.     for (int i = 0; i<=3; i++) {
  204.       r1[i].draw_ellipse();  
  205.       r2[i].draw_ellipse();  
  206.       r3[i].draw_ellipse();  
  207.  
  208.       b1[i].draw_ellipse();  
  209.       b2[i].draw_ellipse();  
  210.       b3[i].draw_ellipse();
  211.     }
  212.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement