Advertisement
itblanco

SmoothMovementExample

May 31st, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.72 KB | None | 0 0
  1. import processing.net.*;
  2.  
  3. Client client;
  4. PVector pos, vel;
  5.  
  6. void setup() {
  7.   size(1000, 500);
  8.   client = new Client(this, "192.168.0.206", 30002);
  9.   float maxspeed = 5;
  10.   pos = new PVector(width/2, height/2);
  11.   vel = new PVector(random(-maxspeed,maxspeed), random(-maxspeed,maxspeed));
  12.   client.write("movej(p[0,-0.5,0.5,0,2,-2])\n");
  13.   delay(5000);
  14. }
  15.  
  16. void draw() {
  17.   background(0);
  18.   pos.add(vel);
  19.   if(pos.x > width || pos.x < 0) {
  20.    vel.x *= -1;
  21.   }
  22.   if(pos.y > height || pos.y < 0) {
  23.    vel.y *= -1;
  24.   }
  25.   noStroke();
  26.   fill(255);
  27.   circle(pos.x, pos.y, 40);
  28.   float scale = 0.07;
  29.   String msg = String.format("speedl([%.9s,0,%.9s,0,0,0], 0.5, 0.5)\n", vel.x*scale, -vel.y*scale);
  30.   client.write(msg);
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement