topical media & game development

talk show tell print

#javascript-processing-example-basic-data-datatypeconversion.htm / htm



  <!DOCTYPE html>
  <html><head>
  <script src="javascript-processing-example-processing.js"></script>
  <script src="javascript-processing-example-init.js"></script>
  <link rel="stylesheet" href="javascript-processing-example-style.css">
  </head><body><h1><a href="http://ejohn.org/blog/processingjs/">Processing.js</a></h1>
  <h2>DatatypeConversion</h2>
  
  <p>It is sometimes beneficial to convert a value from one type of 
  data to another. Each of the conversion functions converts its parameter 
  to an equivalent representation within its datatype. 
  The conversion functions include int(), float(), char(), byte(), and others.</p>
  
  <p><a href="http://processing.org/learning/basics/datatypeconversion.html"><b>Original Processing.org Example:</b> DatatypeConversion</a><br>
  <script type="application/processing">
  size(200, 200);
  background(51);
  noStroke();
  
  char c;    // Chars are used for storing typographic symbols
  float f;   // Floats are decimal numbers
  int i;     // Ints are values between 2,147,483,647 and -2147483648
  byte b;    // Bytes are values between -128 and 128
  
  c = 'A';
  f = float(c);     // Sets f = 65.0
  i = int(f * 1.4); // Sets i to 91
  b = byte(c / 2);  // Sets b to 32
  
  rect(f, 0, 40, 66);
  fill(204);
  rect(i, 67, 40, 66);
  fill(255);
  rect(b, 134, 40, 66);
  </script><canvas width="200" height="200"></canvas></p>
  <div style="overflow: hidden; height: 0px; width: 0px;"></div>
  
  <pre><b>// All Examples Written by <a href="http://reas.com/">Casey Reas</a> and <a href="http://benfry.com/">Ben Fry</a>
  // unless otherwise stated.</b>
  size(200, 200);
  background(51);
  noStroke();
  
  char c;    // Chars are used for storing typographic symbols
  float f;   // Floats are decimal numbers
  int i;     // Ints are values between 2,147,483,647 and -2147483648
  byte b;    // Bytes are values between -128 and 128
  
  c = 'A';
  f = float(c);     // Sets f = 65.0
  i = int(f * 1.4); // Sets i to 91
  b = byte(c / 2);  // Sets b to 32
  
  rect(f, 0, 40, 66);
  fill(204);
  rect(i, 67, 40, 66);
  fill(255);
  rect(b, 134, 40, 66);</pre>
  </body></html>
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.