[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[sc-users] collisions
- To: sc-users@xxxxxxxxxxxxxxxx
- Subject: [sc-users] collisions
- From: adam sanches <adam.sanches@xxxxxxxxx>
- Date: Thu, 23 Sep 2010 00:46:32 -0700
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:date:message-id :subject:from:to:content-type; bh=g6mVoFNTC+91RPXNLVpnyU+eKebCsPYjQaWax/2lO8I=; b=VTPrYwM75BZEi6igFXZnnJqd1MHwj9qfsSEvEswiDVmGw0k6oIJaBbPTE6UFwXZsq1 izx8ye/WBwCp6TwO5ZaQkPZZOFbh5XfuzS11mJ4r3tyCXOILVA9CMa43Ts8Rb2N7uc8w e6HF35resJlhThT6MCh2TrgDQMf6dKNZASU7M=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=iiXCW7fcTJNWIog3mxEYRJOBM7vYUkJ+ZHZ+LqvPuTaGQkHHy1dDaHl5lAtxJCMCQg lbf2x3Nf4t/z8oUX2A0KEUCzM8MjC8byCYWbZO/Wq7QuEZdRQo3/682o8GPl0ActLk8b Xj73w9qtIwvdRZGAQL3a7+KpnaAyqFGdiNbgY=
- List-id: SuperCollider users mailing list <sc-users.create.ucsb.edu>
- Reply-to: sc-users@xxxxxxxxxxxxxxxx
- Sender: owner-sc-users@xxxxxxxxxxxxxxxx
Hello , i been trying to make collisions between moving points calculating the distance between them using this formula:
d = sqrt((x-x2)*(x-x2) +(y-y2) * (y-y2))
I made this code for visualize the collisions using pen, its suppose that each spheres change its color when it collides with another, but im getting unexpected behaivors, all spheres are changing at the same time, Do anybody have an idea of what is happening?
(
~dist = 10;
w = Window("collisions", Rect(0,0,500, 500)).front;
w.view.background = "">u = UserView(w, Rect(0,0,500,500));
m = 25; //number of spheres
d= {500.rand@xxxxxxxx}.dup(m); // initial positions
u.animate= true;
u.drawFunc = {
Pen.width = 2;
Pen.capStyle = 1;
Pen.strokeColor= Color.white;
d= d.collect{|point|
point+( (5.rand - 2) @(5.rand - 2)) %(600@600);
};
d.do{|point|
d.do{|point2|
var dx, dy ;
dx = (point2.x - point.x);
dy = (point2.y - point.y);
if (point2 != point) {
if ( ((dx * dx) + (dy * dy)).sqrt < ~dist) {
Pen.strokeColor= Color.red;
}
}
};
Pen.addArc(point, 2, 0, 2pi);
};
Pen.stroke;
};
u.refresh;
)
thanks in advance
Adam