How to serialize data from processing.js to rails application?
I am creating a simple canvas using processing.js , how to pass values 开发者_开发技巧from rails application to Processing.js
void drawBox(int bx, int by, int bs, int bs){
strokeWeight(3);
stroke(50,50,50);
// Test if the cursor is over the box
if (mouseX > bx-bs && mouseX < bx+bs &&
mouseY > by-bs && mouseY < by+bs) {
bover = true;
if(!locked) {
fill(181,213,255);
}
} else {
fill(255);
bover = false;
}
fill(192);
stroke(64);
roundRect(bx, by,80,30,10,10);
// put in text
if (!isRight) {
text("Box Value", x-size+5, y-5);
//Here i need to pass value from my controller
}
else {
text("Box Value", x+5, y-5);
//Here i need to pass value from my controller
}
}
Instead of static string "Box Value" , I need to pass the value from the ex @post.name through ajax
I would do this with some RJS template where you set a global variable to the text or use a data store to attach it to a DOM element. Then in your processing.js, just use the variable to render your text.
You can add pure javascript into your processing code : http://processingjs.org/reference/articles/jsQuickStart#mixingjsandprocessing
So, retrieving your data from AJAX with your favorite library should be easy.
精彩评论