Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Graphics;
- import java.awt.Color;
- import java.util.Random; //piesledz RNG
- public class bezjeform extends javax.swing.JFrame {
- public static int[] x_arr=new int[7];
- public static int[] y_arr=new int[7];
- // glabajam cp kordinasu vertibas
- public static float[] B_arr=new float[7];
- // glabajam Bermsteina polinoma vertibas
- public void Bezje_method()
- {
- Graphics g=jPanel1.getGraphics();
- g.setColor(Color.white);
- // uzstadam baltu krasu un veodjam baltu tainsturi
- g.fillRect(0, 0, jPanel1.getWidth(), jPanel1.getHeight());
- //zimejam baltu taisnsturi
- float t=0;
- while (t<=1)
- {
- B_arr[0]=(1-t)*(1-t)*(1-t)*(1-t)*(1-t)*(1-t);
- B_arr[1]=6*t*(1-t)*(1-t)*(1-t)*(1-t)*(1-t);
- B_arr[2]=6*t*t*(1-t)*(1-t)*(1-t)*(1-t);
- B_arr[3]=6*t*t*t*(1-t)*(1-t)*(1-t);
- B_arr[4]=6*t*t*t*t*(1-t)*(1-t);
- B_arr[5]=6*t*t*t*t*t*(1-t);
- B_arr[6]=t*t*t*t*t*t;
- // B_arr[0]=(1-t)*(1-t)*(1-t)*(1-t)*(1-t)*(1-t)*(1-t)*(1-t);
- // B_arr[1]=8*t*(1-t)*(1-t)*(1-t)*(1-t)*(1-t)*(1-t)*(1-t);
- // B_arr[2]=8*t*t*(1-t)*(1-t)*(1-t)*(1-t)*(1-t)*(1-t);
- // B_arr[3]=8*t*t*t*(1-t)*(1-t)*(1-t)*(1-t)*(1-t);
- // B_arr[4]=8*t*t*t*t*(1-t)*(1-t)*(1-t)*(1-t);
- // B_arr[5]=8*t*t*t*t*t*(1-t)*(1-t)*(1-t);
- // B_arr[6]=8*t*t*t*t*t*t*(1-t)*(1-t);
- // B_arr[7]=8*t*t*t*t*t*t*t*(1-t);
- // B_arr[8]=t*t*t*t*t*t*t*t;
- // so pierakstu ir japapildina (pascal triangle)
- int x=(int)(B_arr[0]*x_arr[0]+
- B_arr[1]*x_arr[1]+
- B_arr[2]*x_arr[2]+
- B_arr[3]*x_arr[3]+
- B_arr[4]*x_arr[4]+
- B_arr[5]*x_arr[5]+
- B_arr[6]*x_arr[6]);
- // B_arr[7]*x_arr[7]+
- // B_arr[8]*x_arr[8]);
- int y=(int)(B_arr[0]*y_arr[0]+
- B_arr[1]*y_arr[1]+
- B_arr[2]*y_arr[2]+
- B_arr[3]*y_arr[3]+
- B_arr[4]*y_arr[4]+
- B_arr[5]*y_arr[5]+
- B_arr[6]*y_arr[6]);
- // B_arr[7]*y_arr[7]+
- // B_arr[8]*y_arr[8]);
- g.setColor(Color.magenta);
- g.drawLine(x, y, x, y); // zimejam likni
- t=(float) (t+0.001); // while cikls
- }
- for (int i=0; i<=7; i++) //8
- {
- if (i<7) //8
- {
- g.setColor(Color.green);
- g.drawLine(x_arr[i], y_arr[i], x_arr[i+1], y_arr[i+1]); //zimejam linijas kas savieno cp
- }
- g.setColor(Color.red);
- g.drawString(String.valueOf(i+1),x_arr[i],y_arr[i]-6); // izvadam cp numeraciju
- g.fillOval(x_arr[i], y_arr[i], 5, 5); // zimejam virsotnes
- }
- }
- public bezjeform() {
- initComponents();
- }
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- buttonGroup1 = new javax.swing.ButtonGroup();
- jPanel1 = new javax.swing.JPanel();
- jRadioButton1 = new javax.swing.JRadioButton();
- jRadioButton2 = new javax.swing.JRadioButton();
- jRadioButton3 = new javax.swing.JRadioButton();
- jRadioButton4 = new javax.swing.JRadioButton();
- jButton1 = new javax.swing.JButton();
- jRadioButton5 = new javax.swing.JRadioButton();
- jRadioButton6 = new javax.swing.JRadioButton();
- jRadioButton7 = new javax.swing.JRadioButton();
- jRadioButton8 = new javax.swing.JRadioButton();
- jRadioButton9 = new javax.swing.JRadioButton();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- jPanel1.setBackground(new java.awt.Color(255, 255, 255));
- jPanel1.addMouseListener(new java.awt.event.MouseAdapter() {
- public void mouseClicked(java.awt.event.MouseEvent evt) {
- jPanel1MouseClicked(evt);
- }
- });
- javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
- jPanel1.setLayout(jPanel1Layout);
- jPanel1Layout.setHorizontalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGap(0, 318, Short.MAX_VALUE)
- );
- jPanel1Layout.setVerticalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGap(0, 328, Short.MAX_VALUE)
- );
- buttonGroup1.add(jRadioButton1);
- jRadioButton1.setText("1 cp");
- buttonGroup1.add(jRadioButton2);
- jRadioButton2.setText("2 cp");
- buttonGroup1.add(jRadioButton3);
- jRadioButton3.setText("3 cp");
- buttonGroup1.add(jRadioButton4);
- jRadioButton4.setText("4 cp");
- jButton1.setText("Create");
- jButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
- buttonGroup1.add(jRadioButton5);
- jRadioButton5.setText("5 cp");
- buttonGroup1.add(jRadioButton6);
- jRadioButton6.setText("6 cp");
- buttonGroup1.add(jRadioButton7);
- jRadioButton7.setText("7 cp");
- buttonGroup1.add(jRadioButton8);
- jRadioButton8.setText("8 cp");
- buttonGroup1.add(jRadioButton9);
- jRadioButton9.setText("9 cp");
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jRadioButton1)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 36, Short.MAX_VALUE)
- .addComponent(jButton1)
- .addGap(18, 18, 18))
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jRadioButton2)
- .addComponent(jRadioButton3)
- .addComponent(jRadioButton4)
- .addComponent(jRadioButton5)
- .addComponent(jRadioButton6)
- .addComponent(jRadioButton7)
- .addComponent(jRadioButton8)
- .addComponent(jRadioButton9))
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jRadioButton1)
- .addComponent(jButton1))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jRadioButton2)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jRadioButton3)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jRadioButton4)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jRadioButton5)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jRadioButton6)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jRadioButton7)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jRadioButton8)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jRadioButton9))
- .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addContainerGap(80, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
- Random value=new Random();
- // iesledz nejausu skaitlu generatoru
- for (int i=0; i<=7; i++) //9
- {
- x_arr[i]=value.nextInt(jPanel1.getWidth());
- // pieskiram nejausus skaitlus diapazona
- // vienads ar panela platumu
- y_arr[i]=value.nextInt(jPanel1.getHeight());
- // pieskiram nejausus skaitlus diapazona
- // vienads ar panela augstums
- }
- Bezje_method(); // parzimesana
- }
- private void jPanel1MouseClicked(java.awt.event.MouseEvent evt) {
- int n=-1;
- if (jRadioButton1.isSelected()) n=0;
- else if (jRadioButton2.isSelected()) n=1;
- else if (jRadioButton3.isSelected()) n=2;
- else if (jRadioButton4.isSelected()) n=3;
- else if (jRadioButton5.isSelected()) n=4;
- else if (jRadioButton6.isSelected()) n=5;
- else if (jRadioButton7.isSelected()) n=6;
- // else if (jRadioButton8.isSelected()) n=7;
- // else if (jRadioButton9.isSelected()) n=8;
- int x=evt.getX(); //nolasam peles x vertibu
- int y=evt.getY(); //nolasam peles y vertibu
- x_arr[n]=x; // parrakstam ieprieksejos vertibas
- y_arr[n]=y;
- Bezje_method();
- }
- public static void main(String args[]) {
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new bezjeform().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.ButtonGroup buttonGroup1;
- private javax.swing.JButton jButton1;
- private javax.swing.JPanel jPanel1;
- private javax.swing.JRadioButton jRadioButton1;
- private javax.swing.JRadioButton jRadioButton2;
- private javax.swing.JRadioButton jRadioButton3;
- private javax.swing.JRadioButton jRadioButton4;
- private javax.swing.JRadioButton jRadioButton5;
- private javax.swing.JRadioButton jRadioButton6;
- private javax.swing.JRadioButton jRadioButton7;
- private javax.swing.JRadioButton jRadioButton8;
- private javax.swing.JRadioButton jRadioButton9;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement