generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Club Houses » Off Topic
Home Search
 

Re: I made rope physics last night

Previous Thread :: Next Thread 
ToboboT is not online. ToboboT
Joined: 25 Jun 2011
Total Posts: 2385
23 Aug 2015 12:46 PM
in java
Report Abuse
Nitro509 is not online. Nitro509
Joined: 27 Jun 2010
Total Posts: 11170
23 Aug 2015 12:47 PM
pm me code

is it a rope simulator or is it for a game? 2d or 3d?
Report Abuse
Badfitz100 is not online. Badfitz100
Joined: 03 Nov 2010
Total Posts: 12591
23 Aug 2015 12:48 PM
good for you.

JumbleBee5 wrote at 4/10/2014 11:39 AM Report Abuse nice yolks honey ( ͡° ͜ʖ ͡°)( ͡° ͜ʖ ͡°)
Report Abuse
ToboboT is not online. ToboboT
Joined: 25 Jun 2011
Total Posts: 2385
23 Aug 2015 01:02 PM
its just a tech demo

// the powerhouse of the cell

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Random;

import javax.swing.*;

public class Mitochondria {

private static Timer time;

public static void main(String[] args) {
// TODO Auto-generated method stub
JFrameHandler jf = new JFrameHandler();
jf.setTitle("Rope Simulation");
jf.setBounds(100,50,500,500);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setVisible(true);
}

static class JFrameHandler extends JFrame implements ActionListener, MouseListener {
private int pointCount = 10;
private double mouse_x = 50;
private double mouse_y = 50;
private Random gen = new Random();
private double[] rope_x1 = new double[pointCount];
private double[] rope_y1 = new double[pointCount];
private double[] rope_x2 = new double[pointCount];
private double[] rope_y2 = new double[pointCount];
private double[] velocity_x = new double[pointCount];
private double[] velocity_y = new double[pointCount];

public JFrameHandler(){
time = new Timer(1,this);
time.start();

addMouseListener(this);

// Initialize points in rope_x1 and rope_y1
System.out.println("Intitalizing");
for (int i = 0; i < pointCount; i++){
//if (i != 249) {
rope_x1[i] = 0 + gen.nextInt(500);//10+(i * 2);
rope_y1[i] = (double) i;
rope_x2[i] = rope_x1[i];
rope_y2[i] = rope_y1[i];
//}else{
/*rope_x1[i] = 500;
rope_y1[i] = -50;
rope_x2[i] = rope_x1[i];
rope_y2[i] = rope_y1[i];
*/
//}
}
System.out.println("Intitalized");
}

public void paint(Graphics g) {
super.paint(g);
// draw stuff here
for (int i = 0; i < pointCount; i ++){
if (i != pointCount - 1) {
g.setColor(new Color((i * 255)/pointCount,0,0));
g.drawLine((int) rope_x1[i],(int) rope_y1[i], (int) rope_x1[i+1], (int) rope_y1[i+1]);
}
}
// stop here
repaint();
}

@Override
public void actionPerformed(ActionEvent arg0) {
repaint();

for (int i = 0; i < pointCount; i++){
if (i != 0 && i != pointCount - 1){
double x_vector1 = rope_x1[i-1] - rope_x1[i];
double y_vector1 = rope_y1[i-1] - rope_y1[i];
double magnitude1 = Math.sqrt(Math.pow((double) x_vector1,2.00) + Math.pow((double) y_vector1,2.00));
double extension1 = magnitude1 - 0;

double x_vector2 = rope_x1[i+1] - rope_x1[i];
double y_vector2 = rope_y1[i+1] - rope_y1[i];
double magnitude2 = Math.sqrt(Math.pow((double) x_vector2,2.00) + Math.pow((double) y_vector2,2.00));
double extension2 = magnitude2 - 0;

double xv = (x_vector1 / magnitude1 * extension1) + (x_vector2 / magnitude2 * extension2);
double yv = (y_vector1 / magnitude1 * extension1) + (y_vector2 / magnitude2 * extension2);
if (rope_y1[i] < 500){
yv += 10;
}

//rope_x2[i] = rope_x1[i] + (xv * .01);
//rope_y2[i] = rope_y1[i] + (yv * .01);

velocity_x[i] = velocity_x[i] * .001 + (xv * .01);
velocity_y[i] = velocity_y[i] * .001 + (yv * .01);
rope_x2[i] = rope_x1[i] + velocity_x[i];
rope_y2[i] = rope_y1[i] + velocity_y[i];

} else if (i == pointCount - 1) {
/*double x_vector1 = rope_x1[i-1] - rope_x1[i];
double y_vector1 = rope_y1[i-1] - rope_y1[i];
double magnitude1 = Math.sqrt(Math.pow((double) x_vector1,2.00) + Math.pow((double) y_vector1,2.00));
double extension1 = magnitude1 - .5;

double xv = (x_vector1 / magnitude1 * extension1);
double yv = (y_vector1 / magnitude1 * extension1) + 196;

//rope_x2[i] = rope_x1[i] + (xv * 1);
//rope_y2[i] = rope_y1[i] + (yv * 1);

velocity_x[i] = velocity_x[i] * .001 + (xv * .01);
velocity_y[i] = velocity_y[i] * .001 + (yv * .01);*/
//rope_x2[i] = rope_x1[i] + velocity_x[i];
//rope_y2[i] = rope_y1[i] + velocity_y[i];
rope_x2[i] = mouse_x;
rope_y2[i] = mouse_y;
}
}

for (int i = 0; i < pointCount; i++){
rope_x1[i] = rope_x2[i];
rope_y1[i] = rope_y2[i];
}

}

@Override
public void mouseClicked(MouseEvent arg0) {
// TODO Auto-generated method stub

}

@Override
public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub

}

@Override
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub

}

@Override
public void mousePressed(MouseEvent arg0) {
// TODO Auto-generated method stub
mouse_x = arg0.getX();
mouse_y = arg0.getY();
}

@Override
public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub

}
}
}
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Club Houses » Off Topic
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image