Processing 用鼠标在tuio中绘制椭圆
嗨,如果有人能帮我,我将非常感激,我有一个草图,可以让用户用无线喷壶在屏幕上画涂鸦。此时,安装tuio代码后,当用户按下鼠标按钮时,会发出喷射声。。但是当按下鼠标按钮时,我在绘制椭圆草图时遇到了困难Processing 用鼠标在tuio中绘制椭圆,processing,Processing,嗨,如果有人能帮我,我将非常感激,我有一个草图,可以让用户用无线喷壶在屏幕上画涂鸦。此时,安装tuio代码后,当用户按下鼠标按钮时,会发出喷射声。。但是当按下鼠标按钮时,我在绘制椭圆草图时遇到了困难 This is my code; import ddf.minim.spi.*; import ddf.minim.signals.*; import ddf.minim.*; import ddf.minim.analysis.*; import ddf.
This is my code;
import ddf.minim.spi.*;
import ddf.minim.signals.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.ugens.*;
import ddf.minim.effects.*;
Minim minim;
AudioPlayer player;
AudioInput input;
/*TUIO processing demo - part of the reacTIVision project
http://reactivision.sourceforge.net/
Copyright (c) 2005-2009 Martin Kaltenbrunner <mkalten@iua.upf.edu>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You shgould have greceived a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// we need to import the TUIO library
// and declare a TuioProcessing client variable
import TUIO.*;
TuioProcessing tuioClient;
import java.util.*; //ADD THIS LINE TO BE ABLE TO USE TUIOCLIENT WITH PROCESSING 2+
// these are some helper variables which are used
// to create scalable graphical feedback
float cursor_size = 15;
float object_size = 60;
float table_size = 760;
float scale_factor = 1;
PFont font;
//declare a boolean to check mouse click
boolean drag = false;
int n=0;
int size[]= {20,40};
int sizeChosen;
boolean inside = false;
PImage bg;
PImage img;
PGraphics pg;
import controlP5.*;
ControlP5 cp5;
boolean mp = true;
void setup ()
{
size(1000,1000);//size(screen.width, screen.height).
smooth();
noStroke();
fill(0);
loop();
frameRate(30);
hint(ENABLE_NATIVE_FONTS);
font = createFont("Arial",18);
scale_factor = height/table_size;
// we create an instance of the TuioProcessing client
// since we add "this" class as an argument the TuioProcessing class expects
// an implementation of the TUIO callback methods (see below)
tuioClient = new TuioProcessing(this);
ellipseMode( CENTER);
//smooth();
noCursor();
background(170);
bg = loadImage("brickwall.jpg");
background(bg);
img = loadImage("instructions.jpg");
image (img,30,40,THUMB_SIZE, THUMB_SIZE);
cp5 = new ControlP5(this);//screenshot button
cp5.addButton("Save Graffiti Artwork").setPosition(0,650).setSize(200,100);//screenshot details
minim = new Minim(this);
player = minim.loadFile("spray_close.wav");
input = minim.getLineIn();
}
void draw() {
if (mp = true);
ellipse(255,0,255,0);
background(bg);
textFont(font,18*scale_factor);
float obj_size = object_size*scale_factor;
float cur_size = cursor_size*scale_factor;
Vector tuioObjectList = tuioClient.getTuioObjects();
for (int i=0;i<tuioObjectList.size();i++) {
TuioObject tobj = (TuioObject)tuioObjectList.elementAt(i);
noStroke();
fill(0);
pushMatrix();
translate(tobj.getScreenX(width), tobj.getScreenY(height));
rotate(tobj.getAngle());
// ellipse(-obj_size/2, -obj_size/2, obj_size, obj_size);
popMatrix();
//fill(255);
text(""+tobj.getSymbolID(), tobj.getScreenX(width), tobj.getScreenY(height));
if (mousePressed) {
ellipse(255,0,255,0);
// printIn("Pink");
//mouse press 1
if (tobj.getSymbolID()==12) {
ellipse(255,0,255,0);
}
}
}
Vector tuioCursorList = tuioClient.getTuioCursors();
for (int i=0;i<tuioCursorList.size();i++) {
TuioCursor tcur = (TuioCursor)tuioCursorList.elementAt(i);
Vector pointList = tcur.getPath();
if (pointList.size()>0) {
stroke(0, 0, 255);
TuioPoint start_point = (TuioPoint)pointList.firstElement();
;
for (int j=0;j<pointList.size();j++) {
TuioPoint end_point = (TuioPoint)pointList.elementAt(j);
line(start_point.getScreenX(width), start_point.getScreenY(height), end_point.getScreenX(width), end_point.getScreenY(height));
start_point = end_point;
}
stroke(192, 192, 192);
fill(192, 192, 192);
ellipse( tcur.getScreenX(width), tcur.getScreenY(height), cur_size, cur_size);
fill(0);
text(""+tcur.getCursorID(), tcur.getScreenX(width)-5, tcur.getScreenY(height)+5);
}
}
if (drag) //if drag = true, i-e if mouse click is holding, ellipse are drawing according the mouse's position
{
fill(#FF00FF); //black color
ellipse(mouseX, mouseY, 50,50); //draw ellipse with x and y mouse's position + size 10*10
//or line strokeWeight(3);stroke(0);line(mouseX,mouseY,25,25);
}
//draw palette size
for(n=0;n<2;n++)
{
fill(0);
ellipse(360,10+n*40,20*(n+1),20*(n+1));
}
}
//size selector
void mousePressed() {
//bDrawFullSize = true;
if (inside==true){
sizeChosen=size[n];
}
player.play();
mp = true;
}
void mouseReleased() {
//bDrawFullSize = true;
drag = false;
player.close();
//since close closes the file, we need to load the sound effect again.
player = minim.loadFile("spray_close.wav");
}
//function "drag and drop"
void mouseDragged() {
drag = true;
}
// these callback methods are called whenever a TUIO event occurs
// called when an object is added to the scene
void addTuioObject(TuioObject tobj) {
println("add object "+tobj.getSymbolID()+" ("+tobj.getSessionID()+") "+tobj.getX()+" "+tobj.getY()+" "+tobj.getAngle());
}
// called when an object is removed from the scene
void removeTuioObject(TuioObject tobj) {
println("remove object "+tobj.getSymbolID()+" ("+tobj.getSessionID()+")");
}
// called when an object is moved
void updateTuioObject (TuioObject tobj) {
println("update object "+tobj.getSymbolID()+" ("+tobj.getSessionID()+") "+tobj.getX()+" "+tobj.getY()+" "+tobj.getAngle()
+" "+tobj.getMotionSpeed()+" "+tobj.getRotationSpeed()+" "+tobj.getMotionAccel()+" "+tobj.getRotationAccel());
}
// called when a cursor is added to the scene
void addTuioCursor(TuioCursor tcur) {
println("add cursor "+tcur.getCursorID()+" ("+tcur.getSessionID()+ ") " +tcur.getX()+" "+tcur.getY());
}
// called when a cursor is moved
void updateTuioCursor (TuioCursor tcur) {
println("update cursor "+tcur.getCursorID()+" ("+tcur.getSessionID()+ ") " +tcur.getX()+" "+tcur.getY()
+" "+tcur.getMotionSpeed()+" "+tcur.getMotionAccel());
}
// called when a cursor is removed from the scene
void removeTuioCursor(TuioCursor tcur) {
println("remove cursor "+tcur.getCursorID()+" ("+tcur.getSessionID()+")");
}
// called after each message bundle
// representing the end of an image frame
void refresh(TuioTime bundleTime) {
redraw();
}
void keyPressed() {
endRecord();
background(bg);
// exit();
}
public void saveScreen() {
saveFrame();
player.pause();
}
// returns true if mouse is inside this rectangle
boolean inside(int left, int top, int right, int bottom ) {
if (mouseX>left && mouseX<right && mouseY>top && mouseY<bottom ) {
return true;
}
else {
return false;
}
}
这是我的代码;
进口ddf.minim.spi.*;
输入ddf最小信号。*;
进口ddf.微量。*;
进口ddf.微量分析。*;
进口ddf.minim.ugens.*;
进口ddf.最小影响。*;
极小极小;
音频播放器;
音频输入;
/*TUIO处理演示-Reactiviion项目的一部分
http://reactivision.sourceforge.net/
版权所有(c)2005-2009 Martin Kaltenbrunner
这个程序是自由软件;您可以重新分发和/或修改它
它是根据GNU通用公共许可证的条款发布的
自由软件基金会;许可证的第2版,或
(由您选择)任何更高版本。
这个节目的发布是希望它会有用,
但无任何保证;甚至没有任何关于
适销性或适合某一特定目的。见
有关更多详细信息,请参阅GNU通用公共许可证。
您应该已经收到GNU通用公共许可证的副本
与此同时,;如果没有,请写信给自由软件
基金会,59寺庙广场,套房330,波士顿,MA 02111-1307美国
*/
//我们需要导入TUIO库
//并声明一个TuioProcessing客户端变量
进口屠宰场*;
TuioProcessing tuioClient;
导入java.util.*//添加此行以便能够将TUIOCLIENT用于处理2+
//这些是使用的一些辅助变量
//创建可伸缩的图形反馈
浮动光标_size=15;
浮动对象大小=60;
浮动台_尺寸=760;
浮动比例系数=1;
字体;
//声明一个布尔值以检查鼠标单击
布尔阻力=假;
int n=0;
int size[]={20,40};
int sizeChosen;
布尔内部=假;
皮马杰bg;
皮马杰;
PGraphics-pg;
进口管制P5.*;
控制p5-cp5;
布尔值mp=true;
无效设置()
{
大小(10001000);//大小(屏幕.宽度,屏幕.高度)。
光滑的();
仰泳();
填充(0);
loop();
帧率(30);
提示(启用本地字体);
font=createFont(“Arial”,18);
比例系数=高度/桌子尺寸;
//我们创建TuioProcessing客户端的一个实例
//由于我们将“this”类添加为TuioProcessing类所期望的参数
//TUIO回调方法的实现(见下文)
tuioClient=新的TuioProcessing(this);
ellipseMode(中心);
//光滑的();
noCursor();
背景(170);
bg=loadImage(“brickwall.jpg”);
背景(bg);
img=loadImage(“instructions.jpg”);
图像(img,30,40,拇指大小,拇指大小);
cp5=新控件p5(此);//屏幕截图按钮
cp5.addButton(“保存涂鸦艺术品”).setPosition(0650).setSize(200100);//屏幕截图详细信息
最小值=新的最小值(本);
player=minim.loadFile(“spray_close.wav”);
输入=minim.getLineIn();
}
作废提款(){
如果(mp=true);
椭圆(255,0255,0);
背景(bg);
textFont(字体,18*比例系数);
浮动对象大小=对象大小*比例系数;
浮动电流大小=光标大小*比例系数;
Vector tuioObjectList=tuioClient.getTuioObjects();
对于(int i=0;i函数下的任何内容:
void mousePressed() {
//bDrawFullSize = true;
if (inside==true){
sizeChosen=size[n];
}
player.play();
mp = true;
}
在按下鼠标时每帧运行一次。因此,您可以在此处创建椭圆(或任何您想要的)。您可以将椭圆生成函数放入分支条件中,该条件检查鼠标按下的状态:
if (mousePressed) {
ellipse(random(0,width),random(0,height),random(0,100),random(0,100));
}
将条件放在绘图函数的末尾,使其覆盖任何背景元素嘿,我做了一个非常类似的项目……想分享一下它的进展吗?