Advertisement
Guest User

Untitled

a guest
Oct 7th, 2013
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.93 KB | None | 0 0
  1. import java.applet.*;
  2. import java.awt.*;
  3. import java.awt.image.BufferedImage;
  4.  
  5.  
  6. public class asd extends Applet{
  7.     double prevRotation=0, boatRotation=0, x1, x2, y1, y2, i, r;
  8.     BufferedImage img = new BufferedImage(500, 500, BufferedImage.TYPE_BYTE_BINARY);
  9.     Graphics g1 = img.getGraphics();
  10.     StringBuffer c = new StringBuffer("summon Boat ~ ~2 ~ {");
  11.     String p = "}";
  12.     boolean resize = true;
  13.    
  14.    
  15.     /**********************************************************************/
  16.     double length = 6*Math.PI;
  17.     String riddenEntity = "Arrow, Riding:{id:MinecartRideable}";
  18.    
  19.     //Functions being graphed. Change length to show more/less
  20.     public double f(double i){
  21.         //return 6*Math.cos(5D/7D*i);    //length 7*PI
  22.         //return 7.3*Math.cos(2D/5D*i);  //length 10*PI
  23.         return 7.3*Math.cos(4D/3D*i);    //length 6*PI
  24.         //return i;
  25.     }
  26.     /**********************************************************************/
  27.    
  28.    
  29.    
  30.     public void init(){
  31.         setSize(500,500);
  32.     }
  33.    
  34.     public void update(Graphics g){
  35.         while(i<length){
  36.             r = f(i);
  37.             x1 = x2 = r*Math.cos(i);
  38.             y1 = y2 = r*Math.sin(i);
  39.            
  40.             while(Math.pow((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1), 0.5)<0.4){
  41.                 i+=0.00001;//instead of doing math let's use a *really* big loop =D
  42.                 r = f(i);
  43.                 x2 = r*Math.cos(i);
  44.                 y2 = r*Math.sin(i);
  45.             }
  46.            
  47.             r = f(i-0.001);
  48.             x1 = r*Math.cos(i-0.001);
  49.             y1 = r*Math.sin(i-0.001);
  50.             prevRotation = boatRotation;
  51.             boatRotation= Math.atan((y2-y1)/(x2-x1))*57.2957;
  52.  
  53.             while(boatRotation<prevRotation){
  54.                 boatRotation+=180;
  55.             }
  56.            
  57.             g1.fillRect(250+(int)(20*x2), 250+(int)(20*y2), 2, 2);
  58.             c.append("Rotation:["+(int)(boatRotation*10)/10D+"F,0F],Riding:{id:Boat,");
  59.             p+="}";
  60.         }
  61.        
  62.         c.replace(c.length()-5, c.length(), riddenEntity+p);
  63.         System.out.print(resize?(c.length()<16376?c:c+"\ntoo long for command block!"):"");
  64.         resize=false;
  65.         g.drawImage(img, 0, 0, null);
  66.     }
  67.    
  68.     public void paint(Graphics g){
  69.         update(g);
  70.     }
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement