Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.16 KB | None | 0 0
  1. import java.awt.Graphics;
  2. import java.awt.Color;
  3. import java.util.Random; //piesledz RNG
  4.  
  5. public class bezjeform extends javax.swing.JFrame {
  6.  
  7. public static int[] x_arr=new int[7];
  8. public static int[] y_arr=new int[7];
  9. // glabajam cp kordinasu vertibas
  10. public static float[] B_arr=new float[7];
  11. // glabajam Bermsteina polinoma vertibas
  12. public void Bezje_method()
  13. {
  14.  
  15. Graphics g=jPanel1.getGraphics();
  16. g.setColor(Color.white);
  17. // uzstadam baltu krasu un veodjam baltu tainsturi
  18. g.fillRect(0, 0, jPanel1.getWidth(), jPanel1.getHeight());
  19. //zimejam baltu taisnsturi
  20. float t=0;
  21. while (t<=1)
  22. {
  23. B_arr[0]=(1-t)*(1-t)*(1-t)*(1-t)*(1-t)*(1-t);
  24. B_arr[1]=6*t*(1-t)*(1-t)*(1-t)*(1-t)*(1-t);
  25. B_arr[2]=6*t*t*(1-t)*(1-t)*(1-t)*(1-t);
  26. B_arr[3]=6*t*t*t*(1-t)*(1-t)*(1-t);
  27. B_arr[4]=6*t*t*t*t*(1-t)*(1-t);
  28. B_arr[5]=6*t*t*t*t*t*(1-t);
  29. B_arr[6]=t*t*t*t*t*t;
  30. // B_arr[0]=(1-t)*(1-t)*(1-t)*(1-t)*(1-t)*(1-t)*(1-t)*(1-t);
  31. // B_arr[1]=8*t*(1-t)*(1-t)*(1-t)*(1-t)*(1-t)*(1-t)*(1-t);
  32. // B_arr[2]=8*t*t*(1-t)*(1-t)*(1-t)*(1-t)*(1-t)*(1-t);
  33. // B_arr[3]=8*t*t*t*(1-t)*(1-t)*(1-t)*(1-t)*(1-t);
  34. // B_arr[4]=8*t*t*t*t*(1-t)*(1-t)*(1-t)*(1-t);
  35. // B_arr[5]=8*t*t*t*t*t*(1-t)*(1-t)*(1-t);
  36. // B_arr[6]=8*t*t*t*t*t*t*(1-t)*(1-t);
  37. // B_arr[7]=8*t*t*t*t*t*t*t*(1-t);
  38. // B_arr[8]=t*t*t*t*t*t*t*t;
  39. // so pierakstu ir japapildina (pascal triangle)
  40.  
  41. int x=(int)(B_arr[0]*x_arr[0]+
  42. B_arr[1]*x_arr[1]+
  43. B_arr[2]*x_arr[2]+
  44. B_arr[3]*x_arr[3]+
  45. B_arr[4]*x_arr[4]+
  46. B_arr[5]*x_arr[5]+
  47. B_arr[6]*x_arr[6]);
  48. // B_arr[7]*x_arr[7]+
  49. // B_arr[8]*x_arr[8]);
  50. int y=(int)(B_arr[0]*y_arr[0]+
  51. B_arr[1]*y_arr[1]+
  52. B_arr[2]*y_arr[2]+
  53. B_arr[3]*y_arr[3]+
  54. B_arr[4]*y_arr[4]+
  55. B_arr[5]*y_arr[5]+
  56. B_arr[6]*y_arr[6]);
  57. // B_arr[7]*y_arr[7]+
  58. // B_arr[8]*y_arr[8]);
  59. g.setColor(Color.magenta);
  60. g.drawLine(x, y, x, y); // zimejam likni
  61. t=(float) (t+0.001); // while cikls
  62. }
  63. for (int i=0; i<=7; i++) //8
  64. {
  65. if (i<7) //8
  66. {
  67. g.setColor(Color.green);
  68. g.drawLine(x_arr[i], y_arr[i], x_arr[i+1], y_arr[i+1]); //zimejam linijas kas savieno cp
  69. }
  70. g.setColor(Color.red);
  71. g.drawString(String.valueOf(i+1),x_arr[i],y_arr[i]-6); // izvadam cp numeraciju
  72. g.fillOval(x_arr[i], y_arr[i], 5, 5); // zimejam virsotnes
  73. }
  74. }
  75. public bezjeform() {
  76. initComponents();
  77. }
  78. @SuppressWarnings("unchecked")
  79. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  80. private void initComponents() {
  81.  
  82. buttonGroup1 = new javax.swing.ButtonGroup();
  83. jPanel1 = new javax.swing.JPanel();
  84. jRadioButton1 = new javax.swing.JRadioButton();
  85. jRadioButton2 = new javax.swing.JRadioButton();
  86. jRadioButton3 = new javax.swing.JRadioButton();
  87. jRadioButton4 = new javax.swing.JRadioButton();
  88. jButton1 = new javax.swing.JButton();
  89. jRadioButton5 = new javax.swing.JRadioButton();
  90. jRadioButton6 = new javax.swing.JRadioButton();
  91. jRadioButton7 = new javax.swing.JRadioButton();
  92. jRadioButton8 = new javax.swing.JRadioButton();
  93. jRadioButton9 = new javax.swing.JRadioButton();
  94.  
  95. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  96.  
  97. jPanel1.setBackground(new java.awt.Color(255, 255, 255));
  98. jPanel1.addMouseListener(new java.awt.event.MouseAdapter() {
  99. public void mouseClicked(java.awt.event.MouseEvent evt) {
  100. jPanel1MouseClicked(evt);
  101. }
  102. });
  103.  
  104. javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
  105. jPanel1.setLayout(jPanel1Layout);
  106. jPanel1Layout.setHorizontalGroup(
  107. jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  108. .addGap(0, 318, Short.MAX_VALUE)
  109. );
  110. jPanel1Layout.setVerticalGroup(
  111. jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  112. .addGap(0, 328, Short.MAX_VALUE)
  113. );
  114.  
  115. buttonGroup1.add(jRadioButton1);
  116. jRadioButton1.setText("1 cp");
  117.  
  118. buttonGroup1.add(jRadioButton2);
  119. jRadioButton2.setText("2 cp");
  120.  
  121. buttonGroup1.add(jRadioButton3);
  122. jRadioButton3.setText("3 cp");
  123.  
  124. buttonGroup1.add(jRadioButton4);
  125. jRadioButton4.setText("4 cp");
  126.  
  127. jButton1.setText("Create");
  128. jButton1.addActionListener(new java.awt.event.ActionListener() {
  129. public void actionPerformed(java.awt.event.ActionEvent evt) {
  130. jButton1ActionPerformed(evt);
  131. }
  132. });
  133.  
  134. buttonGroup1.add(jRadioButton5);
  135. jRadioButton5.setText("5 cp");
  136.  
  137. buttonGroup1.add(jRadioButton6);
  138. jRadioButton6.setText("6 cp");
  139.  
  140. buttonGroup1.add(jRadioButton7);
  141. jRadioButton7.setText("7 cp");
  142.  
  143. buttonGroup1.add(jRadioButton8);
  144. jRadioButton8.setText("8 cp");
  145.  
  146. buttonGroup1.add(jRadioButton9);
  147. jRadioButton9.setText("9 cp");
  148.  
  149. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  150. getContentPane().setLayout(layout);
  151. layout.setHorizontalGroup(
  152. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  153. .addGroup(layout.createSequentialGroup()
  154. .addContainerGap()
  155. .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  156. .addGap(18, 18, 18)
  157. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  158. .addGroup(layout.createSequentialGroup()
  159. .addComponent(jRadioButton1)
  160. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 36, Short.MAX_VALUE)
  161. .addComponent(jButton1)
  162. .addGap(18, 18, 18))
  163. .addGroup(layout.createSequentialGroup()
  164. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  165. .addComponent(jRadioButton2)
  166. .addComponent(jRadioButton3)
  167. .addComponent(jRadioButton4)
  168. .addComponent(jRadioButton5)
  169. .addComponent(jRadioButton6)
  170. .addComponent(jRadioButton7)
  171. .addComponent(jRadioButton8)
  172. .addComponent(jRadioButton9))
  173. .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
  174. );
  175. layout.setVerticalGroup(
  176. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  177. .addGroup(layout.createSequentialGroup()
  178. .addContainerGap()
  179. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  180. .addGroup(layout.createSequentialGroup()
  181. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  182. .addComponent(jRadioButton1)
  183. .addComponent(jButton1))
  184. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  185. .addComponent(jRadioButton2)
  186. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  187. .addComponent(jRadioButton3)
  188. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  189. .addComponent(jRadioButton4)
  190. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  191. .addComponent(jRadioButton5)
  192. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  193. .addComponent(jRadioButton6)
  194. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  195. .addComponent(jRadioButton7)
  196. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  197. .addComponent(jRadioButton8)
  198. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  199. .addComponent(jRadioButton9))
  200. .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  201. .addContainerGap(80, Short.MAX_VALUE))
  202. );
  203.  
  204. pack();
  205. }// </editor-fold>
  206.  
  207. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
  208. Random value=new Random();
  209. // iesledz nejausu skaitlu generatoru
  210. for (int i=0; i<=7; i++) //9
  211. {
  212. x_arr[i]=value.nextInt(jPanel1.getWidth());
  213. // pieskiram nejausus skaitlus diapazona
  214. // vienads ar panela platumu
  215. y_arr[i]=value.nextInt(jPanel1.getHeight());
  216. // pieskiram nejausus skaitlus diapazona
  217. // vienads ar panela augstums
  218. }
  219. Bezje_method(); // parzimesana
  220. }
  221.  
  222. private void jPanel1MouseClicked(java.awt.event.MouseEvent evt) {
  223. int n=-1;
  224. if (jRadioButton1.isSelected()) n=0;
  225. else if (jRadioButton2.isSelected()) n=1;
  226. else if (jRadioButton3.isSelected()) n=2;
  227. else if (jRadioButton4.isSelected()) n=3;
  228. else if (jRadioButton5.isSelected()) n=4;
  229. else if (jRadioButton6.isSelected()) n=5;
  230. else if (jRadioButton7.isSelected()) n=6;
  231. // else if (jRadioButton8.isSelected()) n=7;
  232. // else if (jRadioButton9.isSelected()) n=8;
  233. int x=evt.getX(); //nolasam peles x vertibu
  234. int y=evt.getY(); //nolasam peles y vertibu
  235. x_arr[n]=x; // parrakstam ieprieksejos vertibas
  236. y_arr[n]=y;
  237. Bezje_method();
  238. }
  239.  
  240. public static void main(String args[]) {
  241.  
  242. java.awt.EventQueue.invokeLater(new Runnable() {
  243. public void run() {
  244. new bezjeform().setVisible(true);
  245. }
  246. });
  247. }
  248. // Variables declaration - do not modify
  249. private javax.swing.ButtonGroup buttonGroup1;
  250. private javax.swing.JButton jButton1;
  251. private javax.swing.JPanel jPanel1;
  252. private javax.swing.JRadioButton jRadioButton1;
  253. private javax.swing.JRadioButton jRadioButton2;
  254. private javax.swing.JRadioButton jRadioButton3;
  255. private javax.swing.JRadioButton jRadioButton4;
  256. private javax.swing.JRadioButton jRadioButton5;
  257. private javax.swing.JRadioButton jRadioButton6;
  258. private javax.swing.JRadioButton jRadioButton7;
  259. private javax.swing.JRadioButton jRadioButton8;
  260. private javax.swing.JRadioButton jRadioButton9;
  261. // End of variables declaration
  262. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement