In Processing, I'm building a simple buttons interface. And the idea is that when you click on a button in the sketch. A text snippet from a different macOS application will launch a text snippet box.
At the moment, this text snippet box will be launched if I type a word in an email. So let's say I type (sample-a) in the email, and this will open a text snippet box that I have set up with this application.
But I want to trigger (sample-a) on a button click in Processing and not have to type this word in the email.
I searched the internet and looked at io.popen, os.execute and launch. But I wondered what the best way is to trigger a macOS "word" from Processing on a button click? Maybe do something with an echo command?
I hope someone can give me some tips or have an example code to create this function?
*added updated code:
// Import library for textfields
import g4p_controls.*;
GTextField txf1;
String sample;
boolean background = true;
// Button setup
final int btnX = 100;
final int btnY = 100;
final int btnW = 200;
final int btnH = 200;
public void setup() {
size(400, 600);
background(209, 209, 209);
// Button
rect(btnX, btnY, btnW, btnH);
// Textfield setup
txf1 = new GTextField(this, 100, 400, 200, 20);
}
public void draw() {
if (keyPressed && key == ENTER) {
}
}
public void handleTextEvents(GEditableTextControl textcontrol, GEvent event) {
if (txf1 == textcontrol && event == GEvent.ENTERED) {
sample = txf1.getText();
}
}
// Button trigger
void mousePressed() {
if (mouseX >= btnX && mouseX <= btnX + btnW && mouseY >= btnY && mouseY <= btnY + btnH) {
println("button clicked");
exec("open", "/Applications/TextExpander.app");
txf1.setText("sample");
}
}
New code for button interface with ControlP5 and Robot Class
import controlP5.*;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
boolean background = true;
// Robot function
Robot robot;
String keyString="template-1";
Robot1 robot1;
String keyString="template-2";
ControlP5 gui;
void setup() {
size(1440, 900);
gui = new ControlP5(this);
//Add a Button
gui.addButton("Template 1")
.setPosition(50, 50)
.setSize(100, 100)
.setValue(0)
.activateBy(ControlP5.RELEASE);
;
gui.addButton("Template 2")
.setPosition(200, 50)
.setSize(100, 100)
.setValue(0)
.activateBy(ControlP5.RELEASE);
;
// Robot function
try {
robot = new Robot();
robot1 = new Robot1();
}
catch (AWTException ex) {
System.out.println(ex.getMessage());
}
frameRate(1);
// Robot function
}
public void Template1(int value) {
println("Template 1 Button pressed");
sendKeys(robot, keyString);
}
public void Template2(int value) {
println("Template 2 Button pressed");
sendKeys(robot1, keyString);
}
public void controlEvent(ControlEvent theEvent) {
}
// Robot function for Template 1
void sendKeys(Robot robot, String keys) {
for (char c : keys.toCharArray()) {
int keyCode = KeyEvent.getExtendedKeyCodeForChar(c);
if (KeyEvent.CHAR_UNDEFINED == keyCode) {
throw new RuntimeException(
"Key code not found for character '" + c + "'");
}
robot.keyPress(keyCode);
robot.delay(100);
robot.keyRelease(keyCode);
robot.delay(100);
noLoop();
}
}
// Robot function for Template 2
void sendKeys(Robot1 robot1, String keys) {
for (char c : keys.toCharArray()) {
int keyCode = KeyEvent.getExtendedKeyCodeForChar(c);
if (KeyEvent.CHAR_UNDEFINED == keyCode) {
throw new RuntimeException(
"Key code not found for character '" + c + "'");
}
robot1.keyPress(keyCode);
robot1.delay(100);
robot1.keyRelease(keyCode);
robot1.delay(100);
noLoop();
}
}
void draw() {
}
Here is your source code as posted in the comments:
boolean background = true;
void setup() {
size(400, 400);
}
void draw() {
rect(100, 100, 200, 200);
}
boolean isMouseOver(int x, int y, int w, int h) {
if (mouseX >= x && mouseX <= x + w && mouseY >= y && mouseY <= y + h) {
return true;
}
return false;
}
void mousePressed() {
// if (isMouseOver(width/2, height/2, 100, 100) == true){
if (isMouseOver(100, 100, 200, 200) == true) {
println("button clicked");
// Process proc = I'm doing more research on this exec("open", "/Applications/TextExpander.app");
// name of the TextExpander abbreviation / shortcut = "(sample-a)"
// code that fire the word "(sample-a)" so that a TextExpander snippet will popup
}
}
As written there is a problem with mousePressed(); it will only pick up a button click toward the bottom of the button. Clicks at the top do nothing. That's due to an error in the line if(isMouseOver()== true) because the parameters are incorrect; they should be the same as the parameters that you used to create the rect initially, ie (100,100,200,200).
Alternate revision which shortens the code by obviating the function isMouseOver(). Rectangle coordinates are made constants so that if you want to change the size of the button later you only will have to change the parameter once instead of finding multiple occurrences in your code. Your initial version will certainly work as is, but I am only showing you a possible way to improve it. As you continue to experiment we can edit this post to reflect changes. Keep on experimenting and you should hopefully achieve your goal.
boolean background = true;
final int btnX = 100;
final int btnY = 100;
final int btnW = 200;
final int btnH = 200;
void setup() {
size(400, 400);
rect(btnX, btnY, btnW, btnH);
}
void draw() {
}
void mousePressed() {
if (mouseX >= btnX && mouseX <= btnX + btnW && mouseY >= btnY && mouseY <= btnY + btnH) {
println("button clicked");
// Process proc = I'm doing more research on this exec("open", "/Applications/TextExpander.app");
// name of the TextExpander abbreviation / shortcut = "(sample-a)"
// code that fire the word "(sample-a)" so that a TextExpander snippet will popup
}
}
Robot revision:
You don't need two robots; one will suffice. Likewise you don't need two sendKeys() function. Use one robot and send it a different string depending on which button is pressed. Whatever name is used for the button, that string is also used to called a corresponding function and the two must match precisely. That is, if you title the button 'template_1' then the function needs to be 'template_1()' also.
import controlP5.*;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
Robot robot;
ControlP5 gui;
String keyString = "template-1";
String keyString2 = "template-2";
void setup() {
size(350, 250);
gui = new ControlP5(this);
// Function that's called must match the button title.
gui.addButton("Template_1")
.setPosition(50, 50)
.setSize(100, 100)
.activateBy(ControlP5.RELEASE);
;
gui.addButton("Template_2")
.setPosition(200, 50)
.setSize(100, 100)
.activateBy(ControlP5.RELEASE);
;
try {
robot = new Robot();
} catch (AWTException ex) {
System.out.println(ex.getMessage());
}
}
void Template_1() {
println("Template 1 Button pressed");
sendKeys(keyString);
}
void Template_2() {
println("Template 2 Button pressed");
sendKeys(keyString2);
}
public void controlEvent(ControlEvent evnt) {
println(evnt);
}
void sendKeys(String keys) {
println("sendKeys fired.");
delay(3000); // Give user some time to set cursor
for (char c : keys.toCharArray()) {
println(c);
int keyCode = KeyEvent.getExtendedKeyCodeForChar(c);
if (KeyEvent.CHAR_UNDEFINED == keyCode) {
throw new RuntimeException(
"Key code not found for character '" + c + "'");
}
robot.keyPress(keyCode);
robot.delay(100);
robot.keyRelease(keyCode);
robot.delay(100);
}
}
void draw() {
}
Related
i have created an android app via xamarin.android. i have a multispinnersearch in a fragment and when opened normally, all the items inside it are preselected. but i had a problem. if the user touches the screen outside the spinner, the latter closes and all the items get into my list. i don't want that. unless he clicks "ok" in the spinner, no items should be taken to my list. so i tried to handle the touch event to prevent the selection of items on screen touch but it didn't work. here are the codes i tried:
public override bool DispatchTouchEvent(MotionEvent ev)
{
if (ev.Action == MotionEventActions.Down)
{
View v = CurrentFocus;
if (v is MultiSpinnerSearch)
{
Rect outRect = new Rect();
v.GetGlobalVisibleRect(outRect);
if (!outRect.Contains((int)ev.RawX, (int) ev.RawY))
{
Toast.MakeText(this, "shgsg", ToastLength.Long).Show();
}
}
}
return base.DispatchTouchEvent(ev);
}
i tried this in my main activity but i didn't work. then i tried this in my fragment on the ontouch listener interface:
if (e.Action == MotionEventActions.Down)
{
if (labors_dropdown.IsFocused == true)
{
Android.Graphics.Rect rect = new Rect();
labors_dropdown.GetGlobalVisibleRect(rect);
if (!rect.Contains((int)e.RawX, (int)e.RawY))
{
Toast.MakeText(this.Context, "gfgf", ToastLength.Short).Show();
}
}
}
it didn't work too, what should i do? thanks in advance.
You could try the below method:
public override bool DispatchTouchEvent(MotionEvent ev)
{
if (ev.Action == MotionEventActions.Down)
{
View v = (MultiSpinnerSearch)FindViewById<MultiSpinnerSearch>(Resource.Id.xxxxx);
if (!IsTouchPointInView(v, (int)ev.GetX(), (int)ev.GetY()))
{
Toast.MakeText(this, "shgsg", ToastLength.Long).Show();
}
}
return base.DispatchTouchEvent(ev);
}
private bool IsTouchPointInView(View targetView, int currentX, int currentY)
{
if (targetView == null)
{
return false;
}
int[] localtion = new int[2];
targetView.GetLocationOnScreen(localtion);
int left = localtion[0];
int top = localtion[1];
int right = left + targetView.MeasuredWidth;
int bottom = top + targetView.MeasuredHeight;
if (currentY >= top && currentY <= bottom && currentX >= left
&& currentX <= right)
{
return true;
}
return false;
}
I have written the following code that draws a rectangle for bearish engulfing patterns for two inputed timeframes. I set the defaults to daily and 4 hours. When I am on the daily chart I expect that only the daily rectangles should appear for one candle and when I am on the 4 hour chart, the daily rectangle region should extend for 6 candles whiles the 4-hour rectangle shows for only one candle, and so on as I move to lower time frames.
The general idea is the rectangle should extend to cover the candles that sum it's period. But that is not happening, only one candle appears always. How can I solve this? Here's my code below:
int numBars = 1;
extern ENUM_TIMEFRAMES higherRegionPeriod = PERIOD_D1;
extern ENUM_TIMEFRAMES lowerRegionPeriod = PERIOD_H4;
extern color higherRegionColorSupply = clrRed;
extern color lowerRegionColorSupply = clrChocolate;
bool isBearishEngulfing(int current, ENUM_TIMEFRAMES cDuration) {
if((iClose(_Symbol,cDuration,current) < iOpen(_Symbol,cDuration,current)) &&
(iClose(_Symbol,cDuration,current + 1) > iOpen(_Symbol,cDuration,current + 1)) &&
(iOpen(_Symbol,cDuration,current) > iClose(_Symbol,cDuration,current + 1)) &&
(iClose(_Symbol,cDuration,current) < iOpen(_Symbol,cDuration,current + 1)))
return true;
return false;
}
void showRectangles() {
for (int i=300;i>=1;i--) {
if(isBearishEngulfing(i, lowerRegionPeriod)) {
drawBearRectangle(i + 1,iHigh(_Symbol,lowerRegionPeriod,i + 1),iOpen(_Symbol,lowerRegionPeriod,i + 1), lowerRegionPeriod, lowerRegionColorSupply);
}
if(isBearishEngulfing(i, higherRegionPeriod)) {
drawBearRectangle(i + 1,iHigh(_Symbol,higherRegionPeriod,i + 1),iOpen(_Symbol,higherRegionPeriod,i + 1), higherRegionPeriod, higherRegionColorSupply);
}
}
}
bool drawBearRectangle(int candleInt,const double top,const double bottom, ENUM_TIMEFRAMES cDuration, color rectColor)
{
const datetime starts=iTime(_Symbol,cDuration,candleInt);
const datetime ends=starts+PeriodSeconds()*NumBars;
const string name=prefix+"_"+(candleInt>0?"DEMAND":"SUPPLY")+"_"+TimeToString(starts);
if(!ObjectCreate(0,name,OBJ_RECTANGLE,0,0,0,0,0))
{
printf("%i %s: failed to create %s. error=%d",__LINE__,__FILE__,name,_LastError);
return false;
}
ObjectSetInteger(0,name,OBJPROP_TIME1,starts);
ObjectSetInteger(0,name,OBJPROP_TIME2,ends);
ObjectSetDouble(0,name,OBJPROP_PRICE1,bottom);
ObjectSetDouble(0,name,OBJPROP_PRICE2,top);
ObjectSetInteger(0,name,OBJPROP_COLOR, rectColor);
ObjectSetInteger(0,name,OBJPROP_STYLE, STYLE_DASHDOT);
ObjectSetInteger(0,name,OBJPROP_WIDTH,1);
ObjectSetInteger(0,name,OBJPROP_FILL, false);
return true;
}
void OnDeinit(const int reason){ObjectsDeleteAll(0,prefix);}
void OnTick()
{
if(!isNewBar(higherRegionPeriod))
return; //not necessary but waste of time to check every second
if(!isNewBar(lowerRegionPeriod))
return; //not necessary but waste of time to check every second
showRectangles();
}
bool isNewBar(ENUM_TIMEFRAMES cDuration)
{
static datetime lastbar;
datetime curbar = (datetime)SeriesInfoInteger(_Symbol,cDuration,SERIES_LASTBAR_DATE);
if(lastbar != curbar)
{
lastbar = curbar;
return true;
}
return false;
I wrote the following code to look through the last 100 candlesticks and draw a rectangle around a bullish engulfing candlestick patterns. I hope extend it for bearish engulfing pattern too. I don't know why, but the rectangles don't draw. Please take a look at the code below
bool isBullishEngulfing(int current) {
if((iClose(_Symbol,0,current) > iOpen(_Symbol,0,current)) && (iClose(_Symbol,0,current + 1) < iOpen(_Symbol,0,current + 1)) &&
(iOpen(_Symbol,0,current) < iClose(_Symbol,0,current + 1)) && (iClose(_Symbol,0,current) > iOpen(_Symbol,0,current + 1)))
return true;
return false;
}
void showRectangles() {
for (int i=100;i<=1;i--) {
if(isBullishEngulfing(i)) {
drawBullRectangle(i,iHigh(_Symbol,0,i),iLow(_Symbol,0,i));
}
}
}
bool drawBullRectangle(int candleInt,const double top,const double bottom)
{
const datetime starts=iTime(_Symbol,0,candleInt);
const datetime ends=starts+PeriodSeconds()*Numbars; //Numbars shows how long the rectangle should draw
const string name=prefix+"_"+(candleInt>0?"DEMAND":"SUPPLY")+"_"+TimeToString(starts);
if(!ObjectCreate(0,name,OBJ_RECTANGLE,0,0,0,0,0))
{
printf("%i %s: failed to create %s. error=%d",__LINE__,__FILE__,name,_LastError);
return false;
}
ObjectSetInteger(0,name,OBJPROP_TIME1,starts);
ObjectSetInteger(0,name,OBJPROP_TIME2,ends);
ObjectSetDouble(0,name,OBJPROP_PRICE1,top);
ObjectSetDouble(0,name,OBJPROP_PRICE2,bottom);
ObjectSetInteger(0,name,OBJPROP_COLOR, clrAqua);
ObjectSetInteger(0,name,OBJPROP_STYLE, STYLE_SOLID);
ObjectSetInteger(0,name,OBJPROP_WIDTH,1);
ObjectSetInteger(0,name,OBJPROP_FILL, true);
return true;
}
void OnDeinit(const int reason){ObjectsDeleteAll(0,prefix);}
void OnTick()
{
if(!isNewBar())
return; //not necessary but waste of time to check every second
showRectangles();
}
bool isNewBar()
{
static datetime lastbar;
datetime curbar = (datetime)SeriesInfoInteger(_Symbol,_Period,SERIES_LASTBAR_DATE);
if(lastbar != curbar)
{
lastbar = curbar;
return true;
}
return false;
}
I would appreciate help to resolve this.
The error is mainly in the loop, it should be for (int i=100;i>=1;i--)
The other "possible" error is in the logic of theisBullishEngulfing() function.
Usually, the Close of the previous bar is equal to the Open of the current bar, so the following condition doesn't get fulfilled(most of the time)
iOpen(_Symbol,0,current) < iClose(_Symbol,0,current + 1)
(So, I suggest to remove this line, but this is just a suggestion, note there are occasions that your condition get fulfilled as well)
I am developing a POS application in windows 8.1 (Universal App).
Order receipt will be printed from the application and even I am able to do so.
Printer - EPSON TM-U220D
Input - A grid is being created pragmatically with dynamic content within the ViewModel. So this grid is the input for printer
Output - In the print preview (Attahced pic 1) all looks good but when the receipt is actually printed then content is cut off from the end (Attahced pic 2)
PIC 1
PIC 2
Observations -
If I print a normal text file manually using print command (Right click file and then print), then all content is printed perfectly.
If I print that SAME content, from the application, by creating Dynamic grid, then with Small font size print is good but with bit bigger font size content again cuts off.
Tried -
Optimized the code for Creating Gird, by specifying height
Questions-
If preview is all good then why not output
Did anyone tried using ePOS-Print_SDK_141020E for Windows Store app?
Generate Dynamic Grid Code
private void AddRows(Grid grid, int count)
{
for (int i = 0; i < count; i++)
{
RowDefinition row = new RowDefinition();
row.Height = GridLength.Auto;
grid.RowDefinitions.Add(row);
}
}
private void AddColumns(Grid grid, int count)
{
for (int i = 0; i < count; i++)
{
grid.ColumnDefinitions.Add(new ColumnDefinition());
}
}
private TextBlock CreateTextBlock(string text, Color color, FontWeight fw, double fs = 10, int thick = 5)
{
if (color == null) color = Colors.Black;
TextBlock txtBlock1 = new TextBlock();
txtBlock1.Text = text;
txtBlock1.FontSize = fs;
txtBlock1.FontWeight = fw;
txtBlock1.Foreground = new SolidColorBrush(color);
txtBlock1.VerticalAlignment = VerticalAlignment.Center;
txtBlock1.Margin = new Thickness(thick);
return txtBlock1;
}
private async Task<Grid> CreateDynamicWPFGrid()
{
Grid ParentGrid = new Grid();
AddRows(ParentGrid, 8);
/* Start First Grid*/
Grid DynamicGrid = new Grid();
DynamicGrid.Width = 230;
DynamicGrid.HorizontalAlignment = HorizontalAlignment.Left;
DynamicGrid.VerticalAlignment = VerticalAlignment.Top;
DynamicGrid.Margin = new Thickness(24, 0, 0, 0);
AddColumns(DynamicGrid, 2);
AddRows(DynamicGrid, 3);
TextBlock txtBlock1 = CreateTextBlock(DateTime.Now.ToString("M/d/yy"), Colors.Black, FontWeights.Normal);
Grid.SetRow(txtBlock1, 0);
Grid.SetColumn(txtBlock1, 1);
.
.
.
.
Return ParentGrid;
}
Printer Events Code
//Register Print Contract
async Task RegisterPrintContract()
{
PrintManager manager = PrintManager.GetForCurrentView();
manager.PrintTaskRequested += OnPrintTaskRequested;
await PrintManager.ShowPrintUIAsync();
}
//Unregister Print Contract
void UnregisterPrintContract()
{
PrintManager printMan = PrintManager.GetForCurrentView();
printMan.PrintTaskRequested -= OnPrintTaskRequested;
}
void OnPrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs args)
{
// If I need to be asynchronous, I can get a deferral. I don't *need*
// to do this here, I'm just faking it.
var deferral = args.Request.GetDeferral();
PrintTask printTask = args.Request.CreatePrintTask("My Print Job", OnPrintTaskSourceRequestedHandler);
printTask.Completed += OnPrintTaskCompleted;
deferral.Complete();
}
void OnPrintTaskCompleted(PrintTask sender, PrintTaskCompletedEventArgs args)
{
// TODO: Tidy up.
this._document = null;
this._pages = null;
}
async void OnPrintTaskSourceRequestedHandler(PrintTaskSourceRequestedArgs args)
{
var deferral = args.GetDeferral();
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
() =>
{
this._document = new PrintDocument();
this._document.Paginate += OnPaginate;
this._document.GetPreviewPage += OnGetPreviewPage;
this._document.AddPages += OnAddPages;
// Tell the caller about it.
args.SetSource(this._document.DocumentSource);
});
deferral.Complete();
}
void OnAddPages(object sender, AddPagesEventArgs e)
{
// Loop over all of the preview pages and add each one to add each page to be printied
// We should have all pages ready at this point...
foreach (var page in this._pages)
{
//this._pages[page.Key]
this._document.AddPage(this._pages[page.Key]);
}
PrintDocument printDoc = (PrintDocument)sender;
// Indicate that all of the print pages have been provided
printDoc.AddPagesComplete();
}
async void OnGetPreviewPage(object sender, GetPreviewPageEventArgs e)
{
Grid x = await CreateDynamicWPFGrid();
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
() =>
{
// NB: assuming it's ok to keep all these pages in
// memory. might not be the right thing to do
// of course.
if (this._pages == null)
{
this._pages = new Dictionary<int, UIElement>();
}
if (!this._pages.ContainsKey(e.PageNumber))
{
this._pages[e.PageNumber] = x;
}
if (this._document == null)
this._document = new PrintDocument();
this._document.SetPreviewPage(e.PageNumber, this._pages[e.PageNumber]);
}
);
}
async void OnPaginate(object sender, PaginateEventArgs e)
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
() =>
{
// I have one page and that's *FINAL* !
this._document.SetPreviewPageCount(e.CurrentPreviewPageNumber, PreviewPageCountType.Final);
});
}
hi i am new to processing and i'm trying to figure out how to make the sphere move from left to right using a marker instead of the mouse. can you help me please? i can use the marker to shoot but i cant move the sphere by shooting
import TUIO.*;
TuioProcessing tuioClient;
HashMap symbols=new HashMap();
PFont fontA;
int sphereDiameter = 50;
boolean shoot = false;
float obj_size = 60;
int randx()
{
return int(random(600));
}
int[] sphereXCoords = { randx(), randx(), randx(), randx(), randx() };
int[] sphereYCoords = { 0, 0, 0, 0, 0 };
void setup()
{
size(1000,700);
tuioClient = new TuioProcessing(this);
}
void draw()
{
Vector<TuioObject> tuioObjectList =tuioClient.getTuioObjects();
Collections.sort(tuioObjectList, comp);
for (TuioObject tobj:tuioObjectList) {
fill(50, 50, 100);
int id = tobj.getSymbolID();
int x = tobj.getScreenX(width);
int y = tobj.getScreenY(height);
rect(x, y, obj_size, obj_size);
String txt="?";
if (symbols.containsKey(id)) {// if it's one in symbols, then look it up
txt = (String)symbols.get(id);
}
fill(255);
text(txt, x, y);
}
int[] sphereXCoords = { randx(), randx(), randx(), randx(), randx() };
fill(100, 0, 0);
// draw the answer box
// ellipse(answerX, answerY, obj_size, obj_size);
fill(255);
// write the answer text
// text(""+answer, answerX, answerY);
background(1);
fill(color(255,255,0));
stroke(color(0,255,0));
triangle(mouseX-8, 580, mouseX+8, 580, mouseX, 565);
fill(color(255,0,0));
stroke(color(255,0,0));
if(shoot==true)
{
sphereKiller( mouseX);
shoot = false;
}
sphereDropper();
//gameEnder();
}
Comparator<TuioObject> comp = new Comparator<TuioObject>() {
// Comparator object to compare two TuioObjects on the basis of their x position
// Returns -1 if o1 left of o2; 0 if they have same x pos; 1 if o1 right of o2
public int compare(TuioObject o1, TuioObject o2) {
if (o1.getX()<o2.getX()) {
return -1;
}
else if (o1.getX()>o2.getX()) {
return 1;
}
else {
return 0;
}
}
};
void mousePressed()
{
shoot = true;
}
void sphereDropper()
{
stroke(255);
fill(255);
for (int i=0; i<5; i++)
{
ellipse(sphereXCoords[i], sphereYCoords[i]++,
sphereDiameter, sphereDiameter);
}
}
void sphereKiller(int shotX)
{
boolean hit = false;
for (int i = 0; i < 5; i++)
{
if((shotX >= (sphereXCoords[i]-sphereDiameter/2)) &&
(shotX <= (sphereXCoords[i]+sphereDiameter/2)))
{
hit = true;
line(mouseX, 565, mouseX, sphereYCoords[i]);
ellipse(sphereXCoords[i], sphereYCoords[i],
sphereDiameter+25, sphereDiameter+25);
sphereXCoords[i] = randx();
sphereYCoords[i] = 0;
}
}
if(hit == false)
{
line(mouseX, 565, mouseX, 0);
}
}
/* void gameEnder()
{
for (int i=0; i< 5; i++)
{
if(sphereYCoords[i]==600)
{
fill(color(255,0,0));
noLoop();
}
}
}*/
void addTuioObject(TuioObject tobj) {
}
// called when an object is removed from the scene
void removeTuioObject(TuioObject tobj) {
}
/ / called when an object is moved
void updateTuioObject (TuioObject tobj) {
if(tobj.getSymbolID() == 32)
{
shoot = true;
}
}
// called when a cursor is added to the scene
void addTuioCursor(TuioCursor tcur) {
}
// called when a cursor is moved
void updateTuioCursor (TuioCursor tcur) {
}
// called when a cursor is removed from the scene
void removeTuioCursor(TuioCursor tcur) {
}
// called after each message bundle
// representing the end of an image frame
void refresh(TuioTime bundleTime) {
//redraw();
}
What do you mean by "shooting" ?
So you have your tuioClient and you initialize it in setup(). Thats good, because then the callback methods (addTuioObject, removeTuioObject, updateTuioObject, addTuioCursor, updateTuioCursor, removeTuioCursor, refresh) will fire whenever your sketch receives a TUIO message.
Keep in mind that TUIO is based on OSC which is transported over UDP. That means the tracker (reactivision & co) will have to send to the IP and port your sketch is listening to. If both are on the same machine use 127.0.0.1 and port 3333 (default).
Have a look at the examples. You'll find them in the processing "IDE" click:
"File -> Examples"
and Navigate to
"Contributed Libraries -> TUIO"