project: show tags
[beagleboard.org.git] / db / 2892.xml
blob71fbb3c7f1a2a6d8c26a055da3da3245ef6bca11
1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <?xml-stylesheet type="text/xsl" href="helma.xsl"?>
3 <xmlroot xmlns:hop="http://www.helma.org/docs/guide/features/database">
4   <hopobject id="2892" name="processingjs" prototype="Page" created="1374308047101" lastModified="1375888514901">
5   <hop:parent idref="2471" prototyperef="Page"/>
6     <http_browser>Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36</http_browser>
7     <lang>en-us</lang>
8     <uri>processingjs</uri>
9     <http_host>beagleboard.org</http_host>
10     <time type="date">21.07.2013 01:28:51 CDT</time>
11     <pseudoparent idref="2471" prototyperef="Page"/>
12     <http_remotehost>127.0.0.1</http_remotehost>
13     <hopsession>127.0.0.12.0.200.cbriq8cyreb6</hopsession>
14     <user>jkridner@gmail.com</user>
15     <body>&lt;h1&gt;&lt;a href=&quot;http://processingjs.org/&quot; class=&quot;external&quot;&gt;Processing.JS&lt;/a&gt;&lt;/h1&gt;
16 &lt;canvas id=&quot;mysketch&quot;&gt;&lt;/canvas&gt;
17 &lt;script src=&quot;/static/bonescript.js&quot;&gt;&lt;/script&gt;
18 &lt;script src=&quot;/static/processing.js&quot;&gt;&lt;/script&gt;
19 &lt;script&gt;
20 (function(){
21 var canvas = document.getElementById(&apos;mysketch&apos;);
22 var pjs = new Processing(canvas);
24 // Global variables
25 var radius = 50.0;
26 var X, Y;
27 var nX, nY;
28 var delay = 16;
29 var brightness = 0;
30 var buttonStatus = false;
31 var LED_RED = &apos;P9_42&apos;;
32 var LED_GREEN = &apos;P9_14&apos;;
33 var LED_BLUE = &apos;P9_16&apos;;
34 var BUTTON = &apos;P8_19&apos;;
35 var POT = &apos;P9_36&apos;;
37 // Get the BoneScript library and begin updating the canvas
38 setTargetAddress(&apos;192.168.7.2&apos;, {initialized: run});
39 function run() {
40     var b = require(&apos;bonescript&apos;);
41     b.pinMode(LED_RED, b.OUTPUT);
42     b.pinMode(LED_GREEN, b.OUTPUT);
43     b.pinMode(LED_BLUE, b.OUTPUT);
44     b.pinMode(BUTTON, b.INPUT);
46     // Setup the Processing Canvas
47     pjs.setup = function() {
48         pjs.size(300, 300);
49         pjs.strokeWeight(10);
50         pjs.frameRate(15);
51         X = pjs.width / 2;
52         Y = pjs.height / 2;
53         nX = X;
54         nY = Y;  
55     }
56     
57     // Main draw loop
58     pjs.draw = function() {
59         // Calculate some fading values based on the frame count
60         radius = 50.0 + 10.0*pjs.sin(pjs.frameCount / 4);
61         brightness = (radius - 40.0) / 20.0;
62         
63         // Set the RGB LED color based on the status of the button
64         if(buttonStatus) {
65             b.analogWrite(LED_RED, brightness);
66             b.analogWrite(LED_BLUE, 0);
67         } else {
68             b.analogWrite(LED_RED, 0);            
69             b.analogWrite(LED_BLUE, brightness);
70         }
71       
72         // Track circle to new destination
73         X+=(nX-X)/delay;
74         Y+=(nY-Y)/delay;
75       
76         // Fill canvas grey
77         pjs.background(100);
78       
79         // Set fill-color to blue or red, based on button status
80         if(buttonStatus) pjs.fill(200, 30, 20)
81         else pjs.fill(0, 121, 184);
82       
83         // Set stroke-color white
84         pjs.stroke(255); 
85       
86         // Draw circle
87         pjs.ellipse(X, Y, radius, radius);
88         
89         // Fetch slider location for next time
90         b.analogRead(POT, onAnalogRead);
91         
92         // Fetch button status
93         b.digitalRead(BUTTON, onDigitalRead);
94     }
95     
96     // Handle data back from potentiometer
97     function onAnalogRead(x) {
98         if(!x.err &amp;&amp; (x.value &gt;= 0) &amp;&amp; (x.value &lt;= 1)) {
99             nY = x.value * pjs.height;    
100         }
101     }
102     
103     // Handle data back from button
104     function onDigitalRead(x) {
105         buttonStatus = (x.value == b.LOW) ? true : false;
106     }
107     
108     pjs.setup();
111 })();
112 &lt;/script&gt;
113 &lt;div style=&quot;clear:both;&quot;&gt;&lt;/div&gt;</body>
114     <http_language>en-US,en;q=0.8</http_language>
115     <is_xhtml type="boolean">true</is_xhtml>
116     <http_referer>http://beagleboard.org/support/BoneScript/processingjs/edit</http_referer>
117     <hop:child idref="3008" prototyperef="Page"/>
118   </hopobject>
119 </xmlroot>