We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › Toxiclibs beginner's tutorial
Page Index Toggle Pages: 1
Toxiclibs beginner's tutorial (Read 5014 times)
Toxiclibs beginner's tutorial
Oct 18th, 2009, 11:16am
 
Hi.
Are there tutorials for toxiclibs?

I just can't get started because the examples (at least those i found)
are either too complex or don't cover everything i'd like to do. The JavaDocs don't help very much.

For example i'd like to define a rect as a bounding box for some particles. How can i achieve that?
Ok, I found the "bounds" property of the VerletParticle2D class. But now i'd like the particle to bounce off the "wall".

Thanks
Re: Toxiclibs beginner's tutorial
Reply #1 - Oct 18th, 2009, 3:18pm
 
ive had some problems getting started because of the same reasons. i cant help you cause i couldnt find any good tutorials either.
But for the bounding box. I know using traerphysics it was simply done by just flippin the direction of the velocity maybe thats a good way to start... but if you find some good tutorials. please post them...
Re: Toxiclibs beginner's tutorial
Reply #2 - Oct 19th, 2009, 6:28am
 
Sorry not to post a solution to your post, but I am also trying to understand the lib, it can do very cool stuff but, without tutorials and documentation I find it very difficult

Please Toxi give us a hand!

Cheers
rS
Re: Toxiclibs beginner's tutorial
Reply #3 - Oct 21st, 2009, 12:12pm
 
Hi guys, I'm really sorry you're struggling with the lack of examples. It's something I'm painfully aware of, but at the same time trying my best to remedy. The main difference to other libraries here is that their development is not very linear & I'm constantly refactoring and extending the collection as I learn & work on new projects (of which there were many this year) and so development happens on many different fronts in parallel, but also with a bias towards features I currently require for these projects. And because I've been super busy with work projects for quite a few months now, I simply did not have the time to create a decent number of examples showing all the different features the libraries offer. I generally believe & have made lots of effort that they're easy to use though, but the most challenging task is to first communicate the basic concepts, idioms & conventions to people.

Having said that, I've been adding more demos with recent releases and the next round is coming up in the next week (which will have a few more demos again). Also, please don't make the mistake to compare or assume, that for example, my physics library is a 1:1 replacement for traer physics. It has not the same features (e.g. attraction) and served somewhat different purposes (so far).

I also realize that javadocs are not any help at all if you're working in the Processing IDE. However, I do mainly work on larger Java projects and exclusively use Eclipse (with Processing just being a part of the puzzle) and there the javadocs for each method are shown by simply hovering over a method name and so are much more in context when you're coding. I hardly ever look at javadocs in a web browser...

The other thing to note is that just like with Processing in the early days, other users of the libraries are somewhat reluctant to become contributors, share their code examples and so help at least on the examples front. I know people are putting stuff up, but are not communicating this back to me - so that they could be bundled with future revisions or put on the Google code site. Though again, I guess part of the reason here is also the lack of a proper roadmap and I'm desperately working towards having a bit more idle time at the end of the year to setup a project blog/website and spend more time on documentation.

Lastly, here're another 2 tiny examples (partly) related to your original question, which someone asked me to mockup recently (not sure if they're any helpful).

Code:

/**
* Softbody square demo
*/
import processing.opengl.*;

import toxi.physics2d.constraints.*;
import toxi.physics2d.*;

import toxi.geom.*;
import toxi.math.*;

int DIM=10;
int REST_LENGTH=20;
float STRENGTH=0.125;
float INNER_STRENGTH = 0.2;

VerletPhysics2D physics;
VerletParticle2D head,tail;

void setup() {
 size(1280,720,OPENGL);
 smooth();
 physics=new VerletPhysics2D();
 physics.gravity=new Vec2D(0,0.1);
 physics.setWorldBounds(new Rect(0,0,width,height));
 for(int y=0,idx=0; y<DIM; y++) {
   for(int x=0; x<DIM; x++) {
     VerletParticle2D p=new VerletParticle2D(x*REST_LENGTH,y*REST_LENGTH);
     physics.addParticle(p);
     if (x>0) {
       VerletSpring2D s=new VerletSpring2D(p,physics.particles.get(idx-1),REST_LENGTH,STRENGTH);
       physics.addSpring(s);
     }
     if (y>0) {
       VerletSpring2D s=new VerletSpring2D(p,physics.particles.get(idx-DIM),REST_LENGTH,STRENGTH);
       physics.addSpring(s);
     }
     idx++;
   }
 }
 VerletParticle2D p=physics.particles.get(0);
 VerletParticle2D q=physics.particles.get(physics.particles.size()-1);
 float len=sqrt(sq(REST_LENGTH*(DIM-1))*2);
 VerletSpring2D s=new VerletSpring2D(p,q,len,INNER_STRENGTH);
 physics.addSpring(s);
 p=physics.particles.get(DIM-1);
 q=physics.particles.get(physics.particles.size()-DIM);
 s=new VerletSpring2D(p,q,len,INNER_STRENGTH);
 physics.addSpring(s);
 head=physics.particles.get((DIM-1)/2);
 head.lock();
}

void draw() {
 background(0);
 stroke(255);
 head.set(mouseX,mouseY);
 physics.update();
 for(Iterator i=physics.springs.iterator(); i.hasNext();) {
   VerletSpring2D s=(VerletSpring2D)i.next();
   line(s.a.x,s.a.y,s.b.x,s.b.y);
 }
}
Re: Toxiclibs beginner's tutorial
Reply #4 - Oct 21st, 2009, 12:14pm
 
And the second one from the upcoming release:

Code:
/**
* PolarUnravel demo combines the following 3 features of toxiclibs:
* <ul>
* <li>Polar-Cartesian coordinate transformation</li>
* <li>Vector interpolation to smoothly switch layouts</li>
* <li>Use of InterpolateStrategy for easing effects</li>
* <li>Use TColor for working with HSV color space</li>
* </ul>
*
* The demo depends on the separately distributed colorutils package, also
* part of toxiclibs. You can download the latest version from here:
* http://code.google.com/p/toxiclibs/downloads/list
*
* Usage:
* Click mouse to toggle between radial/horizontal layout
*/

/*
* Copyright (c) 2009 Karsten Schmidt
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* http://creativecommons.org/licenses/LGPL/2.1/
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

import toxi.color.*;

import toxi.geom.*;
import toxi.math.*;

// keepers of transition state & target
float transition, transTarget;

// use a S-Curve to achieve ease in/out effect
InterpolateStrategy is=new SigmoidInterpolation(3);

void setup() {
 size(600,600,P3D);
}

void draw() {
 background(255);
 float w2=width * 0.5;
 float h2=height * 0.5;
 translate(w2, h2);
 // update transition
 transition += (transTarget - transition) * 0.01;
 // define direction vector for linear layout
 Vec2D normUp = new Vec2D(0, -1);
 // define a color container using HSV
 TColor col = TColor.newHSV(0, 1, 1);
 for(int i = 270; i < 360 + 270; i += 2) {
   float theta = radians(i);
   // create a polar coordinate
   Vec2D polar = new Vec2D(100,theta);
   // use theta as color hue (ensure theta is properly wrapped)
   col.setHue((polar.y / TWO_PI) % 1);
   // also use theta to manipulate line length
   float len = noise(polar.y * 4) * 100;
   // convert polar coord into cartesian space (to obtain position on a circle)
   Vec2D circ = polar.copy().toCartesian();
   // create another coord splicing the circle at the top and using theta difference as position on a line
   Vec2D linear = new Vec2D((MathUtils.THREE_HALVES_PI - polar.y) * w2 / PI + w2, 0);
   // interprete circular position as normal/direction vector
   Vec2D dir = circ.getNormalized();
   // interpolate both position & normal based on current transition state
   circ.interpolateToSelf(linear, transition,is);
   dir.interpolateToSelf(normUp, transition,is).normalizeTo(len);
   // apply color & draw line
   stroke(col.toARGB());
   line(circ.x, circ.y, circ.x + dir.x, circ.y + dir.y);
 }
}

void mousePressed() {
 // toggle transition target state
 transTarget=(++transTarget % 2);
}
Re: Toxiclibs beginner's tutorial
Reply #5 - Oct 21st, 2009, 12:49pm
 
Thank you for your effort. I really appreciate it.
Re: Toxiclibs beginner's tutorial
Reply #6 - Oct 21st, 2009, 12:57pm
 
Yer welcome. Also, if you're up for a more challenging (but well documented) application of the libraries, check this out:

http://processing.org/discourse/yabb2/num_1256153936.html
Re: Toxiclibs beginner's tutorial
Reply #7 - Oct 21st, 2009, 1:57pm
 
toxi wrote on Oct 21st, 2009, 12:12pm:
I also realize that javadocs are not any help at all if you're working in the Processing IDE.

They do, at least in the browser.

Quote:
other users of the libraries are somewhat reluctant to become contributors, share their code examples and so help at least on the examples front.

Quite an echo of what I wrote in controlP5, what causes event thread.
Re: Toxiclibs beginner's tutorial
Reply #8 - Oct 22nd, 2009, 7:12am
 
Thanks a lot! for the sample code, they did help me moving forward

rS
Re: Toxiclibs beginner's tutorial
Reply #9 - Oct 24th, 2009, 8:42am
 
Thank you so much! I'm looking forward to getting the new toxiclibs. It's almost like christmas. I hope that I will be able to give something back to the community some time.

best

wolle
Re: Toxiclibs beginner's tutorial
Reply #10 - Nov 17th, 2009, 2:08pm
 
I've just downloaded this library (core and colors). Happy to see there are a few examples in both zipfiles. All I need now is some free time to dive into all this. Hopefully soon!  Smiley
Page Index Toggle Pages: 1