Advertisement
Rafpast

Everythink 2

Jul 28th, 2020
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 25.37 KB | None | 0 0
  1. //everythink
  2. import java.util.regex.Matcher;
  3. import java.util.regex.Pattern;
  4. import java.util.Random;
  5. import controlP5.*;
  6.  
  7. Random randa = new Random();
  8. ControlP5 cp5;
  9.  
  10.  
  11. int mode = 1;//1 - gravitation , 2 - pendulum, 3 - programs on whole screen
  12. boolean field = false;//true -  central field , false -  homogeneous field
  13. boolean pendul = false;//true - single pendulum , false - double pendulum
  14. boolean wholeScreen = false;// true - Lisajous table, false - nBonaci Sequence
  15. boolean information = false;
  16. boolean startMenu = true;
  17. boolean stopStart = false;//true - everything is working , false - everything is stoped
  18. boolean isMouseOver = false;
  19. boolean centralAction = false, homogeneousAction = false, singleAction = false, doubleAction = false, lisajousAction = false, nBonaciAction = false, strangeCirclesAction = false;
  20. boolean[] changePositionByMouse = new boolean[5];
  21. boolean[] contextMenuOpenByMouse = new boolean[5];
  22. long StartedMillis = 0;
  23. String buttonName;
  24. char shortcutCentralField = 'V', shortcutHomogenField = 'F', shortcutSinglePendulum = 'P', shortcutDoublePendulum = 'D', shortcutLisajousTable = 'L', shortcutBonaciSeqense = 'N', shortcutStrangeCircles = 'C';
  25. int control = 10, current, control2 = control, i, control3 = control2+1, ile = 1, ile2 = ile, ile_pend =1, ile_pend2 = ile_pend, pozX =2, pozY;
  26. int centerX = 0, centerY = 0, button_height =30, button_width = 106, he = button_height, hi = 1, pozXSet = pozX + button_width;
  27. float mass = 1000, radius = 20, density, G_const = 0.6673, total_mass = 0, a1 = 4*PI, w = 0.01;
  28. float length1, length2, mas1, mas2, a2, poz, rad = 10, angleChange_ = 0.01;
  29. float pozYSet[] = new float[2], screenSizeX = 0, screenSizeY = 0;
  30. LisajousTable table;
  31. BonaciSequence seq;
  32. StrengeCircles stren;
  33.  
  34. ArrayList<Circum> cir = new ArrayList<Circum>(control);
  35. ArrayList<pendulum> pend = new ArrayList<pendulum>(ile_pend);
  36. ArrayList<double_pendulum> doublePend = new ArrayList<double_pendulum>(ile);
  37. PVector  inic = new PVector(0.0000, 0.0000);
  38. int amo = 1000, currentIndex = 0;
  39. PFont font;
  40.  
  41. void settings() {
  42.   size(1000, 800, P2D);
  43.   //fullScreen(P2D, 1);
  44.   //screenSizeX = width;
  45.   //screenSizeY = height;
  46.   PJOGL.setIcon("icon5.png");
  47. }
  48.  
  49.  
  50. void setup() {  
  51.   //surface.setResizable(true);
  52.   //surface.setLocation(0,0);
  53.   surface.setTitle("Fizyka");
  54.   //surface.setSize(displayWidth, displayHeight);
  55.   stroke(255);
  56.   background(255);
  57.   font = createFont("arial", 20);
  58.   centerX = (width/2)  - (button_width/2);
  59.   centerY = (height/2)  - (button_height/2);
  60.   //creating individual objects
  61.   table = new LisajousTable();
  62.   seq = new BonaciSequence();
  63.   stren = new StrengeCircles( rad, angleChange_, amo);
  64.  
  65.   //creating random circles
  66.   for (int i = 0; i <control; i++)
  67.   {
  68.     mass = 10;
  69.     total_mass += mass;
  70.     radius = 10;
  71.     cir.add(new Circum(0, 0, radius, mass));
  72.     cir.get(i).velocity = new PVector(0, 0);
  73.     cir.get(i).acceleration = new PVector(0, 0);
  74.     cir.get(i).gre = new PVector(0, 0);
  75.   }
  76.   //creating a random double pendulum
  77.   for (int i = 0; i< ile; i++)
  78.   {
  79.     a1 = PI / (randa.nextFloat() + 1);
  80.     a2 = PI / (randa.nextFloat() + 3);
  81.     length1 = 350;
  82.     length2 = 200;
  83.     mas1 = 40;
  84.     mas2 = 20;
  85.     doublePend.add(new double_pendulum( a1, a2, length1, length2, mas1, mas2));
  86.   }
  87.   //creating a random pendulum
  88.   for (int i = 0; i <ile_pend; i++)
  89.   {
  90.     a1 = PI / (randa.nextFloat() + 0.5);
  91.     pend.add(new pendulum(a1));
  92.   }
  93.  
  94.  
  95.   cp5 = new ControlP5(this);
  96.  
  97.   //creating buttons
  98.  
  99.   cp5.addButton("Menu").setPosition(pozX, 2).setSize(button_width, button_height);  
  100.   cp5.addButton("Start").setPosition(centerX, centerY).setSize(200, 60).setCaptionLabel("Start");
  101.   cp5.addButton("Settings").setPosition(centerX, centerY+ 60).setSize(200, 60).setCaptionLabel("Ustawienia");
  102.   cp5.addButton("Exit").setPosition(centerX, centerY + 120).setSize(200, 60).setCaptionLabel("Wyjscie z programu");
  103.   cp5.addButton("Save").setPosition(pozXSet, 63).setSize(button_width, button_height).setCaptionLabel("Zapis").hide();
  104.   cp5.addButton("Load").setPosition(pozXSet, 63).setSize(button_width, button_height).setCaptionLabel("Odczyt").hide();
  105.   cp5.addButton("Set").setPosition(pozXSet, 63).setSize(button_width, button_height).setCaptionLabel("Ustawienia").hide();
  106.   cp5.addButton("Reset").setPosition(pozX, he * hi).setSize(button_width, button_height);
  107.   hi++;
  108.   cp5.addButton("StartStop").setPosition(pozX, he * hi).setSize(button_width, button_height).setCaptionLabel("Uruchomienie programu");
  109.   hi++;
  110.   cp5.addButton("Single").setPosition(pozX, he * hi).setSize(button_width, button_height).setCaptionLabel("Pojedyncze wahadło").setVisible(false).setValue(2);
  111.   hi++;
  112.   cp5.addButton("Dual").setPosition(pozX, he * hi).setSize(button_width, button_height).setCaptionLabel("Podwójne wahadło").setVisible(false).setValue(2);
  113.   hi++;
  114.   cp5.addButton("Homogen").setPosition(pozX, he * hi).setSize(button_width, button_height).setCaptionLabel(" Pole jednorodne").setVisible(false).setValue(1);
  115.   hi++;
  116.   cp5.addButton("Central").setPosition(pozX, he * hi).setSize(button_width, button_height).setCaptionLabel(" Pole centralne").setVisible(false).setValue(1);
  117.   hi++;
  118.   cp5.addButton("Lisajous").setPosition(pozX, he * hi).setSize(button_width, button_height).setCaptionLabel("Tablica Lisajous ").setVisible(false).setValue(3);
  119.   hi++;
  120.   cp5.addButton("Bonaci").setPosition(pozX, he * hi).setSize(button_width, button_height).setCaptionLabel("Sekwencja fibonacziego").setVisible(false).setValue(3);
  121.   hi++;
  122.   cp5.addButton("Circle").setPosition(pozX, he * hi).setSize(button_width, button_height).setCaptionLabel("Wzory").setVisible(false).setValue(4);
  123.   cp5.addTextfield("input").setPosition(20, 100).setSize(200, 40).setFont(font).setFocus(false).setCaptionLabel(" ").setColor(color(255, 0, 0)).setVisible(false);
  124. }
  125.  
  126. void drawBorders()
  127. {
  128.   strokeWeight(6);
  129.   stroke(200, 0, 10);
  130.   line(0, height, width, height);
  131.   line(0, 0, width, 0);
  132.   line(0, 0, 0, height);
  133.   line(width, 0, width, height);
  134.   strokeWeight(1);
  135. }
  136.  
  137. //reading the time that has elapsed since the program started
  138. String formatMillis(long millis)
  139. {
  140.  
  141.   int milliseconds = floor(millis)%1000;
  142.   int seconds = (int)((millis / 1000) % 60);
  143.   long minutes = ((millis / 1000) / 60)% 60;
  144.   long hour = ((millis / 1000) / 3600)% 60;
  145.   return "" + nf(hour, 2, 0) + ":"  + nf(minutes, 2, 0) + ":" + nf(seconds, 2, 0) + ":" + nf(milliseconds, 3, 0);
  146. }
  147.  
  148. void contextMenu(int currentIndex)
  149. {
  150.   i = currentIndex;
  151.  
  152.   if (contextMenuOpenByMouse[0])
  153.   {
  154.     cir.get(i).showingData();
  155.   } else if (contextMenuOpenByMouse[1])
  156.   {
  157.     cir.get(i).showingData();
  158.   } else if (contextMenuOpenByMouse[2])
  159.   {
  160.     pend.get(i).showingData();
  161.   } else if (contextMenuOpenByMouse[3])
  162.   {
  163.     doublePend.get(i).showingData(3);
  164.   } else if (contextMenuOpenByMouse[4])
  165.   {
  166.     doublePend.get(i).showingData(4);
  167.   }
  168. }
  169.  
  170.  
  171. void changePositionByTheMouse(int currentIndex)
  172. {
  173.   i = currentIndex;
  174.   PVector diff;
  175.  
  176.   if (changePositionByMouse[0])
  177.   {
  178.     cir.get(i).point.x = mouseX;
  179.     cir.get(i).point.y = mouseY;
  180.     cir.get(i).velocity.mult(0);
  181.   } else if (changePositionByMouse[1])
  182.   {
  183.     cir.get(i).point.x = mouseX;
  184.     cir.get(i).point.y = mouseY;
  185.   } else if (changePositionByMouse[2])
  186.   {
  187.     pend.get(i).position.x = mouseX;
  188.     pend.get(i).position.y = mouseY;
  189.  
  190.     diff = PVector.sub(pend.get(i).origin, new PVector(mouseX, mouseY));      // Difference between 2 points
  191.     pend.get(i).angle = atan2(-1*diff.y, diff.x) - radians(90);                      // Angle relative to vertical axis
  192.  
  193.     pend.get(i).lengh = diff.mag();
  194.     pend.get(i).a1_vel = 0;
  195.   } else if (changePositionByMouse[3])
  196.   {
  197.     doublePend.get(i).position[0].x = mouseX;
  198.     doublePend.get(i).position[0].y = mouseY;
  199.  
  200.     diff = PVector.sub(doublePend.get(i).origin, new PVector(mouseX, mouseY));    
  201.     doublePend.get(i).a1 = atan2(-1*diff.y, diff.x)- radians(90);                        
  202.  
  203.     doublePend.get(i).length1 = diff.mag();
  204.     PVector diff2 = PVector.sub(doublePend.get(i).position[0], doublePend.get(i).position[1]);
  205.     doublePend.get(i).length2 = diff2.mag();
  206.     doublePend.get(i).a1_vel = 0;
  207.     doublePend.get(i).a2_vel = 0;
  208.   } else if (changePositionByMouse[4])
  209.   {
  210.     doublePend.get(i).position[1].x = mouseX;
  211.     doublePend.get(i).position[1].y = mouseY;
  212.  
  213.     diff = PVector.sub(doublePend.get(i).position[0], new PVector(mouseX, mouseY));    
  214.     doublePend.get(i).a2 = atan2(-1*diff.y, diff.x)- radians(90);                              
  215.  
  216.     doublePend.get(i).length2 = diff.mag();
  217.     doublePend.get(i).a2_vel = 0;
  218.   }
  219. }
  220.  
  221. void mousePressed() {
  222.  
  223.   if (!stopStart)
  224.   {
  225.     if (mode == 1)
  226.     {
  227.       if (field)
  228.       {
  229.         for (int i = 0; i<cir.size(); i++)
  230.         {
  231.           float d = dist(mouseX, mouseY, cir.get(i).point.x, cir.get(i).point.y);
  232.           if (d <= cir.get(i).radius ) {
  233.             if (mouseButton == LEFT)
  234.             {
  235.               changePositionByMouse[0] = true;
  236.             } else if (mouseButton == RIGHT)
  237.             {
  238.               contextMenuOpenByMouse[0] = true;
  239.             }
  240.  
  241.             currentIndex = i;
  242.           }
  243.         }
  244.       } else
  245.       {
  246.         for (int j = 0; j<cir.size(); j++)
  247.         {
  248.           float d = dist(mouseX, mouseY, cir.get(j).point.x, cir.get(j).point.y);
  249.           if (d <= cir.get(j).radius) {
  250.             if (mouseButton == LEFT)
  251.             {
  252.               changePositionByMouse[1] = true;
  253.             } else if (mouseButton == RIGHT)
  254.             {
  255.               contextMenuOpenByMouse[1] = true;
  256.             }
  257.  
  258.             currentIndex = j;
  259.           }
  260.         }
  261.       }
  262.     } else if (mode == 2)
  263.     {
  264.       if (pendul)
  265.       {
  266.         for (int k = 0; k< pend.size(); k++)
  267.         {
  268.           float d = dist(mouseX, mouseY, pend.get(k).position.x, pend.get(k).position.y);
  269.  
  270.           if (d <= cir.get(k).radius) {
  271.             if (mouseButton == LEFT)
  272.             {
  273.               changePositionByMouse[2] = true;
  274.             } else if (mouseButton == RIGHT)
  275.             {
  276.               contextMenuOpenByMouse[2] = true;
  277.             }
  278.  
  279.             currentIndex = k;
  280.           }
  281.         }
  282.       } else
  283.       {
  284.         for (int l = 0; l< doublePend.size(); l++)
  285.         {
  286.           float d1 = dist(mouseX, mouseY, doublePend.get(l).position[0].x, doublePend.get(l).position[0].y);
  287.           float d2 = dist(mouseX, mouseY, doublePend.get(l).position[1].x, doublePend.get(l).position[1].y);
  288.  
  289.           if (d1 <= doublePend.get(l).radius1) {
  290.             if (mouseButton == LEFT)
  291.             {
  292.               changePositionByMouse[3] = true;
  293.             } else if (mouseButton == RIGHT)
  294.             {
  295.               contextMenuOpenByMouse[3] = true;
  296.             }
  297.           } else if (d2 <= doublePend.get(l).radius2) {
  298.             if (mouseButton == LEFT)
  299.             {
  300.               changePositionByMouse[4] = true;
  301.             } else if (mouseButton == RIGHT)
  302.             {
  303.               contextMenuOpenByMouse[4] = true;
  304.             }
  305.           }
  306.           currentIndex = l;
  307.         }
  308.       }
  309.     } else if (mode == 4)
  310.     {
  311.     }
  312.   }
  313. }
  314.  
  315. void mouseReleased() {
  316.   if (!stopStart)
  317.   {
  318.     if (mode == 1)
  319.     {
  320.       if (field)
  321.       {
  322.         if (changePositionByMouse[0]) {
  323.           changePositionByMouse[0] = false;
  324.         }
  325.       } else
  326.       {
  327.         if (changePositionByMouse[1]) {
  328.           changePositionByMouse[1] = false;
  329.         }
  330.       }
  331.     } else if (mode == 2)
  332.     {
  333.       if (pendul)
  334.       {
  335.         if (changePositionByMouse[2]) {
  336.           changePositionByMouse[2] = false;
  337.         }
  338.       } else
  339.       {
  340.         if (changePositionByMouse[3]) {
  341.  
  342.           changePositionByMouse[3] = false;
  343.         } else if (changePositionByMouse[4]) {
  344.  
  345.           changePositionByMouse[4] = false;
  346.         }
  347.       }
  348.     }
  349.   } else if (mode == 4)
  350.   {
  351.   }
  352. }
  353.  
  354. void keyPressed()
  355. {
  356.   //reading keyboard shortcuts
  357.   if ((key >= 'A' && key <= 'Z') || (key >= 'a' && key <= 'z'))
  358.   {
  359.  
  360.     if (key == 'M' ||key == 'm')
  361.     {
  362.       information = !information; //menu
  363.     } else if (key == (shortcutHomogenField+32) ||key == shortcutHomogenField)
  364.     {
  365.       mode = 1;
  366.       field = false; // f - homogeneous field
  367.       setting();
  368.     } else if (key == (shortcutCentralField+32) ||key == shortcutCentralField)
  369.     {
  370.       mode = 1;
  371.       field = true; //v - central field
  372.       setting();
  373.     } else if (key == (shortcutSinglePendulum+32) ||key ==  shortcutSinglePendulum)
  374.     {
  375.       mode = 2;
  376.       pendul = true; //p - single pendulum
  377.       setting();
  378.     } else if (key == (shortcutDoublePendulum+32) ||key == shortcutDoublePendulum)
  379.     {
  380.       mode = 2;
  381.       pendul = false; //d - double pendulum
  382.       setting();
  383.     } else if (key == (shortcutLisajousTable+32) ||key == shortcutLisajousTable)
  384.     {
  385.       mode = 3;
  386.       wholeScreen = true;
  387.       setting();
  388.     } else if (key == (shortcutBonaciSeqense+32) ||key == shortcutBonaciSeqense)
  389.     {
  390.       mode = 3;
  391.       wholeScreen = false;
  392.       setting();
  393.     } else if (key == (shortcutStrangeCircles+32) ||key == shortcutStrangeCircles)
  394.     {
  395.       mode = 4;//c - strange circles
  396.       setting();
  397.     } else if (key == 'R' ||key == 'r')
  398.     {//reset
  399.       background(255);
  400.       setting();
  401.     } else if (key == 'K' ||key == 'k')
  402.     {
  403.       if (!information)
  404.       {
  405.         information = !information;
  406.       }  
  407.       //
  408.       if (mode == 1 & field == true)
  409.       {
  410.         pozYSet = cp5.getController("Central").getPosition();
  411.         cp5.get(Button.class, "Set").setPosition(pozXSet, pozYSet[1]).setVisible(true);
  412.         cp5.get(Textfield.class, "input").setPosition(pozXSet, pozYSet[1]+button_height).setVisible(true).setFocus(true);
  413.       } else if (mode == 1 & field == false)
  414.       {
  415.         pozYSet = cp5.getController("Homogen").getPosition();
  416.         cp5.get(Button.class, "Set").setPosition(pozXSet, pozYSet[1]).setVisible(true);
  417.         cp5.get(Textfield.class, "input").setPosition(pozXSet, pozYSet[1]+button_height).setVisible(true).setFocus(true);
  418.       } else if (mode == 2 & pendul == true)
  419.       {
  420.         pozYSet = cp5.getController("Single").getPosition();
  421.         cp5.get(Button.class, "Set").setPosition(pozXSet, pozYSet[1]).setVisible(true);
  422.         cp5.get(Textfield.class, "input").setPosition(pozXSet, pozYSet[1]+button_height).setVisible(true).setFocus(true);
  423.       } else if (mode == 2 & pendul == false)
  424.       {
  425.         pozYSet = cp5.getController("Dual").getPosition();
  426.         cp5.get(Button.class, "Set").setPosition(pozXSet, pozYSet[1]).setVisible(true);
  427.         cp5.get(Textfield.class, "input").setPosition(pozXSet, pozYSet[1]+button_height).setVisible(true).setFocus(true);
  428.       } else if (mode == 3 & wholeScreen == true)
  429.       {
  430.         pozYSet = cp5.getController("Lisajous").getPosition();
  431.         cp5.get(Button.class, "Set").setPosition(pozXSet, pozYSet[1]).setVisible(true);
  432.         cp5.get(Textfield.class, "input").setPosition(pozXSet, pozYSet[1]+button_height).setVisible(true).setFocus(true);
  433.       } else if (mode == 3 & wholeScreen == false)
  434.       {    
  435.         //pozYSet = cp5.getController("Bonaci").getPosition();
  436.         //cp5.get(Button.class, "Set").setPosition(pozXSet, pozYSet[1]).setVisible(true);
  437.         //cp5.get(Button.class, "input").setPosition(pozXSet, pozYSet[1]+button_height).setVisible(true);
  438.       } else if (mode == 4)
  439.       {
  440.         pozYSet = cp5.getController("Circle").getPosition();
  441.         cp5.get(Button.class, "Set").setPosition(pozXSet, pozYSet[1]).setVisible(true);
  442.         cp5.get(Textfield.class, "input").setPosition(pozXSet, pozYSet[1]+button_height).setVisible(true).setFocus(true);
  443.       }
  444.       setting();
  445.     }
  446.   }
  447. }
  448.  
  449. void setting()
  450. {
  451.  
  452.   if (mode == 1)
  453.   {
  454.     float pozX = 0, pozY = 0;
  455.  
  456.     for (int i = control - 1; i >= 0; i--)
  457.     {
  458.       cir.remove(i);
  459.     }
  460.  
  461.     if ( field == true)
  462.     {
  463.  
  464.       for (int i = 0; i <control2; i++)
  465.       {
  466.         mass = 20 * randa.nextFloat() + 4;
  467.         total_mass +=mass;
  468.         radius = mass  * 2;
  469.         pozX = (width * new Random().nextFloat()) - radius;
  470.         pozY =  (height * new Random().nextFloat()) - radius;
  471.  
  472.         cir.add(new Circum(pozX, pozY, radius, mass));
  473.         cir.get(i).velocity = new PVector(0, 0);
  474.       }
  475.       control = control2;
  476.     } else if ( field == false)
  477.     {
  478.  
  479.       for (int i = 0; i<control2; i++)
  480.       {
  481.         mass = 8 * randa.nextFloat() + 4;
  482.         radius = mass  * 2;
  483.         pozX = (width * new Random().nextFloat()) - radius;
  484.         pozY =  (height * new Random().nextFloat()) - radius;
  485.  
  486.         cir.add(new Circum( pozX, pozY, radius, mass));
  487.         cir.get(i).setSpeed(inic);
  488.       }
  489.       control = control2;
  490.     }
  491.   } else if (mode == 2)
  492.   {
  493.     if (pendul == true)
  494.     {
  495.  
  496.       for (int i = ile_pend2 - 1; i >= 0; i--)
  497.       {
  498.         pend.remove(i);
  499.       }
  500.  
  501.       a1 = PI  / (4 * randa.nextFloat() + 1);
  502.  
  503.       ile_pend2 = ile_pend;
  504.  
  505.       for (int i = 0; i< ile_pend; i++)
  506.       {
  507.         pend.add(new pendulum(a1));
  508.         a1+=0.2;
  509.       }
  510.     } else if (pendul == false)
  511.     {
  512.       for (int i = ile - 1; i >= 0; i--)
  513.       {
  514.         doublePend.remove(i);
  515.       }
  516.  
  517.       for (int i = 0; i< ile2; i++)
  518.       {
  519.         doublePend.add(new double_pendulum(PI / (randa.nextFloat() + 1), PI / (randa.nextFloat() + 3), 400, 250, 40, 20));
  520.         doublePend.get(i).set0();
  521.       }
  522.  
  523.       ile = ile2;
  524.     }
  525.   } else if (mode == 3)
  526.   {  
  527.     if (wholeScreen)
  528.     {
  529.       table.reset(w);
  530.     } else
  531.     {
  532.       seq.reset();
  533.     }
  534.   } else if (mode == 4)
  535.   {
  536.     stren.reset();
  537.   }
  538.   StartedMillis = millis();
  539. }
  540.  
  541. void checkingIfMouseIsOver()
  542. {
  543.   if (cp5.isMouseOver(cp5.getController("Menu"))) {
  544.     cp5.getController("Set").hide();
  545.     cp5.getController("input").setVisible(false);
  546.     textFont(font, 20);
  547.     textLeading(18);
  548.     textAlign(LEFT);
  549.     String advice = " Nie ma znaczenia jaka jest wielkość liter.\n "+ shortcutHomogenField + "- pole jednorodne\n "+ shortcutCentralField +" - pole centralne\n "+ shortcutSinglePendulum +" - pojedyncze wahadło\n "+ shortcutDoublePendulum  +" - podwójne wahadło\n "+ shortcutLisajousTable  +" - tablica Lisajous\n "+ shortcutBonaciSeqense +" - sekwencja fibonacziego\n "+ shortcutStrangeCircles +" - dziwne koła \n K - zmiana ilości obiektów \n R - reset";
  550.     text(advice, 110, 20, 660, 160);
  551.   } else if (cp5.isMouseOver(cp5.getController("Reset")))
  552.   {
  553.     cp5.getController("Set").hide();
  554.     cp5.getController("input").setVisible(false);
  555.   } else if (cp5.isMouseOver(cp5.getController("Central"))) {
  556.     cp5.get(Textfield.class, "input").setCaptionLabel("Ustaw ilość obiektów w centralnym polu grawitacyjnym");
  557.     Disclosures_set("Central");
  558.   } else if (cp5.isMouseOver(cp5.getController("Single"))) {
  559.     Disclosures_set("Single");
  560.     cp5.get(Textfield.class, "input").setCaptionLabel("Ustaw ilość pojedyńczych wahadeł");
  561.   } else if (cp5.isMouseOver(cp5.getController("Dual"))) {
  562.     cp5.get(Textfield.class, "input").setCaptionLabel("Ustaw ilość podwójnych wahadeł");
  563.     Disclosures_set("Dual");
  564.   } else if (cp5.isMouseOver(cp5.getController("Homogen"))) {
  565.     cp5.get(Textfield.class, "input").setLabel("Ustaw ilość obiektów w jednorodnym polu grawitacyjnym");
  566.     Disclosures_set("Homogen");
  567.   } else if (cp5.isMouseOver(cp5.getController("Lisajous"))) {
  568.     Disclosures_set("Lisajous");
  569.     cp5.get(Textfield.class, "input").setLabel("Ustaw wielkość okręgów");
  570.     cp5.getController("Set").setVisible(false);
  571.   } else if (cp5.isMouseOver(cp5.getController("Bonaci"))) {
  572.     // Disclosures_set("Bonaci");
  573.     cp5.getController("input").setVisible(false);
  574.     cp5.getController("Set").setVisible(false);
  575.   } else if (cp5.isMouseOver(cp5.getController("Circle"))) {
  576.     Disclosures_set("Circle");
  577.     cp5.get(Textfield.class, "input").setLabel("Ustaw wielkość zmiany kąta");
  578.     cp5.getController("Set").setVisible(true);
  579.   }
  580. }
  581.  
  582. void draw() {
  583.  
  584.   background(120);
  585.   drawBorders();
  586.  
  587.   if (mode == 1)
  588.   {
  589.     if (field)
  590.     {
  591.       centralField();
  592.     } else
  593.     {
  594.       homogeneousField();
  595.     }
  596.   } else if (mode == 2)
  597.   {
  598.     if (pendul)
  599.     {
  600.       singlePendulum();
  601.     } else
  602.     {
  603.       dublePendulum();
  604.     }
  605.   } else if (mode == 3)
  606.   {
  607.     background(0);
  608.  
  609.     if (wholeScreen)
  610.     {
  611.       noFill();
  612.       table.show();
  613.     } else
  614.     {
  615.       seq.drawing();
  616.     }
  617.   } else if (mode == 4)
  618.   {
  619.     pushMatrix();
  620.     translate(width / 2, height/2);
  621.     background(0);
  622.     strokeWeight(5);
  623.     point(0, 0);
  624.     strokeWeight(2);
  625.     noFill();
  626.     circle(0, 0, 100);
  627.     stren.strangeCircle();
  628.     popMatrix();
  629.   }
  630.  
  631.   textSize(20);
  632.   fill(10, 10, 10);
  633.  
  634.   if (mode == 3 || mode == 4)
  635.   {
  636.     fill(200, 200, 200);
  637.   }
  638.  
  639.   if (!stopStart)
  640.   {
  641.     changePositionByTheMouse(currentIndex);
  642.     contextMenu(currentIndex);
  643.   }
  644.  
  645.   checkingIfMouseIsOver();
  646.  menuManagement();
  647.   ButtonManagement();
  648. }
  649.  
  650. //AButton
  651.  
  652. //reading input from buttons
  653. void Homogen(int n) {
  654.  
  655.   CentralButton(n, true, false);
  656. }
  657.  
  658. void Circle(int n) {
  659.  
  660.   CentralButton(n, true, false);
  661. }
  662.  
  663. void Lisajous(int n) {
  664.  
  665.   wholeScreen = true;
  666.   CentralButton(n, true, false);
  667. }
  668.  
  669. void Bonaci(int n) {
  670.  
  671.   wholeScreen = false;
  672.   CentralButton(n, true, false);
  673. }
  674.  
  675. void Central(int n) {
  676.  
  677.   CentralButton(n, true, true);
  678. }
  679.  
  680. void Single(int n) {
  681.  
  682.   CentralButton(n, false, true);
  683. }
  684.  
  685. void Dual(int n) {
  686.  
  687.   CentralButton(n, false, false);
  688. }
  689.  
  690. void Menu()
  691. {
  692.   information = !information;
  693. }
  694.  
  695. void Reset()
  696. {
  697.   background(255);
  698.   setting();
  699. }
  700.  
  701. void StartStop() {
  702. println("3",stopStart,startMenu);
  703.   stopStart = !stopStart;
  704. println("4",stopStart,startMenu);
  705.   if (stopStart)
  706.   {
  707.     cp5.getController("StartStop").setCaptionLabel("Zatrzymanie programu");
  708.     centralAction = true;
  709.     homogeneousAction = true;
  710.     singleAction = true;
  711.     doubleAction = true;
  712.     lisajousAction = true;
  713.     nBonaciAction = true;
  714.     strangeCirclesAction = true;
  715.      
  716.   } else
  717.   {
  718.     cp5.getController("StartStop").setCaptionLabel("Uruchomienie programu");
  719.     centralAction = false;
  720.     homogeneousAction = false;
  721.     singleAction = false;
  722.     doubleAction = false;
  723.     lisajousAction = false;
  724.     nBonaciAction = false;
  725.     strangeCirclesAction = false;
  726.   }
  727.  
  728.  
  729. }
  730.  
  731. void Start() {
  732. println("1",stopStart,startMenu);
  733.   stopStart = true;
  734.   startMenu = false;
  735.   println("2",stopStart,startMenu);
  736.   cp5.get(Button.class, "Start").hide();
  737.   cp5.get(Button.class, "Settings").hide();
  738.   cp5.get(Button.class, "Exit").hide();
  739. }
  740.  
  741. void Settings() {
  742. }
  743.  
  744. void Exit() {
  745.   exit();
  746. }
  747.  
  748. void menuManagement()
  749. {
  750.   if(startMenu)
  751.   {
  752.   cp5.get(Button.class, "Start").setVisible(true);
  753.   cp5.get(Button.class, "Settings").setVisible(true);
  754.   cp5.get(Button.class, "Exit").setVisible(true);//.show();
  755.   } else if (startMenu == false)
  756.   {
  757.   cp5.get(Button.class, "Start").setVisible(false);//.hide();
  758.   cp5.get(Button.class, "Settings").setVisible(false);//.hide();
  759.   cp5.get(Button.class, "Exit").setVisible(false);//.hide();
  760.   }
  761. }
  762.  
  763.  
  764. void Set()
  765. {
  766.   setting();
  767. }
  768.  
  769. void CentralButton(int n, boolean poleOrPendul, boolean i)
  770. {
  771.   mode  = n;
  772.  
  773.   if (poleOrPendul)
  774.   {
  775.     field = i;
  776.   } else
  777.   {
  778.     pendul = i;
  779.   }
  780.  
  781.   setting();
  782. }
  783.  
  784. void ButtonManagement()
  785. {
  786.   if (information)
  787.   {
  788.  
  789.     long DurationMillis = millis() - StartedMillis;
  790.     text(formatMillis(DurationMillis), width - 136, 20);
  791.     text( frameRate, width - 80, 40);
  792.     cp5.get(Button.class, "Homogen").setVisible(true);
  793.     cp5.get(Button.class, "Central").setVisible(true);
  794.     cp5.get(Button.class, "Single").setVisible(true);
  795.     cp5.get(Button.class, "Dual").setVisible(true);
  796.     cp5.get(Button.class, "Lisajous").setVisible(true);
  797.     cp5.get(Button.class, "Bonaci").setVisible(true);
  798.     cp5.get(Button.class, "Circle").setVisible(true);
  799.   } else  if (information == false)
  800.   {
  801.     cp5.get(Button.class, "Homogen").setVisible(false);
  802.     cp5.get(Button.class, "Central").setVisible(false);
  803.     cp5.get(Button.class, "Single").setVisible(false);
  804.     cp5.get(Button.class, "Dual").setVisible(false);
  805.     cp5.get(Button.class, "Lisajous").setVisible(false);
  806.     cp5.get(Button.class, "Bonaci").setVisible(false);
  807.     cp5.get(Button.class, "Circle").setVisible(false);
  808.     cp5.get(Textfield.class, "input").setVisible(false);
  809.   }
  810. }
  811.  
  812. void Disclosures_set(String name)
  813. {
  814.   pozYSet = cp5.getController(name).getPosition();
  815.   cp5.getController("Set").setPosition(pozXSet, pozYSet[1]);
  816.   cp5.getController("input").setPosition(pozXSet, pozYSet[1]+button_height);
  817.   buttonName = name;  
  818.   cp5.getController("Set").show();
  819.   cp5.getController("input").show();
  820. }
  821.  
  822. int inputChange(String theText)
  823. {
  824.   Pattern numbers = Pattern.compile("[0-9]+");
  825.   theText.replaceAll("^\\D+", "").split("\\D+");
  826.   Matcher matcher = numbers.matcher(theText);
  827.   int sum = 0;
  828.   while (matcher.find()) {
  829.     sum += Integer.parseInt(matcher.group());
  830.   }
  831.  
  832.   return sum;
  833. }
  834.  
  835. // automatically receives results from controller input
  836. void input(String theText) {
  837.  
  838.   int amount = inputChange(theText);
  839.  
  840.   if (buttonName == "Homogen")
  841.   {
  842.     control2 = amount;
  843.   } else if (buttonName.equals("Central"))
  844.   {
  845.     control2 = amount;
  846.   } else if (buttonName.equals("Dual"))
  847.   {
  848.     ile2 = amount;
  849.   } else if (buttonName.equals("Single"))
  850.   {
  851.     ile_pend = amount;
  852.   } else if (buttonName.equals("Lisajous"))
  853.   {
  854.     w = amount;
  855.   }
  856.  
  857.   setting();
  858. }
  859.  
  860.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement