processing code shows nothing on the browser. don't know why - class

Does anybody know what's wrong with this code? It shows nothing in the browser.
My intention is to draw two eyes based on the mouse location. So I define an Eye class and then call its draw method with variable mouseX and mouseY.
However, it shows nothing on the browser.
Also, I wonder how to detect the size of the browser because screen.width and screen.height don't seem to work within a browser.
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="processing.js"></script>
<script type="text/processing" data-processing-target="mycanvas">
void setup(){
size(400,400);
smooth();
background(225);
}
if (mousePressed){
Face.draw(mouseX,mouseY);}
class Face{
float x,y,a;
Face(float ax,float ay){
x=ax;
y=ay;
a=random(1,5);}
void draw{
noFill();
stroke(0);
//eye1
ellipse(x+2.2*a,y-a,a/2,a/2);
//eyelashes1
arc(x+2.2*a,y-.5*a,1.2*a,1.2*a,PI,2*PI);
//eyebrows1
arc(x+3*a,y-.3,2*a,2*a,5/4*PI,9/4*PI);
//eye2
ellipse(x-2.2*a,y-a,a/2,a/2);
//eyelashes2
arc(x-2.2*a,y-.5*a,1.2*a,1.2*a,PI,2*PI);
//eyebrows2
arc(x-3*a,y-.3,2*a,2*a,5/4*PI,9/4*PI);
}
}
</script>
</head>
<body></body>
<canvas id="mycanvas"></canvas>
</html>
I'm a beginner, so I don't know if my problem is stupid or not.
But any hint is welcomed:)
Btw how to add color to the code on stackoverflow?

There are a some problems with your script.
Related with the html page:
You have to declare the encoding of the document in the header section: <meta charset="utf-8">
The canvas element should be included inside the html body.
Related with the processing code:
The processing script needs at least one setup() function and one draw() function. You defined a draw() method in your Face class, but not the main draw() function (by the way, you missed the brackets in your draw() method).
The mousePressed functionality should be included inside the main draw() method.
You need at least to declare one instance of your Face class (inside the setup() function). For example: Face myFace = new Face(10, 10);.
And probably more syntax errors inside your draw() method...
My recommendations:
Start with something simpler: The more lines you write from scratch, the harder to debug. Try to draw first just an ellipse and incrementally add more things to your code.
Keep your processing script in a separate file. It's cleaner and you can debug it using the processing editor or the processing online sketch:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Testing testing</title>
<script type="text/javascript" src="processing.js"></script>
</head>
<body>
<canvas id="my-sketch" data-processing-sources="my-sketch.pde"></canvas>
</body>
</html>
Check this tutorial to get some ideas about objects and classes in processing.
The syntax in processing is very similar to java, and there're a lot more resources for understanding the basics of OOP for that language. Just google for it.
For syntax highlightning, look here.

Related

openui5 ActionSelect not showing ListItems in drop list

I am trying to use the sap.m.ActionSelect within my application (as I like the combination of selection and action buttons). However, even within this simple test, I cannot get the drop list to show anything other than the first item. I am sure I am doing something completely dumb, but this one has me beaten. If anyone can spot the deliberate mistake I would be grateful!
<!doctype html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<title>ActionSelect</title>
<script id="sap-ui-bootstrap" src="../openui5/sap-ui-core.js" data-sap-ui-theme="sap_bluecrystal" data-sap-ui-libs="sap.ui.commons"
data-sap-ui-libs="sap.ui.unified" data-sap-ui-libs="sap.m"
data-sap-ui-resourceroots='{
"sparqlish":"../",
"sparqlish":"../sparqlish",
"Components":"../",
"Components":"../Components"
}'
data-sap-ui-xx-bindingSyntax="complex" type="text/javascript"></script>
<script type="text/javascript">
jQuery.sap.require("sap.m.ActionSelect");
jQuery.sap.require("sap.m.Button");
this.oServiceSelect = new sap.m.ActionSelect();
var oItem = new sap.ui.core.ListItem("Country1");
oItem.setText("Canada");
this.oServiceSelect.addItem(oItem);
oItem = new sap.ui.core.ListItem("Country2");
oItem.setText("Deutschland");
this.oServiceSelect.addItem(oItem);
oItem = new sap.ui.core.ListItem("Country3");
oItem.setText("England");
this.oServiceSelect.addItem(oItem);
oItem = new sap.ui.core.ListItem("Country4");
oItem.setText("Россия");
this.oServiceSelect.addItem(oItem);
this.oServiceSelect.setEnabled(true);
this.oServiceSelect.placeAt("serviceMenu");
this.oServiceSelect.addButton(new sap.m.Button({
text : "Action 1",
press : function(){alert("Action 1")}
}));
this.oServiceSelect.addButton(new sap.m.Button({
text : "Action 2",
press : function(){alert("Action 2")}
}));
</script>
</head>
<body>
<div id="serviceMenu"></div>
</body>
</html>
You have several issues in the code. First, you are loading the libs at bootstrap with three different attributes. This is wrong! Instead simply use one attribute and list the libs you want separated by comma.
Another issue in the code is that you are loading both sap.ui.commons and sap.m. As a rule of thumb you should never ever mix sap.ui.commons and sap.m!!! That's very important.
In your case you could and definitely should even completely remove sap.ui.commons because as far as I can see it from your code you are not using it anyway.
It appears that the order in which one declares the data-sap-ui-libs is important. The original order in the example above was:
data-sap-ui-libs="sap.ui.commons"
data-sap-ui-libs="sap.ui.unified"
data-sap-ui-libs="sap.m"
However if I reorder these to the following, with data-sap-ui-libs="sap.m" everything works well
data-sap-ui-libs="sap.m"
data-sap-ui-libs="sap.ui.commons"
data-sap-ui-libs="sap.ui.unified"

coffeescript line number in error.stack?

Following coffee-script code:
try
any_error_here
catch err
alert err.stack
Gives following stack trace:
ReferenceError: any_error_here is not defined
at eval (coffeescript:5:3)
How to get coffeescript line number for this stack (line 2)?
Here is simple html with same question:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Coffee-script stack trace problems</title>
<script type="text/javascript" language="javascript" src="http://coffeescript.org/extras/coffee-script.js"></script>
</head>
<body id="dt_example">
<script type="text/coffeescript" language="javascript">
try
any_error_here
catch err
alert err.message+'\n'+err.stack + '\n\nWhat is coffeescript line number for this stack?'
</script>
</body>
</html>
This sounds like a problem for source maps.
When you compile your CoffeeScript, you can generate a source map by specifying the -m option:
coffee -c -m so.coffee
In browsers that support source maps (e.g. Chrome), the CoffeeScript file will appear in the Sources tab, and errors and log statements will refer to the corresponding line in the CoffeeScript file.
For more information, check out the HTML5 tutorial on source maps, and a short article about using source maps with CoffeeScript.
If you have a source map, you can also use it to parse a stack trace string and refer back to the original uncompiled file as outlined in this question.

equivalent of \let\phi\varphi in MathJax

I usually have \let\phi\varphi in preambles of my LaTeX files, for aesthetics reasons. Is it possible to do something similar in MathJax? I tried defining macros
MathJax.Hub.Config({TeX:{Macros:{phi:"\\varphi"}}})
but it seems to have confused MathJax (no math was rendered on the page at all). What is the proper way to do this?
What you have done should work, so I suspect something is typed wrong or in the wrong place in your file. Here is a complete working example file:
<!DOCTYPE html>
<html>
<head>
<title>MathJax Macros Configuration</title>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({TeX: {Macros: {phi:"\\varphi"}}});
</script>
<script src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>
</head>
<body>
phi \(\phi\) and varphi \(\varphi\) should both be the same.
</body>
</html>

dhtmlx combo, autocomplete mode, js

I am having problem with autocomplete mode with dhtmlx combo.
The includes files are as follows:
// Images
<script>
window.dhx_globalImgPath="combo/dhtmlxCombo/codebase/imgs/";
</script>
// CSS
<link rel="stylesheet" type="text/css" href="combo/dhtmlxCombo/codebase/dhtmlxcombo.css">
// Required JS files
<script src="combo/dhtmlxCombo/codebase/dhtmlxcommon.js"></script>
<script src="combo/dhtmlxCombo/codebase/dhtmlxcombo.js"></script>
<script src="combo/dhtmlxCombo/codebase/ext/dhtmlxcombo_extra.js"></script>
I have no issues with the code above and works well.
The following code I have on the page I have the combo itself is as follows:
<!-- HTML Combo -->
<div id="pickup" style="width:260px;"></div>
<!-- Initialisation of combo -->
<script>
var x = new dhtmlXCombo("pickup",260,"image");
// this works
x.loadXML("list.xml");
x.enableFilteringMode(true);
</script>
My problem is i want to use autocomplete mode by using the following line of code:
x.enableFilteringMode(true, "list.xml", true, true)
When i try the above line, it doesnt give error but it doesnt filter either. However im told to use a php file but i don't know what I need to put in the list.php file itself. I can code just dont know what to put in. Can anyone shed some light, the docs arent that helpful.
enableFilteringMode enables server-side filtering. It means that when you type something in the combo header, this text is sent to the script that is defined the second parameter of the method. The script generates XML with options that correspond the mask.
Therefore, you can't use static XML in this case.
You can find a demo of the dynamic loading in the dhtmlxCombo package:
dhtmlxCombo/samples/04_filtering/01_combo_big_db.html
Also, you can use dhtmlxConnector that provides a ready solutions for the server side (PHP, ASP.NET, etc.). The dhtmlxConnector package includes a demo with dhtmlxCombo, e.g.:
dhtmlxConnector_php_v10_110725/php/samples/combo/02_sql.html

how do I use XUI tween?

I don't understand how to use XUI tween. On the xui website, they give the following example code:
x$('#box').tween([{left:'100px', backgroundColor:'green', duration:.2 }, { right:'100px' }]);
What is that supposed to do? I created a <div id="box"></div>, ran the line of js code above, but nothing happened. Here's my complete code:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript" src="xui.min.js"></script>
<script type="text/javascript">
x$('#box').tween([{left:'100px', backgroundColor:'green', duration:.2 }, { right:'100px' }]);
</script>
</head>
<body>
<div id="box"></div>
</body>
</html>
Nothing happens...
So, XUI's tween seems to be a work in process. In fact, in the master branch code on GitHub you find:
// queued animations
/* wtf is this?
if (props instanceof Array) {
// animate each passing the next to the last callback to enqueue
props.forEach(function(a){
});
}
*/
So, in short, the array-based tween properties appear busted at the moment. In addition, XUI's tween seems to be a little flakey when dealing with properties that are not currently set on the DOM element. (For example, setting the background-color on a transparent element turns it black...rather than the intended color.)
That said, the single tween and callback work well on previously set properties. So take a look at the following (and excuse the inline css):
<html>
<head>
<script type="text/javascript" src="http://xuijs.com/downloads/xui-2.3.2.min.js"></script>
<script type="text/javascript">
x$.ready(function(){
setTimeout(function(){
x$('#box').tween({'left':'100px', 'background-color':'#339900', duration:2000}, function(){
x$('#box').tween({'left':'500px', duration:2000});
});
}, 500);
});
</script>
</head>
<body style="position:relative;">
<div id="box" style="position:absolute;top:50px;left:500px;width:100px;height:100px;background-color:#fff;border:1px solid #000;">the box</div>
</body>
</html>
Because #box now has a css background-property and left position explicitly set, it is relatively easy to produce an effect similar to the one desired.
One-half second after the page loads, #box should spend 2 seconds moving from left:500px to left:100px while turning the background color from white to green. Then, using the callback, #box moves back to its original position at left:500px--taking another 2 seconds to get back.
Obviously, this does not answer your exact question but for those (like me) who stumble upon this, it provides a workaround for the time being.