Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all 2896 articles
Browse latest View live

Finding camera up with yaw, pitch and roll?

$
0
0

Hey!

I am trying to do object picking with rays in Processing. Everything works fine, except I cannot find the right 'up' vector of the camera. I am using Peasy library.

I could get the cameraUp vector by:

right = PVector.cross(view,new PVector(0,0,1)); then

cameraUp = PVector.cross(view, right);

However the problem is that when I am orbiting with the camera the up vector (0,0,1) gets rotated. I would like to find the up vector of the rotated coordinate system. Peasy lets you access the pitch, yaw and roll.

I tried doing it with:

    up.x = cos(cam.getRotations()[0])*sin(cam.getRotations()[1]);
    up.y = -cos(cam.getRotations()[1]);
    up.z = sin(cam.getRotations()[0])*sin(cam.getRotations()[1]);

and a few similar versions, but I just can't get it to work. it might be due to peasy defining the axis differently.

Any hint on how I could solve this?

Any answer would be much appreciated:)


Problem importing a .STL model

$
0
0

When I import a STL model using toxiclibs, the object is rendered with all the normals of the mesh polygons. How can I turn off showing of all the normals?

Creating only one set of random values for every number slider update

$
0
0

Hi,

I was trying to create a slider controlled random distribution of points in a sketch. I wrote the code as shown below. Although it changes the number of random points when I update the slider value, it continuously produce new points and update position. I know it is happening because I kept the for loop inside the draw() function. How can I create only one collection of random point positions so that the points wont looks like they are flickering around .?

`import controlP5.*;
ControlP5 mycp5;

int number;

void setup() {

  size(600, 600);

  mycp5 = new ControlP5(this);

  mycp5.addSlider("number")
    .setPosition(300, 300)
    .setSize(100, 20)
    .setRange(0, 20)
    .setValue(1)
    ;
}

void draw() {

  background(250);

  for (int i =0; i<number; i++) {

    fill(200, 0, 0);
    ellipse(random(10, 200)+i*2, random(0, 200)+i*10, 10, 10);
  }
}
`

How to upload pictures taken on webcam via processing directly to website as they are taken?

$
0
0

The question already kinda describes what I'm going for. I need a code to use on Processing that can upload my pictures directly to a domain automatically upon the picture being taken. The code I have currently is:

import processing.video.*; Capture webcam;

void setup() { size(640,480); webcam = new Capture(this,640,480);
String[] devices = Capture.list(); println(devices); webcam.start();

}

void draw() { if (webcam.available() == true) { webcam.read(); image(webcam ,0,0); } saveFrame("line.bmp"); } Which allows me to take the photo from the webcam just fine. Now the hard part, automatic uploading.

Any help would be much appreciated,

Thanks!

Is it possible to use play a movie as background for video capture?

$
0
0

I want to use a movie as background while capturing video.

The movie will be displayed on all the black pixels (or white pixels) of my captured video (those pixels in the captures video are suppose to be transparent).

Does anyone know if this could even be possible?

Thanks a lot. Your help is blessed.

How can I use the camera as input to control the speed of a movie?

$
0
0

I want to use the camera as input (if there's a lot of frame by frame change the value will be ~1, if there's little frame by frame change the value will be ~0) to control the speed (ranging from x0.5 to x2) of a 10 second movie which will be constantly looping.

I couldn't manage to figure out how to do that. I'm probably using the video library wrong.

Would appreciate any help! <3

Is it possible to patch SinOsc (processing sound) with minim?

$
0
0

I have a working sketch using SinOsc to produce a variable sound. I would like to record the output and the only way I have found to do this is through Minim. However, I am not keen on the alternative of Oscil wave on minim. I am probably coding it wrong for I am sure it can do the same thing. On my original sketch I have SinOsc being affected by a variable: fNoise = map(lerpFdata, 0, 255, 0, 100); sine0.freq(fNoise);

And on the sketch using minim I have this: fNoise = map( lerpFdata, 0, 255, 100, 200); wave1 = new Oscil( fNoise,0.5, Waves.SINE ); wave1.patch( out );

The result with SinOsc is smooth, whilst with Oscil it is quite patchy .

I am new to Processing and I am clueless as to where the mistake might be. Any suggestions or help welcome! thanks

ControlP5 error?

$
0
0

hi

here is the order that the code employs: entertext black record button is made visible
press record button turns red theEvent.getController().getName() feeds back recording press record button disappears and save button appears theEvent.getController().getName() feeds back recording press save button theEvent.getController().getName() feeds back recording why is it not returning saving as button pushed

import controlP5.*; ControlP5 cp5; import oscP5.*; import netP5.*; String kissersNames; Table writeTable, readTable; int buttonStatus; boolean oscStatus = true; OscP5 oscP5; NetAddress myRemoteLocation1, myRemoteLocation2, myRemoteLocation3; void setup() { size(300, 150); noStroke(); cp5 = new ControlP5(this); PImage replayPlay = loadImage("replay.png"); PImage replayStop = loadImage("replayStop.png"); PImage recordPlay = loadImage("recording.png"); PImage recordStop = loadImage("stopRecording.png"); PImage saves = loadImage("saved.png"); buttonStatus =0;

cp5.addTextfield("enterKissers") .setPosition(10, 20) .setSize(250, 20) .setAutoClear(false) ; cp5.addToggle("replay") .setPosition(150, 60) .setImages(replayStop, replayPlay) .updateSize() ; cp5.addToggle("recording") .setValue(1) .setPosition(10, 60) .setImages(recordPlay, recordStop) .updateSize() .setVisible(false) ;

cp5.addButton("saving")
.setValue(1)
.setPosition(80, 60)
.setImage(saves)
.updateSize()
.setVisible(false)
;

/* start oscP5, listening for incoming messages at port 12000 */ }

public void saving(int theValue) { /* send the message */ println("saved"); if (buttonStatus==3) {
//println("kissersNames= " +kissersNames); //saveTable(writeTable, kissersNames);
markers(104); cp5.getController("recording").setValue(0.0); buttonStatus=-1; } } public void recording(int theValue) { if (buttonStatus==0) { delay(2000); markers(101);
markers(102); oscStatus = true; buttonStatus++; } else if (buttonStatus==1) { buttonStatus++; } else if (buttonStatus==2) { buttonStatus++; cp5.getController("saving").setVisible(true); cp5.getController("recording").setVisible(false); markers(103); markers(104); } }

void controlEvent(ControlEvent theEvent) { println("this event was triggered by Controller " + theEvent.getController().getName());

if (theEvent.isFrom(cp5.getController("replay"))) { } if (theEvent.isFrom(cp5.getController("enterKissers"))) { cp5.getController("recording").setVisible(true); //cp5.getController("saving").setVisible(false); // cp5.getController("saving"). // TableRow newRow = writeTable.addRow(); //println(writeTable.getRowCount()); // saveTable(writeTable, kissersNames); } } void markers(int markers) { println("Markers" +" ," + markers); } void draw() { //println(kissersNames); background(0); }


Football data API

$
0
0

I am trying to get data from the football-data.org API. My code looks like this:

import java.net.*;

String Link = "http://api.football-data.org/v1/teams/66/";

void setup()
{
  String[] results = null;
  try
  {
    URL url= new URL(Link);
    URLConnection connection = url.openConnection();
    connection.setRequestProperty("X-Auth-Token","XXXXXXXXXXXXXXXXXXXXXXXXXXXX");
    connection.setRequestProperty("X-Response-Control","minified");

    results = loadStrings(connection.getInputStream());
  }
  catch (Exception e)
  {
    e.printStackTrace();
  }

  if (results != null)
  {
    for (int i=0; i<results.length; i++) { System.out.format(results[i]); }
  }
}

The data is being printed like this:

{"id":66,"name":"Manchester United FC","shortName":"ManU","squadMarketValue":"534,250,000 €","crestUrl":"http://upload.wikimedia.org/wikipedia/de/d/da/Manchester_United_FC.svg"}

but I want it like this:

{"id":66,

"name":"Manchester United FC",

"shortName":"ManU",

"squadMarketValue":"534,250,000€",

"crestUrl":"http://upload.wikimedia.org/wikipedia/de/d/da/Manchester_United_FC.svg"}

Can someone please help me? (I'm sorry, i'm new to processing)

Can Processing work with .sf2 files or something similar?

$
0
0

I made a simple music keyboard program with processing, and I want some decent samples for it. Is there a library that can handle soundfonts like sf2? I COULD record sounds from various synth apps on my iPad and map each note in the program, but that would take up a huge amount of time and effort (even with a MIDI-based automation program I wrote for Arduino, it takes 14.5 minutes for it to record a 10 second sample of all 88 keys and who knows how long for me to split and export), not to mention memory in the sketch's data folder. Surely there's a better way...?

Disclaimer: I've only just heard of the existence of soundfonts not ten minutes ago, but my Googling brought up nothing useful for Processing integration... Just false alarms and a 2-year-old forum post with no replies.

Receiving multiple udp messages

$
0
0

Only been using Processing fairly recently but I want to use it for a project where it will collate and send out various udp messages

Essentially it needs to be able to send out to one udp message but receive data in from 3 different machines which have each there own ip and port numbers. Looking through the examples I can see how I would write code to send out udp frames to multiple nodes but I have not seen how you receive multiple data frames.

Basically I can't see how to use "void receive" to receive the different data packets and then assign them so that I do the correct process on them

Thanks

Paul

How to make a cube face a 3D coordinate (x,y,z) ?

$
0
0

Hi,

I have a problem with a sketch in witch I need to make some cubes face a certain coordinate in P3D it works for the Z axis just like 2D with atan2() but when it comes to the X and Y axis it doesn't work :/

here is the code I have for now:


import peasy.*;

PeasyCam cam;


float x;
float y;
float z;

void setup() {
  size(500,500,P3D);
  cam = new PeasyCam(this, 100);
}

void draw() {
  background(50);

  //the angles
  float angleZ = atan2(-x,y); //-x,y
  float angleX = atan2(0,z);
  float angleY = atan2(-z,x);

  //Cube that need to face the target
  pushMatrix();
  rotateZ(angleZ);
  rotateX(angleX);
  //rotateY(angleY);
  translate(0,0,0);
  box(100);
  line(0,0,0,0,1000,0);
  popMatrix();

  //Cube that need to face the target
  pushMatrix();
  translate(1000,1000,1000);
  rotateZ(atan2(-x+1000,y-1000));
  //rotateX(atan2(y+100,-z-100));
  box(100);
  line(0,0,0,0,1000,0);
  popMatrix();

  //to control the little cube (target)
  if(keyPressed) {
   if(keyCode==UP) {
      y+=4;
    }
    if(keyCode==DOWN) {
      y-=4;
    }
    if(keyCode==LEFT) {
      x+=4;
    }
    if(keyCode==RIGHT) {
      x-=4;
    }
    if(key==' ') {
      z+=4;
    }
    if(keyCode==SHIFT) {
      z-=4;
    }
  }

  //little cube (taget)
  pushMatrix();
  translate(x,y,z);
  box(50);
  popMatrix();
}

I used the peasyCam so its easier to see and control

float x,y,z are the targets to face, you can control them with Arrows Space and Shift

thanks !

How can I (quickly) retrieve video frames one at a time, indexed by time/frame number?

$
0
0

I am trying to synchronize an animation and video and save the output as a new video. The animation is based on data collected at arbitrary times, roughly at 20 fps (but not close enough to look right at that speed). Therefore I need to tag the data with the time it is collected and display the corresponding frame of the video each time a new data point is loaded.

It is simple to do this using Movie.jump(), but that function takes several seconds to complete, so rendering an entire video is intractably slow. I also tried using the jmcvideo library, but it only works with Processing 1.5.1 and doesn't display frames correctly.

Is there another library or function that can load video frames quickly? Rendering in real-time is acceptable, but any slower will make the whole program useless. Thanks!

How can I visualise tweets on a map in Processing?

$
0
0

I'm trying to use the twitter API to search for a keyword and get the location of that particular tweet to then visualise onto a map.

I've successfully created my map using unfolding maps and tilemill, I'm just struggling with the twitter part. Using the twitter 4J library, I've tried the following code but I'm not able to get the location as coordinates. Also, once I've got the coordinates I dont know how to go about visualising them on my map.

import twitter4j.conf.*;
import twitter4j.api.*;
import twitter4j.*;

import java.util.List;
import java.util.Iterator;

ConfigurationBuilder   cb;
Query query;
Twitter twitter;

ArrayList<String> twittersList;
Timer             time;

//Number twitters per search
int numberSearch = 10;

PFont font;
int   fontSize = 14;

void setup() {
  size(670, 650);
  background(0);
  smooth(4);

  //FONT
  font = createFont("NexaLight-16.vlw", fontSize, true);
 textFont(font, fontSize);

  //You can only search once every 1 minute
  time = new Timer(70000); //1 min with 10 secs

  //Acreditacion
  cb = new ConfigurationBuilder();
  cb.setOAuthConsumerKey("**********");
  cb.setOAuthConsumerSecret("***********");
  cb.setOAuthAccessToken("**************");
  cb.setOAuthAccessTokenSecret("*************");

  //Make the twitter object and prepare the query
  twitter = new TwitterFactory(cb.build()).getInstance();

  //SEARCH
  twittersList = queryTwitter(numberSearch);
}

void draw() {
  background(50);

  //draw twitters
  drawTwitters(twittersList);


  if (time.isDone()) {
    twittersList = queryTwitter(numberSearch);
    time.reset();
   }

  text(time.getCurrentTime(), 20, 30);

  time.update();
}

 void drawTwitters(ArrayList<String> tw) {
   Iterator<String> it = tw.iterator();
  int i = 0;

  while (it.hasNext ()) {
      String twitt = it.next();
    fill(150);
    text(i + 1, 27, 60 + i*(fontSize)*4 + fontSize);
    fill(220);
    text(twitt, 50, 60 + i*(fontSize)*4, 600,  fontSize*4);
    i++;
  }
}

 double lat = 63.894947;
double lon = -22.054045;
double res = 10;
String resUnit = "mi";

ArrayList<String> queryTwitter(int nSearch) {
  ArrayList<String> twitt = new ArrayList<String>();

  query = new Query("#happy");
  query.setCount(nSearch);
  try {
    QueryResult result = twitter.search(new Query().geoCode(new GeoLocation(lat, lon),res, resUnit));
    List<Status> tweets = result.getTweets();
    println("New Tweet : ");
    for (Status tw : tweets) {
      String msg = tw.getText();
       String usr = tw.getUser().getScreenName();
      String twStr = "@"+usr+": "+msg;
      println(twStr);
      twitt.add(twStr);
    }


  }
  catch (TwitterException te) {
    println("Couldn't connect: " + te);
  }

  return twitt;
    }

I'm quite new to processing, so please be patient with me as I don't even know if I'm going about this the right way.

Any help would be gratefully appreciated!!

Cant get random speed for the ellipse

$
0
0

Hello everyone,

I have programmed a very simple ping pong-ish but the ball does not bounce back randomly. I want the Y speed to be random. (for example -4 and -8).

Here is the whole code

import ddf.minim.*;

AudioPlayer player;
Minim minim;//audio context
int base=30;
int x,y,gameScore=0;
int changeX=-8;
int changeY=-6;
int gameOver=0;
PImage img;
void setup()
{
  size(760, 640);
  x=(int)random(width);
  y=height-base;
  minim = new Minim(this);
  player = minim.loadFile("work.mp3", 2048);
  player.play();
  img = loadImage("work.jpg");

}
void draw()
{
  if(gameOver==0)
  {
  background(img);
  text("SCORE:"+gameScore+"",width/2,height/2);
  rect(mouseX,height-base,160,base);
  ellipse(x,y,15,15);
  x=x+changeX;
  y=y+changeY;
  if(x<0 | x>width)
  {
    changeX=-changeX;
  }
  if(y<0)
  {
    changeY=-changeY;
  }
  if(y>height-base)
  {
    //check whether it is falling inside the rectangle or not
    if(x>mouseX && x<mouseX+200)
    {
      changeY=-changeY; //bounce back
      gameScore++;
    }
    else
    {
      gameOverSplash();
    }
  }
  }
  else
  {
    background(100,100,200);
    text("Game Over!",width/2,height/2);
    text("CLICK TO RESTART",width/2,height/2+20);
  }
}
void gameOverSplash()
{
  gameOver=1;
}
void mouseClicked()
{
  changeY=-changeY;
  gameScore=0;
  gameOver=0;
}
void stop()
{
  player.close();
  minim.stop();
  super.stop();
}

I really would appreciate your help. Thanks


3d brush to move points

$
0
0

movement

Hello. I'm in "dead end" with my code and I need help. Trying to create my own little 3d sculpting app. My main question now is how to create something like "Move Brush", to move the points up and down, left and right (look at screenshot from Zbrush sculpting app, something like this). The main problem is that my brush in moving on the screen which is 2d coordinates, but my points is in rotating 3d space. Can't understand how to make 3d coordintes hold still and move only in 2d space, parallel to the screen.

Here is the code, PeasyCam library is required, you can rotate zoom and pan using mouse.

import peasy.*;
PeasyCam jcam;

float r=200;
int segments=30;
int brushsize = 200;

ArrayList <Point> points = new ArrayList <Point>();

Brush brush;


void setup()
{
  size(800,800,P3D);
  jcam = new PeasyCam(this,600);

  for(int i=0; i<segments;i++)   // initialize
  {
    float lat = map(i,0,segments,-HALF_PI,HALF_PI);
    for(int j=0;j<segments;j++)
    {
      float lon=map(j,0,segments,-PI,PI);

      float x = r*sin(lon)*cos(lat);
      float y = r*sin(lon)*sin(lat);
      float z = r*cos(lon);
      PVector temp = new PVector(x,y,z);
      Point pt1= new Point(temp);
      points.add(pt1);
    }
  }

  PVector brushPos = new PVector(0,0);
  brush = new Brush(brushPos);
}


void draw()
{
  background(150);

   for (int i = points.size ()-1; i >= 0; i--)   // points display
  {
    points.get(i).display();
  }

  for(int i=0;i<points.size();i++)   // smooth selection
  {
    float xx = screenX(points.get(i).pos.x,points.get(i).pos.y);
    float yy = screenY(points.get(i).pos.x,points.get(i).pos.y);

    float force = (dist(xx,yy,mouseX,mouseY)*255)/(brushsize/2);

    colorMode(RGB);
    if(dist(xx,yy,mouseX,mouseY)<brushsize/2)
    {
      points.get(i).colore = color(255,0+force,0+force);
    }
    else
    {
      points.get(i).colore = 255;
    }
  }


  jcam.beginHUD();   // 2D menu


  brush.pos= new PVector(mouseX,mouseY);  // brush
  brush.display();


  jcam.endHUD();
}


class Point
{
  PVector pos;
  color colore;

  Point(PVector posIn)
  {
    pos = posIn;
  }

  void display()
  {
    noStroke();
    fill(colore);
    pushMatrix();
    translate(pos.x,pos.y,pos.z);
    box(3);
    popMatrix();
  }
}


class Brush
{
  PVector pos;
  color brColor = color(255,0,0);

  Brush(PVector posIn)
  {
    pos = posIn;
  }

  void display()
  {
    noFill();
    stroke(255,0,0);
    pushMatrix();
    ellipse(pos.x,pos.y,brushsize,brushsize);
    ellipse(pos.x,pos.y,brushsize/2,brushsize/2);
    ellipse(pos.x,pos.y,2,2);
    popMatrix();
  }
}

only apply Force on event

$
0
0

Hello

I'm trying to connect midi input to natural forces (following the instructions of the Nature of code book) and I wonder how I can manage to add the force Wind on input of Note 59 (it works) but also to stop using the force wind when the note is not hit. For now the wind keeps adding each time I hit note 59, however I use acceleration.mult(0) in the update() function. Thank you very much for some tips.

functions in the class

 void applyForce(PVector force){
      PVector f = PVector.div(force,mass);
      acceleration.add(f);
      }

    void update(){
      velocity.add(acceleration);
      position.add(velocity);
      acceleration.mult(0);
    }

main

void draw() {
   background(10,15,25);

  //PVector wind = new PVector(random(0.01),random(-0.01));
  PVector gravity = new PVector(0,0.1);


   for (int i=0; i < tri.length; i++){
    tri[i].display();
    tri[i].update();
    tri[i].applyForce(gravity);
  //tri[i].applyForce(wind);
    tri[i].checkBoundaryCollision();
     }
}

    void onNote59 (int vel) {
        PVector wind = new PVector(10,10);
        for (int i=0; i < tri.length; i++){
        if (vel > 0 ) {
        tri[i].applyForce(wind);
      } else {
        // I don't know what to put here
      }
        }
    }

midi functions void midiMessage(MidiMessage message) {

          int note = (int)(message.getMessage()[1] & 0xFF) ;
          int vel = (int)(message.getMessage()[2] & 0xFF);

          println("Bus " + ": Note "+ note + ", vel " + vel);

          invokeNoteHandler(note, vel);
        }

        void invokeNoteHandler(int note, int velocity) {
          try {
            Class[] cls = new Class[1];
            cls[0] = int.class;
            Method handler = this.getClass().getMethod( "onNote" + note, cls );
            handler.invoke(this, velocity);
          } catch (Exception e) {
             e.printStackTrace();
          }
        }

Ball can't be seen on the client side

$
0
0

Has been struggling a while now, Trying to make pong using a client/server connection . The coördinates of both rectangles seem to be exchanged fine, the coördinates of the ball however won't.

I can't find the problem, but the weird thing is, I am doing exactly the same with the rectangle of the server send to the client, but when the server sends the coörds of the ball it just won't work.

server

import processing.net.*;

int size = 15; // Ball diameter
float xpos, ypos; // Position of the ball
float xspeed = random(5,6); // Speed of the ball in the x-direction
float yspeed = random(0,4); // Velocity of the ball in y-direction
int error1=0;
int error2=0;
int playerpos1;


Server s;
Client c;
String input;
int data[];

void setup() {
  s = new Server(this, 12345);  // Start a simple server on a port

  size(640, 400);
  noStroke();
  frameRate(30);
  smooth();
  playerpos1 = height/2;
  xpos = 45;
  ypos = playerpos1;
  frameRate(30);
}
void draw() {
  textSize(20);
  textAlign(CENTER);
  text ("Score: " + str(error2)+ ":" +str(error1) , width/2, 20);
    background(204);


  // Receive data from client
  c = s.available();
  if (c != null) {
    input = c.readString();
    input = input.substring(0, input.indexOf("\n"));  // Only up to the newline
    data = int(split(input, ' '));  // Split values into an array
    // Draw rect using received coords
    rect(data[0], data[1]-50, data[2], data[3]);
  }

 // speed of the ball
 xspeed *= 1.001;
 xpos += xspeed;
 ypos += yspeed;

// bounce the ball (up, down)
 if (ypos > height-size/2 || ypos < 0+size/2) {
 yspeed *= -1;
 }

// Boundary left and error
 if ( xpos <= 30+size/2) {
 if (ypos > playerpos1-50 && ypos < playerpos1+50){
 xspeed *= -1;
 yspeed += (ypos-playerpos1)/5;
 }
 }

 //Error 1
 if (xpos <= 0){
 error1 += 1;
 if (error1 <= 4){
 xpos = 50;
 ypos = playerpos1;
 xspeed = random(5,6);
 //xspeed *= -1;
 yspeed = 0;
println("Score: "+ str(error2)+":"+str(error1) );
 }
 if (error1 ==5) {
 println("Player 2 has won:"+ str(error2));
   text ("Player 2 has won " + str(error2), width/2, 20);
 }
 }

 // Right limit and error
 if ( xpos >= width-30-size/2) {
 if (ypos > data[1]-50 && ypos < data[1]+50){
 xspeed *= -1;
 yspeed += (ypos-data[1])/5;
 }
 }

 //Error 2
 if (xpos >= width){
 error2 +=1 ;
 if (error2 <= 4){
 xpos = width-50;
 ypos = data[1];
 xspeed = -random(5,6);
 //xspeed *= -1;
 yspeed = 0;
println("Score: "+ error2+":"+ error1 );
 }

 if (error2 ==5) {
 println("Player 1 has won:"+ str(error1));
   text ("Player 1 has won:" + str(error1), width/2, 20);
 }
 }

 // Draw the ball and the rectangles

 ellipse(xpos, ypos, size, size);
 rect (10, playerpos1-50,20,100);
 s.write(10 + " " + playerpos1 + " " + 20 + " " + 100 + " " + xpos + " " + ypos + " " + "\n");


// Move the rectangles
 if (keyPressed) {
   if (key == 'w') {
   if (playerpos1 >=50)
   playerpos1 = playerpos1 - 8;
   }
   if (key == 's') {
   if (playerpos1 <=height-50)
   playerpos1 = playerpos1 + 8;
   }
 }

}

client

import processing.net.*;


int playerpos2;


Client c;
String input;
int data[];
int size = 15;

void setup() {
  // Connect to the server’s IP address and port­
  c = new Client(this, "000.000.0.00", 12345); // Replace with your server’s IP and port

  size(640, 400);
  noStroke();
  frameRate(30);
  smooth();
  playerpos2 =height/2;
  frameRate(30);
}

void draw() {
    background(204);

    // Draw rect
     fill(255);
     rect(width-30, playerpos2-50,20,100);
    // Send mouse coords to other person
    c.write((width-30) + " " + playerpos2 + " " + 20 + " " + 100 + "\n");


  // Receive data from server
   if (c.available() > 0) {
    input = c.readString();
    input = input.substring(0,input.indexOf("\n"));  // Only up to the newline
    data = int(split(input, ' '));  // Split values into an array
    // Draw line using received coords
    fill(255);
    rect(data[0], data[1], data[2], data[3]);
    ellipse(data[4], data[5], size, size);
  }



   if (keyPressed) {
   if (key == 'i')
    {
     if (playerpos2 >=50)
     playerpos2 = playerpos2 - 8;
     }
     if (key == 'k') {
     if (playerpos2 <=height-50)
     playerpos2 = playerpos2 + 8;
   }
 }
}

Using a sound input to affect text.

$
0
0

I'm trying to self teach the Processing language, and struggling with something I'm trying to do for university.

This is probably quite simple for someone who knows what they're doing... I'm trying to use sound input to change the opacity of text. The louder the sound, the greater the opacity. Could someone help with the coding?

Many thanks hope someone can help!

I have use Google Map

$
0
0

I want to use google maps with processing 3 for GPS work with define location

Help me please....

Thank you very much

Viewing all 2896 articles
Browse latest View live