User Tools

Site Tools


processing:thermometer_example

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
processing:thermometer_example [2013/08/04 02:51] – [Updating the data] mithatprocessing:thermometer_example [2013/08/04 03:55] (current) – [How to make a thermometer] mithat
Line 1: Line 1:
-====== Thermometer example ======+====== How to make a thermometer ======
  
 {{:processing:processing_thermometer.png}} {{:processing:processing_thermometer.png}}
Line 12: Line 12:
 You won't find much description below. I may add some later, but my intent here is just to do a structured code dump. You won't find much description below. I may add some later, but my intent here is just to do a structured code dump.
  
-<WRAP center round important 60%> +<WRAP center round info 60%> 
-Because applet support has been removed in Processing 2 and Processing.js doesn't allow downloading arbitrary files, linking to live examples that work in the browser from this page is not possible.+Because applet support has been removed in [[http://processing.org/|Processing 2]] and [[http://processingjs.org/|Processing.js]] doesn't allow downloading arbitrary files, linking to live examples that work in the browser from this page is not possible.
 </WRAP> </WRAP>
  
 ===== Getting files from the Internet ===== ===== Getting files from the Internet =====
 +{{:processing:processing_get_internet_page.png?nolink&480|}}
 +
 The built-in function ''loadStrings'' will load local files or URLs. The built-in function ''loadStrings'' will load local files or URLs.
  
Line 93: Line 95:
  
 ===== Scraping XML for data ===== ===== Scraping XML for data =====
 +{{:processing:processing_get_xml_page.png?nolink&480|}}
  
 Grabbing selected data from an XML source is easy with Processing's ''XML'' class. In this example, we load an RSS feed (which is XML) and extract some data from it. Grabbing selected data from an XML source is easy with Processing's ''XML'' class. In this example, we load an RSS feed (which is XML) and extract some data from it.
Line 159: Line 162:
  
 ===== A digital thermometer ===== ===== A digital thermometer =====
 +
 +{{:processing:processing_thermometer_digital.png?nolink|}}
  
 Fonts are graphics in Processing. To get the following to work, you'll need to create the *.vlw file using the //Tools > Create Font...// menu item. Fonts are graphics in Processing. To get the following to work, you'll need to create the *.vlw file using the //Tools > Create Font...// menu item.
Line 297: Line 302:
  
 ===== Adding a graphic meter ===== ===== Adding a graphic meter =====
 +
 +{{:processing:processing_thermometer_meter.png?nolink|}}
  
 Representing quantities graphically. Note also the use of Javadoc-style documentation comments for the functions. Representing quantities graphically. Note also the use of Javadoc-style documentation comments for the functions.
Line 339: Line 346:
          
     background(#296783);     background(#296783);
-    drawDigitalTemp(condition.getInt(ATTRIBUTE_CONDITION_TEMPERATURE), +     
-        units.getString(ATTRIBUTE_UNIT_TEMPERATURE), width/2, height/2); +    int temperature = condition.getInt(ATTRIBUTE_CONDITION_TEMPERATURE); 
-    drawMeter(70, -40, 120, 10, height-2*BORDER, width-10-BORDER, BORDER);+    drawDigitalTemp(temperature, units.getString(ATTRIBUTE_UNIT_TEMPERATURE), 
 +                    width/2, height/2); 
 +    drawMeter(temperature, -40, 120, 10, height-2*BORDER, width-10-BORDER, BORDER);
   }   }
   catch (Exception e) {   catch (Exception e) {
Line 358: Line 367:
  
 /** /**
- * Render the temperature numerically at a given canvas location.+ * Render temperature numerically at a given canvas location.
  *  *
  * @param temperature the temperature to be drawn (int)  * @param temperature the temperature to be drawn (int)
Line 378: Line 387:
  
 /** /**
- * Render the temperature graphically.+ * Render a value on a vertical meter.
  *  *
  * @param val      the value to be drawn (float)  * @param val      the value to be drawn (float)
Line 472: Line 481:
  
     background(#296783);     background(#296783);
-    drawDigitalTemp(condition.getInt(ATTRIBUTE_CONDITION_TEMPERATURE) +    int temperature = condition.getInt(ATTRIBUTE_CONDITION_TEMPERATURE); 
-                    units.getString(ATTRIBUTE_UNIT_TEMPERATURE), width/2, height/2); +    drawDigitalTemp(temperature, units.getString(ATTRIBUTE_UNIT_TEMPERATURE), 
-    drawMeter(70, -40, 120, 10, height-2*BORDER, width-10-BORDER, BORDER);+                    width/2, height/2); 
 +    drawMeter(temperature, -40, 120, 10, height-2*BORDER, width-10-BORDER, BORDER);
  
     // uncomment println below for debugging.      // uncomment println below for debugging. 
Line 513: Line 523:
  
 /** /**
- * Render the temperature graphically.+ * Render a value on a vertical meter.
  *  *
  * @param val      the value to be drawn (float)  * @param val      the value to be drawn (float)
processing/thermometer_example.1375584686.txt.gz · Last modified: 2013/08/04 02:51 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki