Programs - Processing Discourse board_Programs.html Programs - Processing Discourse en-us Processing Discourse Thu, 22 Mar 2012 06:09:46 +0000 http://blogs.law.harvard.edu/tech/rss 30 Using light, shading 3d num_1255494263.html Processing Discourse/Programs num_1255494263.html Wed, 30 Jun 2010 01:31:01 +0000 Hi everyone !<br /><br />I'm pretty near the solution, but I cant make it work:<br /><br />I've got a sketch running with toxiclib's triangleMesh.<br />I've got another one running with surfaceLib.<br /><br />They both work fine, and i can use useVertexNormals() with surfaceLib, but I can't figure out how to connect those two. <br />I understand that it's possible to have a toxiclib's triangleMesh with the nice useVertexNormals from surfaceLib. But how ?! <br />Does anyone have an example ? <br /><br />Thanks for your help Program to find the shortest path num_1276835418.html Processing Discourse/Programs num_1276835418.html Fri, 18 Jun 2010 12:50:35 +0000 ox and oy is the x and y cordinates of the object that needs to move to the goal. &nbsp;gx and gy is the x and y position of the goal. &nbsp;thanks for the out of bounds comment. &nbsp;I'll try that. Point to line distance num_1276644884.html Processing Discourse/Programs num_1276644884.html Fri, 18 Jun 2010 10:43:28 +0000 hey smitty! <br /><br />thanks again for suggestions, i removed mY completely. <br /><br />as for your other suggestion about pre-calculating distance+cos/sin: this definitely makes sense if one always checks against a static set of lines, but also means more work before the function call can happen. <br />i think the current version is a good trade-off between ease of use and speed. <br /><br />so for completeness: here's a version that is totally crazy fast as long as your lines rarely change. <br />i put the whole thing into a class cause i'm not a big fan of having many variables flying around. <br /><br /> <b>Code:</b><pre class="code"><br &#47;>&#47;&#47; press space to reset<br &#47;>&#47;&#47; click for randomness<br &#47;>&#47;&#47; drag to move<br &#47;><br &#47;>Line myLine; <br &#47;><br &#47;>void setup&#40;&#41;&#123;<br &#47;>  size&#40; 600, 600 &#41;; <br &#47;>  smooth&#40;&#41;; <br &#47;>  textFont&#40; loadFont&#40; &quot;SansSerif&#45;12&#46;vlw&quot; &#41; &#41;; <br &#47;>  <br &#47;>  myLine = new Line&#40; width&#47;2 &#45; 100, height&#47;2, width&#47;2 + 100, height&#47;2 &#41;; <br &#47;>&#125;<br &#47;><br &#47;><br &#47;>void draw&#40;&#41;&#123;<br &#47;>  background&#40; 0 &#41;; <br &#47;>  <br &#47;>  stroke&#40; 255 &#41;; <br &#47;>  myLine&#46;draw&#40;&#41;; <br &#47;><br &#47;>  fill&#40; 255, 255, 0 &#41;; <br &#47;>  noStroke&#40;&#41;; <br &#47;>  ellipse&#40; mouseX, mouseY, 10, 10 &#41;; <br &#47;>  <br &#47;>  PVector result = myLine&#46;get&#068;istance&#40; mouseX, mouseY &#41;; <br &#47;>  stroke&#40; 150 &#41;; <br &#47;>  line&#40; mouseX, mouseY, result&#46;x, result&#46;y &#41;; <br &#47;>  <br &#47;>  fill&#40; 255 &#41;; <br &#47;>  text&#40; &quot;The distance to the line is&#58; &quot; + result&#46;z, 10, 10 &#41;; <br &#47;>&#125;<br &#47;><br &#47;><br &#47;>void mousePressed&#40;&#41;&#123;<br &#47;>  myLine&#46;x1 = 100+random&#40;width&#45;200&#41;; <br &#47;>  myLine&#46;y1 = 100+random&#40;height&#45;200&#41;; <br &#47;>  myLine&#46;update&#40;&#41;; <br &#47;>&#125;<br &#47;><br &#47;>void mouse&#068;ragged&#40;&#41;&#123;<br &#47;>  myLine&#46;x1 = mouseX; <br &#47;>  myLine&#46;y1 = mouseY; <br &#47;>  myLine&#46;update&#40;&#41;; <br &#47;>&#125;<br &#47;><br &#47;>void keyPressed&#40;&#41;&#123;<br &#47;>  myLine&#46;x1 = width&#47;2&#45;100; <br &#47;>  myLine&#46;y1 = height&#47;2; <br &#47;>  myLine&#46;update&#40;&#41;; <br &#47;>&#125;<br &#47;><br &#47;>&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;<br &#47;><br &#47;>class Line&#123;<br &#47;>  &#47;&#47; where does the line start&#47;end&#63; <br &#47;>  public float x1, x2, y1, y2; <br &#47;>  <br &#47;>  &#47;&#47; some happy math variables<br &#47;>  private float dx, dy, d, ca, sa, mx, dx2, dy2; <br &#47;>  <br &#47;>  &#47;&#47; we use this to store the result, <br &#47;>  &#47;&#47; so if you want to store the result and calculate again <br &#47;>  &#47;&#47; you should do <br &#47;>  &#47;&#47; PVector mine = new PVector&#40;&#41;; <br &#47;>  &#47;&#47; mine&#46;set&#40; line&#46;get&#068;istance&#40; mouseX, mouseY &#41; &#41;; <br &#47;>  private PVector result; <br &#47;>  <br &#47;>  public Line&#40; float x1, float y1, float x2, float y2 &#41;&#123;<br &#47;>    this&#46;x1 = x1; <br &#47;>    this&#46;y1 = y1; <br &#47;>    this&#46;x2 = x2; <br &#47;>    this&#46;y2 = y2; <br &#47;>    result = new PVector&#40;&#41;; <br &#47;>    update&#40;&#41;; <br &#47;>  &#125;<br &#47;>  <br &#47;>  &#47;**<br &#47;>   * Call this after changing the coordinates&#33;&#33;&#33; <br &#47;>   *&#47;<br &#47;>  public void update&#40;&#41;&#123;<br &#47;>    dx = x2 &#45; x1; <br &#47;>    dy = y2 &#45; y1; <br &#47;>    d = sqrt&#40; dx*dx + dy*dy &#41;; <br &#47;>    ca = dx&#47;d; &#47;&#47; cosine<br &#47;>    sa = dy&#47;d; &#47;&#47; sine <br &#47;>  &#125;<br &#47;>  <br &#47;>  &#47;**<br &#47;>   * Returns a point on this line<br &#47;>   * that is closest to the point &#40;x,y&#41;<br &#47;>   * <br &#47;>   * The result is a PVector&#46; <br &#47;>   * result&#46;x and result&#46;y are points on the line&#46; <br &#47;>   * The result&#46;z variable contains the distance from &#40;x,y&#41; to the line, just in case you need it &#58;&#41; <br &#47;>   *&#47;<br &#47;>  PVector get&#068;istance&#40; float x, float y &#41;&#123;<br &#47;>    mx = &#40;&#45;x1+x&#41;*ca + &#40;&#45;y1+y&#41;*sa;<br &#47;>    <br &#47;>    if&#40; mx &lt;= 0 &#41;&#123;<br &#47;>      result&#46;x = x1; <br &#47;>      result&#46;y = y1; <br &#47;>    &#125;<br &#47;>    else if&#40; mx &gt;= d &#41;&#123;<br &#47;>      result&#46;x = x2; <br &#47;>      result&#46;y = y2; <br &#47;>    &#125;<br &#47;>    else&#123;<br &#47;>      result&#46;x = x1 + mx*ca; <br &#47;>      result&#46;y = y1 + mx*sa; <br &#47;>    &#125;<br &#47;>    <br &#47;>    dx2 = x &#45; result&#46;x; <br &#47;>    dy2 = y &#45; result&#46;y; <br &#47;>    result&#46;z = sqrt&#40; dx2*dx2 + dy2*dy2 &#41;; <br &#47;>    <br &#47;>    return result;   <br &#47;>  &#125;<br &#47;>  <br &#47;>  &#47;**<br &#47;>   * &#068;raw it&#33; <br &#47;>   *&#47;<br &#47;>  public void draw&#40;&#41;&#123;<br &#47;>    line&#40; x1, y1, x2, y2 &#41;; <br &#47;>  &#125;<br &#47;>&#125;<br &#47;> </pre><br /><br /><br />obviously there are many more optimizations one could go for, e.g. in my own project i don't even need the result.x/result.y variables so i threw them out alltogether and only return the distance. Need help with Project Euler question. num_1276829883.html Processing Discourse/Programs num_1276829883.html Fri, 18 Jun 2010 06:51:01 +0000 Two things:<br />1) why are you solving math problems and learning the basics of programming in processing I mean, sure there's nothing wrong with it, it just seems a bit odd if you ask me :p<br /><br />2) You should <u>really</u> do some reading on the Modulo operator (%) <a href="http://en.wikipedia.org/wiki/Modulo_operation" target="_blank">http://en.wikipedia.org/wiki/Modulo_operation</a> <br /><a href="http://processing.org/reference/modulo.html" target="_blank">http://processing.org/reference/modulo.html</a>. <br />Your entire program can be written in 9 lines of code while at the same time giving the right answer <img src="yabbfiles/Templates/Forum/processing_one/smiley.gif" border="0" alt="Smiley" title="Smiley" /><br /><br />on a side note though: &quot;multiples of 3 or 5&quot; is that a normal &quot;or&quot; or a &quot;exclusive or&quot; (xor) JPG Image Deterioration Sketch num_1276788023.html Processing Discourse/Programs num_1276788023.html Fri, 18 Jun 2010 02:30:12 +0000 Enlightening, thanks for the replies!<br /><br />Looks like what I wanted to do may not work the way I intended - essentially I wanted to reduce an image down to highly visible artifacts and &quot;glitches&quot; by reproducing it many times over. Hmmm... help with converting 2d image to 3d shape num_1276630718.html Processing Discourse/Programs num_1276630718.html Thu, 17 Jun 2010 13:16:40 +0000 OK Toxi, <br />Now that I know something about your libraries, I'm inspired. I also have questions.<br />If I understand correctly, you're creating a series of blobs in 3D space and then skinning them to create the final watertight model...correct?<br /><br />Can I import a model and skin it the same way?<br /> In your sketch this line:<br />mesh.saveAsSTL(sketchPath(&quot;test.stl&quot;), true);<br />saves the STL file from the sketch, is it possible to save the STL from an applet back to the server?  How?<br /> Need help with flipping cards in processing num_1276005318.html Processing Discourse/Programs num_1276005318.html Thu, 17 Jun 2010 08:39:35 +0000 <img src="yabbfiles/Templates/Forum/processing_one/grin.gif" border="0" alt="Grin" title="Grin" /> i exactly know what you mean..I have no clue what i hacked in there a week ago..but it's funny Rectangular selection of curves using mouse num_1276552288.html Processing Discourse/Programs num_1276552288.html Thu, 17 Jun 2010 04:48:58 +0000 For small amount of text, <a href="http://processing.org/reference/loadStrings_.html" target="_blank">loadStrings()</a> does the job nicely. (BufferedReader is harder to use but perfect for large data files.) ERROR ARDUINO num_1276619456.html Processing Discourse/Programs num_1276619456.html Tue, 15 Jun 2010 13:31:05 +0000 Please:<br />- Avoid all caps subjects (it is like shouting!)<br />- Read the stickies in the forums (the Software Bugs section isn't for posting about bugs in <i>your</i> software, and you shouldn't post there anyway).<br /><br />NullPointerException usually means you are trying to use an object but it is null, ie. not initialized.<br />For example using someObject.someMethod() or someObject.someField<br />Check you did your initializations correctly. worm hole num_1276597267.html Processing Discourse/Programs num_1276597267.html Tue, 15 Jun 2010 12:53:43 +0000 We have already tried but we can't do read it like a video camera reads as an image and then a single frame!! Kumars Sketch: rotate, animate ellipse, text issue num_1276099031.html Processing Discourse/Programs num_1276099031.html Tue, 15 Jun 2010 03:26:52 +0000 Hi Cedric,<br /><br />Awesome work done by you.Thanks a million for spending lot of time for my project. <img src="yabbfiles/Templates/Forum/processing_one/smiley.gif" border="0" alt="Smiley" title="Smiley" /> Toggle 3D/2D back and forth during program num_1276547236.html Processing Discourse/Programs num_1276547236.html Tue, 15 Jun 2010 00:57:06 +0000 In 3D mode, anything rendered at z=0 will be in the 2D (XY) plane. &nbsp;So you shouldn't have to switch modes. &nbsp;If you want to toggle depth_test or depth_sort, check out hint:<br /><a href="http://processing.org/reference/hint_.html" target="_blank">http://processing.org/reference/hint_.html</a> line across an ellipse num_1276539135.html Processing Discourse/Programs num_1276539135.html Mon, 14 Jun 2010 15:27:41 +0000 Just thinking aloud here, but any point on a sphere can be defined by two circles perpendicular to each other: i.e. set a random rotation on one axis around one circle and from that point rotate around the other axis...  though I'm sure there's a much more elegant mathematical solution.  In fact <a href="http://www.google.co.uk/search?q=random+point+on+a+sphere" target="_blank">google</a> gives plenty of results on this.  <a href="http://mathworld.wolfram.com/SpherePointPicking.html" target="_blank">This</a> is one for the maths geeks whilst <a href="http://demonstrations.wolfram.com/RandomPointsOnASphere/" target="_blank">this</a> gives a more obvious option to implement... sketch is partially off screen num_1276296238.html Processing Discourse/Programs num_1276296238.html Mon, 14 Jun 2010 11:30:39 +0000 You can use<br /> <b>Code:</b><pre class="code">frame&#46;setLocation&#40;0, 0&#41;&#059; </pre><br />in your setup() so it will always appear at the top left of your 1st screen <img src="yabbfiles/Templates/Forum/processing_one/cool.gif" border="0" alt="Cool" title="Cool" /><br /> <b>Code:</b><pre class="code"><br &#47;>void setup&#40;&#41;<br &#47;>&#123;<br &#47;>  size&#40;800,800&#41;<br &#47;>  frame&#46;setLocation&#40;0,0&#41;;<br &#47;>&#125; </pre> 3D bezier curve with gradient fill num_1276537508.html Processing Discourse/Programs num_1276537508.html Mon, 14 Jun 2010 10:57:30 +0000 Sorry, I was wrong, bezierPoint() actually works for 3D. I just worked out what I needed. The following is an example in case anyone else needs it:<br /> <b>Code:</b><pre class="code"><br &#47;>    color from = color&#40;255, 0, 0&#41;;<br &#47;>    color to = color&#40;0, 255, 0&#41;;<br &#47;>    int steps = 10;<br &#47;>    beginShape&#40;&#41;;<br &#47;>    for &#40;int j = 0; j &lt;= steps; j++&#41; &#123;<br &#47;>      float t = j &#47; float&#40;steps&#41;;<br &#47;>      stroke&#40;lerpColor&#40;from, to, t&#41;&#41;;<br &#47;>      float x = bezierPoint&#40;x1, cx1, cx2, x2, t&#41;;<br &#47;>      float y = bezierPoint&#40;y1, cy1, cy2, y2, t&#41;;<br &#47;>      float z = bezierPoint&#40;z1, cz1, cz2, z2, t&#41;;      <br &#47;>      vertex&#40;x, y, z&#41;;<br &#47;>    &#125;<br &#47;>    endShape&#40;&#41;; </pre><br /> 3d arc - static/physics? suggestions please num_1264522077.html Processing Discourse/Programs num_1264522077.html Mon, 14 Jun 2010 10:38:35 +0000 Wow... thanks Toxi! I'm learning more CG in a couple of days here than I've learned with the whole semester course... &nbsp;<img src="yabbfiles/Templates/Forum/processing_one/grin.gif" border="0" alt="Grin" title="Grin" /> Line graph num_1276526320.html Processing Discourse/Programs num_1276526320.html Mon, 14 Jun 2010 09:04:59 +0000 All the points are drawn every frame. This graph is actually within a bigger graph - when you roll over a point on the bigger graph, you get this smaller one. That's where the i in the nf(i,5) comes from. <br />I just use the &quot;*100-1000&quot; to make the points fit where I want them to.  I could probably find a better way to put that in the code, but this worked fine with the ellipses, so I don't think that's the problem. Here's the entire code for the graph that actually works, with the part we're working on highlighted:<br /><br /> <b>Code:</b><pre class="code">int numPics = 292; &#47;&#47; change with number of points, numPics = # pictures<br &#47;>PImage&#91;&#93; pics = new PImage&#91;numPics&#93;;<br &#47;>PFont font;<br &#47;>PFont small;<br &#47;>PFont large;<br &#47;>String&#91;&#93; num;<br &#47;>float&#91;&#93; values;<br &#47;><br &#47;>void setup&#40;&#41; &#123;<br &#47;>  size&#40;1000,950&#41;;<br &#47;>  smooth&#40;&#41;;<br &#47;>  font = loadFont&#40;&quot;Serif&#45;15&#46;vlw&quot;&#41;; <br &#47;>  small = loadFont&#40;&quot;Serif&#45;12&#46;vlw&quot;&#41;;<br &#47;>  large = loadFont&#40;&quot;LiSongPro&#45;32&#46;vlw&quot;&#41;;<br &#47;>  for &#40; int k = 0; k &lt; numPics; k++&#41; &#123;<br &#47;>    String imageName =  &quot;S5_stamp_&quot; + nf&#40;k, 5&#41; + &quot;&#46;png&quot;;<br &#47;>    pics&#91;k&#93; = loadImage&#40;imageName&#41;;     <br &#47;>  &#125;<br &#47;>&#125;<br &#47;><br &#47;>void draw&#40;&#41; &#123;<br &#47;>  background&#40;255&#41;;<br &#47;>  String&#91;&#93; data = loadStrings &#40;&quot;S5_quantities_4&#46;txt&quot;&#41;; <br &#47;> for &#40;int i = 0; i &lt; numPics; i++&#41; &#123;            <br &#47;>    num = splitTokens&#40;data&#91;i&#93;, WHITESPACE&#41;; <br &#47;>    values = parseFloat&#40;num&#41;;  <br &#47;>  ellipseMode&#40;CENTER&#41;;<br &#47;>  stroke&#40;150&#41;;<br &#47;>  fill&#40;255&#41;;<br &#47;>  float NII = log&#40;values&#91;5&#93;&#47;values&#91;4&#93;&#41;&#47;log&#40;10&#41;;<br &#47;>  float OIII = log&#40;values&#91;7&#93;&#47;values&#91;6&#93;&#41;&#47;log&#40;10&#41;;<br &#47;>if&#40;values&#91;8&#93; == 1&#41; &#123;<br &#47;>      fill&#40;0,0,255&#41;;<br &#47;>      stroke&#40;0,0,255&#41;;<br &#47;>    ellipse&#40;NII*650+800,&#45;OIII*350+350,3,3&#41;; &#47;&#47;transform, disk<br &#47;>  &#125;<br &#47;>else if&#40;values&#91;8&#93; == 2&#41; &#123;<br &#47;>    fill&#40;0,255,0&#41;;<br &#47;>    stroke&#40;0,255,0&#41;;<br &#47;>  ellipse&#40;NII*650+800,&#45;OIII*350+350,3,3&#41;; &#47;&#47;transform, peculiar<br &#47;>  &#125;<br &#47;>  else &#123;<br &#47;>    fill&#40;255,0,0&#41;;<br &#47;>    stroke&#40;255,0,0&#41;;<br &#47;>  ellipse&#40;NII*650+800,&#45;OIII*350+350,3,3&#41;; &#47;&#47;transform, spheroid<br &#47;>&#125;<br &#47;>  int lim = 2;<br &#47;>  if&#40;abs&#40;mouseX&#45;&#40;NII*650+800&#41;&#41; &lt; lim &amp;&amp; &#47;&#47;transform<br &#47;>  abs&#40;mouseY&#45;&#40;&#45;OIII*350+350&#41;&#41; &lt; lim&#41; &#123;<br &#47;>    image&#40;pics&#91;i&#45;1&#93;, 50, 500, 120, 120&#41;; <br &#47;>    textFont&#40;font&#41;;<br &#47;>    fill&#40;0&#41;;<br &#47;>    text&#40;&quot;NII&#47;Ha&quot; + &quot; &quot; + NII + &quot;  &quot; + &quot;OIII&#47;Hb&quot; + &quot; &quot; + OIII, 50, 630, 300, 60&#41;;<br &#47;>  &#125;<br &#47;>    <br &#47;> <span class="highlight">if &#40;abs&#40;mouseX&#45;&#40;NII*650+800&#41;&#41; &lt; lim &amp;&amp; &#47;&#47;transform<br &#47;>  abs&#40;mouseY&#45;&#40;&#45;OIII*350+350&#41;&#41; &lt; lim&#41; &#123;<br &#47;> String spectra = &quot;S5_hi_spectra_&quot; + nf&#40;i,5&#41; + &quot;&#46;txt&quot;;<br &#47;> println&#40;spectra&#41;;<br &#47;> String&#91;&#93; spec = loadStrings &#40;spectra&#41;;<br &#47;> for &#40;int j = 0; j &lt; 866; j++&#41; &#123;<br &#47;> String&#91;&#93; spec1 = splitTokens&#40;spec&#91;j&#93;, WHITESPACE&#41;;<br &#47;>    float&#91;&#93; spec2 = parseFloat&#40;spec1&#41;;<br &#47;>    pushMatrix&#40;&#41;;<br &#47;>    pushStyle&#40;&#41;;<br &#47;>    fill&#40;0&#41;;<br &#47;>    stroke&#40;0&#41;;<br &#47;>    translate&#40;50,900&#41;;<br &#47;>    scale&#40;0&#46;35&#41;;<br &#47;>    ellipse&#40;spec2&#91;1&#93;*100&#45;1000, &#45;spec2&#91;2&#93;*10000,1,1&#41;;</span><br &#47;>    line&#40;&#45;11,0,951,0&#41;;<br &#47;>    line&#40;0,&#45;550,0,10&#41;;<br &#47;>    for &#40;int k = 0; k &lt; width; k+=100&#41; &#123;<br &#47;>      line&#40;k,0,k,20&#41;;<br &#47;>    &#125;<br &#47;>   for &#40;int k = 0; k &lt; 600; k+=100&#41; &#123;<br &#47;>      line&#40;0,&#45;k,&#45;20,&#45;k&#41;;<br &#47;>    &#125;<br &#47;>    popStyle&#40;&#41;;<br &#47;>    popMatrix&#40;&#41;;<br &#47;> &#125;<br &#47;>    textFont&#40;small&#41;;<br &#47;>     float&#91;&#93; yscale = &#123;0&#46;05, 0&#46;04, 0&#46;03, 0&#46;02, 0&#46;01, 0&#46;0&#125;;<br &#47;>    for &#40;int k = 0; k &lt; 6; k++&#41; &#123;<br &#47;>      text&#40;nf&#40;yscale&#91;k&#93;,1,2&#41;, 15, k*35+725&#41;;<br &#47;>    &#125;<br &#47;>    float&#91;&#93; xscale = &#123;10, 11, 12, 13, 14, 15, 16, 17, 18, 19&#125;;<br &#47;>    for &#40;int k = 0; k &lt; 10; k++&#41; &#123;<br &#47;>      text&#40;nf&#40;xscale&#91;k&#93;,0,0&#41;, k*35+45, 920&#41;;<br &#47;>    &#125;<br &#47;>    text&#40;&quot;Flux v&#46; Wavelength&quot;, 175, 700&#41;;<br &#47;> &#125;<br &#47;> &#125; <br &#47;> <br &#47;>&#47;&#47; axes and scales<br &#47;>stroke&#40;0&#41;;<br &#47;>line&#40;0,2,width,2&#41;; &#47;&#47;horizontal<br &#47;>line&#40;width&#45;2,&#45;height,width&#45;2,height&#41;;    &#47;&#47;vertical<br &#47;>textFont&#40;font&#41;;<br &#47;>fill&#40;0&#41;;<br &#47;>text&#40;&quot;Log&#91;NII&#93;6584&#47;Ha&quot;, 10, 35&#41;;<br &#47;>text&#40;&quot;Log&#91;OIII&#93;5007&#47;Hb&quot;, width&#45;150, height&#45;10&#41;;<br &#47;>fill&#40;0,0,255&#41;;<br &#47;>text&#40;&quot;disk&quot;, 10, 645&#41;;<br &#47;>fill&#40;0,255,0&#41;;<br &#47;>text&#40;&quot;peculiar&quot;, 10, 660&#41;;<br &#47;>fill&#40;255,0,0&#41;;<br &#47;>text&#40;&quot;spheroid&quot;, 10, 675&#41;;<br &#47;>fill&#40;0&#41;;<br &#47;>for&#40;int i = 0; i &lt; height; i+=86&#41; &#123;<br &#47;>  line&#40;width&#45;4,i,width,i&#41;;<br &#47;>&#125;<br &#47;>float&#91;&#93; yscale = &#123;<br &#47;>  1&#46;25, 1, 0&#46;75, 0&#46;5, 0&#46;25, 0, &#45;0&#46;25, &#45;0&#46;5, &#45;0&#46;75, &#45;1&#46;0, &#45;1&#46;25, &#45;1&#46;5, &#45;1&#46;75&#125;;<br &#47;>for &#40;int i = 0; i &lt; 12; i++&#41; &#123;<br &#47;>  text&#40;nf&#40;yscale&#91;i&#93;,0,2&#41;, width&#45;40, &#40;i&#45;1&#41;*86&#41;;<br &#47;>&#125;<br &#47;><br &#47;>for&#40;int i = &#45;13; i &lt; width; i+=167&#41; &#123;<br &#47;>  line&#40;i,0,i,4&#41;;<br &#47;>&#125;<br &#47;><br &#47;>float&#91;&#93; xscale = &#123;<br &#47;>  &#45;1&#46;25, &#45;1, &#45;0&#46;75, &#45;0&#46;5, &#45;0&#46;25, 0, 0&#46;25, 0&#46;5, 0&#46;75, 1&#46;0&#125;;<br &#47;>for&#40;int i = 1; i &lt; 6; i++&#41; &#123;<br &#47;>  text&#40;nf&#40;xscale&#91;i&#93;,0,2&#41;, &#40;i&#41;*167&#45;13, 15&#41;;<br &#47;>&#125;<br &#47;>&#125; </pre><br /><br />This draws an entire graph of ellipses, spec2[1]*100-1000 vs -spec2[2]*10000. counting colors num_1276151592.html Processing Discourse/Programs num_1276151592.html Sun, 13 Jun 2010 23:14:19 +0000 Oh man, this is really cool.<br />Both code is really useful. <br />Thanks toxi and thanks philho! How to color a treemap? num_1269624656.html Processing Discourse/Programs num_1269624656.html Sun, 13 Jun 2010 08:58:20 +0000 <b><a class="message" href="num_1269624656.html#0">arenzky wrote</a> on Mar 26<sup>th</sup>, 2010, 9:30am:</b><br /><div class="quote" style="width: 90%">1. color the squares of my simple treemap <br /> </div><br /><br />don't think this is possible because all the work is being done by the treemap library which you don't have control over.<br /><br />map = new Treemap(mapData, 0, 0, width, height);<br />...<br />map.draw( );<br /><br />if map.draw() doesn't do colours then you're stuck. (unless you change the treemap code).<br /><br />(actually, the change looks quite easy given that Treemap.draw() is <br /> &nbsp;public void draw() &#123;<br /> &nbsp; &nbsp;Mappable[] items = model.getItems();<br /> &nbsp; &nbsp;for (int i = 0; i &lt; items.length; i++) &#123;<br /> &nbsp; &nbsp; &nbsp;items[i].draw();<br /> &nbsp; &nbsp;&#125;<br /> &nbsp;&#125;<br />you just need to change fill() and/or stroke() in the loop before the items[i].draw()<br />) ArrayIndexOutOfBoundsException num_1276277689.html Processing Discourse/Programs num_1276277689.html Sun, 13 Jun 2010 08:54:16 +0000 koogy's comments on style and code writing are all good. &nbsp;When I was first getting into Java/processing, I found it helpful to read a few Java style guides such as <a href="http://geosoft.no/development/javastyle.html" target="_blank">this one</a>.<br /><br />I'm not saying that particular style guide is &quot;correct&quot; or that it's the &quot;best&quot; one (as koogy says, there are religious wars about these things). &nbsp;What's important though, is that if you read a few of those (you can find others by googling &quot;Java style guide&quot; or something similar) it'll get you thinking about how to keep your code clear and readable. &nbsp;You don't have to agree with or follow every rule in that guide (I don't) but after you read it you'll understand some of the ways that code can be hard to read, and at least you'll be aware of those things when you're writing your own. Re: playing slideshow while taking pictures num_1276079765.html Processing Discourse/Programs num_1276079765.html Sun, 13 Jun 2010 03:35:14 +0000 Good idea, but to keep things simple in the slideshow and keep tasks separated, I would give this task to the sketch creating the images. Moved: 'Mother/Foetus sketch troubleshooting' num_1276379807.html Processing Discourse/Programs num_1276379807.html Sun, 13 Jun 2010 01:34:47 +0000 <b>This Topic has been moved to </b><a href="num_1276379808.html#0"><i><b>Other Libraries</b></i></a><b> by <i>PhiLho </i></b> Finding the height of a block of text num_1232855887.html Processing Discourse/Programs num_1232855887.html Fri, 11 Jun 2010 03:21:34 +0000 See also this topic : <br /><a href="http://processing.org/discourse/yabb2/num_1195937999_.html#34; target="_blank">http://processing.org/discourse/yabb2/num_1195937999_.html#60;/a> Worm that eats circles/ellipses num_1276246863.html Processing Discourse/Programs num_1276246863.html Fri, 11 Jun 2010 02:23:06 +0000 Hi, and welcome. Dunno if i got what you need but to achieve the effect you're after, one option could be to use some Vector math. This is the easiest (thanks to the Processing API) and more efficient way to 'move' stuff.<br />Nothing too difficult, have a look at these pages:<br />http://www.shiffman.net/teaching/nature/vectors/<br />http://www.processing.org/reference/PVector.html<br /><br />What you basically need to do, is to simulate motion, wich one could thing as of three vectors: the velocity, the position and the acceleration vectors.<br /><br />velocity = velocity + acceleration<br />position = position + velocity<br /><br />You should subtract the object (worm) initial position to the target position and apply that as a new velocity. That will move the worm toward the circle. more or less. <br />something like <br /><br /> <b>Code:</b><pre class="code"><br &#47;>PVector velocity = PVector&#46;sub&#40;targetloc,worm_origin_loc&#41;&#059;  <br &#47;> </pre><br /><br />but others may suggest different approaches.<br />Cheers<br />GC Image warping/morphing num_1138567834.html Processing Discourse/Programs num_1138567834.html Thu, 10 Jun 2010 11:12:24 +0000 For those who want to know the actual mathematical technique for morphing, and they are familiar with basic linear algebra, &nbsp;<br />google: beier morphing<br /><br />Just combine this technique with the pixel-polygon stuff mentioned above, and it wouldn't be so hard.