メニュー 閉じる

088. ProcessingでOSC通信をもう少しやってみる

import oscP5.*;
import netP5.*;

OscP5 osc;

NetAddress net_address;

int broadcast_port = 12000;
int listening_port = 12000;

boolean connect;

PFont font_data;

String[] font_list = PFont.list ();

PImage color_base;

void setup () {

	size (displayWidth, displayHeight);
	colorMode (RGB, 255);
	background (0);
	orientation (LANDSCAPE);

	font_data = createFont ("Arial-Bold.ttf", 100);

	osc = new OscP5 (this, broadcast_port);

	net_address = new NetAddress ("192.168.1.15", listening_port);

	color_base = loadImage ("color_base.jpg");

	connect = true;

}

void draw () {

	background (0);

	image (color_base, width - 180.0, 0.0);

	OscMessage message01 = new OscMessage ("/mouse/position");

	if (connect == true && mouseX < width - 180.0) {
		message01.add (mouseX);
		message01.add (mouseY);
		osc.send (message01, net_address);
	}

	OscMessage message02 = new OscMessage ("/color/picker");

	if (connect == true && mouseX > width - 180.0) {
		loadPixels ();
		color col = pixels[int (mouseY) * width + int (mouseX)];
		message02.add (red (col));
		message02.add (green (col));
		message02.add (blue (col));
		osc.send (message02, net_address);
		fill (255);
		stroke (0);
		strokeWeight (1);
		rectMode (CENTER);
		rect (mouseX, mouseY, 20, 20);
	}

	fill (255);
	noStroke ();
	textFont (font_data);
	textAlign (CENTER, CENTER);
	textSize (20);
	textLeading (20);
	text ("OSC Client by Processig for Android", width / 2, height - 60);

	if (connect == true && mouseX < width - 180.0) {
		fill (0);
		stroke (255);
		strokeWeight (1);
		line (0, mouseY, width, mouseY);
		line (mouseX, 0, mouseX, height);
		rectMode (CENTER);
		rect (mouseX, mouseY, 40, 40);
	}

}

void mousePressed () {

}

void mouseReleased () {

}
Posted in processing