Benvenuto, Visitatore. Per favore, effettua il login o registrati.

  Hai perso la tua email di attivazione?

Main Home Help Ricerca Login Registrati

+  Virtual Sound - FORUM
|-+  Linguaggi per la Computer Music
| |-+  Max MSP Jitter
| | |-+  piccola pacth
« precedente successivo »
Pagine: [1] Stampa
Autore Topic: piccola pacth  (Letto 1019 volte)
mic
Sr. Member
****
Posts: 401


Guarda Profilo
« il: Dicembre 17, 2005, 21:04:21 »

ciao a tutti, volevo condividere con voi questa patchetina che ho fatto qualche tempo fa (..so che si ora può fare usando flash e jitter, ma quando l'ho fatta non avevo ancora le ultime versioni)..può servire per comandare parametri..ciò che si vuole..bounce bounce!


salvate il seguente codice come b_bounce.js

inlets= 1;
outlets= 3;
 
var gravity= 1;
var airfriction= 0.995;
var elasticity= 0.85;
var _x = 140;
var _y = 140;
var xpos = _x;
var ypos = _y;    // Starting position of shape   
var xold = _x;
var yold = _y;
var xspeed = 2.2;
var yspeed = 2.2;  // Speed of the shape
var lcds= 1; // lcd size
var mouse_state = 0;
var dragging = false;
var bsize ;

//ball size
function ballsize(b)
{
   bsize = b;
}

//lcd resizing
function lcdsize(s)
{
   lcds= s;   
}
//gravity force
function grav(g)
{
   gravity = g;
}
//air friction
function airfric(f)
{
   airfriction = f;
}
//ball elasticity
function elast(e)
{
   elasticity = e;
}

function dragx(d)
{
   if (d > lcds - bsize) {
   d= lcds - bsize;}
   if (d < 0) {
   d= 0;}
_x= d;
}

function dragy(a)
{   
   if (a > lcds - bsize) {
   a= lcds - bsize;}
   if (a < 0) {
   a= 0;}
_y= a;
}

function mouse(m)
{
   mouse_state = m;
   if (m == 1){
   dragging = true;
   }
   else{
   dragging = false;
   }
}
   
function bang()
{
    if (! dragging){

   xspeed = xspeed * airfriction;
   yspeed = (yspeed + gravity)*airfriction;
   xpos = xpos + xspeed;
    ypos = ypos + yspeed;
   outlet(2, Math.abs (xspeed )+ Math.abs (yspeed));
   outlet(0, xpos);
   outlet(1, ypos);
   }
   else{
   xold = xpos;
   yold = ypos;
   xpos = _x;
   ypos = _y;
   xspeed = ( xpos - xold ) / airfriction;
   yspeed = ( ypos - yold ) / airfriction;
   outlet(2, Math.abs (xspeed )+ Math.abs (yspeed));
   outlet(0, xpos);
   outlet(1, ypos);
   }

   

   
    
    // Test to see if the shape exceeds the boundaries of the screen
    // If it does, reverse its direction by multiplying by -1
    if (ypos > (lcds - bsize)) {
   ypos= lcds - bsize;
      yspeed = - yspeed * elasticity; }
   if (ypos <0) {
   ypos= 0;
      yspeed = - yspeed * elasticity; }
   if (xpos > (lcds - bsize)) {
   xpos= lcds-bsize;
      xspeed = - xspeed * elasticity; }
   if (xpos < 0) {
   xpos= 0;
      xspeed = - xspeed * elasticity; }
   
}


 
 
main patch

max v2;
#N vpatcher 25 45 1029 765;
#P origin 0 -11;
#P window setfont "Sans Serif" 9.;
#P flonum 216 226 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 724 46 20 196617 49;
#P message 724 157 59 196617 ballsize \$1;
#P number 724 96 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 645 46 23 196617 0.9;
#P flonum 645 96 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 645 157 47 196617 elast \$1;
#P message 557 44 17 196617 1.;
#P message 472 45 31 196617 0.02;
#P flonum 557 95 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 472 94 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 557 155 55 196617 airfric \$1;
#P message 472 156 46 196617 grav \$1;
#P message 791 137 92 196617 frgb 255 255 255;
#P message 310 70 14 196617 0;
#P message 623 655 53 196617 mouse \$1;
#P message 565 654 51 196617 dragy \$1;
#P message 507 654 51 196617 dragx \$1;
#P newex 98 681 40 196617 unpack;
#P message 260 69 26 196617 280;
#P toggle 60 39 15 0;
#P newex 60 59 52 196617 metro 33;
#P newex 141 198 75 196617 js b_bounce.js;
#P message 60 167 56 196617 lcdsize \$1;
#P number 60 109 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 166 118 27 196617 pak;
#P message 195 118 104 196617 script size lcd \$1 \$2;
#N thispatcher;
#Q end;
#P newobj 195 140 61 196617 thispatcher;
#P newex 260 22 48 196617 loadbang;
#P toggle 301 248 15 0;
#P message 301 266 83 196617 enablesprites \$1;
#P number 98 225 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 62 268 33 196617 pack;
#P newex 62 247 33 196617 bondo;
#P number 62 225 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 62 294 106 196617 drawsprite me \$1 \$2;
#P message 394 266 342 196617 recordsprite \, paintoval 0 0 \$1 \$1 10 \, closesprite me \, drawsprite me 0 0;
#P newex 62 324 46 196617 t l clear;
#P user lcd 98 376 280 280 1 1 0 0 1;
#P objectname lcd;
#P comment 78 39 30 196617 start;
#P comment 479 78 42 196617 gravity;
#P comment 564 78 57 196617 air-friction;
#P comment 653 77 50 196617 elasticity;
#P comment 732 77 24 196617 size;
#P comment 382 381 33 196617 drag!!;
#P comment 62 203 60 196617 x y position;
#P comment 219 201 32 196617 speed;
#P connect 26 0 25 0;
#P fasten 27 0 22 0 265 91 65 91;
#P connect 22 0 23 0;
#P fasten 24 0 12 0 146 219 67 219;
#P connect 12 0 13 0;
#P connect 13 0 14 0;
#P connect 14 0 11 0;
#P connect 11 0 9 0;
#P fasten 15 0 13 1 103 244 90 244;
#P connect 13 1 14 1;
#P fasten 24 1 15 0 178 219 103 219;
#P fasten 33 0 8 0 796 365 103 365;
#P fasten 16 0 8 0 306 365 103 365;
#P fasten 10 0 8 0 399 365 103 365;
#P fasten 9 1 8 0 103 361 103 361;
#P fasten 9 0 8 0 67 361 103 361;
#P fasten 8 0 28 0 103 664 103 664;
#P fasten 30 0 24 0 570 197 146 197;
#P fasten 29 0 24 0 512 197 146 197;
#P fasten 31 0 24 0 628 181 146 181;
#P fasten 40 0 24 0 650 173 146 173;
#P fasten 35 0 24 0 562 173 146 173;
#P fasten 34 0 24 0 477 173 146 173;
#P fasten 25 0 24 0 65 87 146 87;
#P connect 23 0 24 0;
#P fasten 44 0 24 0 729 180 146 180;
#P fasten 22 0 21 0 65 148 171 148;
#P fasten 22 0 21 1 65 134 188 134;
#P fasten 21 0 20 0 171 134 200 134;
#P connect 20 0 19 0;
#P fasten 24 2 46 0 210 219 221 219;
#P connect 18 0 27 0;
#P fasten 18 0 17 0 265 42 306 42;
#P connect 17 0 16 0;
#P fasten 18 0 32 0 265 42 315 42;
#P fasten 18 0 10 0 265 42 399 42;
#P fasten 43 0 10 0 729 130 399 130;
#P fasten 18 0 38 0 265 42 477 42;
#P connect 38 0 36 0;
#P connect 36 0 34 0;
#P fasten 28 0 29 0 103 675 512 675;
#P fasten 18 0 39 0 265 42 562 42;
#P connect 39 0 37 0;
#P connect 37 0 35 0;
#P fasten 28 1 30 0 133 675 570 675;
#P fasten 8 2 31 0 283 675 628 675;
#P fasten 32 0 31 0 315 42 628 42;
#P fasten 18 0 42 0 265 42 650 42;
#P connect 42 0 41 0;
#P connect 41 0 40 0;
#P fasten 18 0 45 0 265 42 729 42;
#P fasten 45 0 43 0 729 86 729 86;
#P connect 43 0 44 0;
#P fasten 18 0 33 0 265 42 796 42;
#P pop;
Loggato
franz
AAA1
Hero Member
*
Posts: 829


Guarda Profilo WWW
« Risposta #1 il: Dicembre 17, 2005, 22:05:43 »

scaricata e montata, appena ho due minuti la provo Sorriso
Loggato

mic
Sr. Member
****
Posts: 401


Guarda Profilo
« Risposta #2 il: Dicembre 17, 2005, 22:15:58 »

..ne ho fatte altre con più palline..in realtà però ho visto che js si appesantisce un po troppo quando gli fai fare troppa roba, meglio tenere separate le varie istanze js..ne ho fatta una dove ho messo lo script js dentro un poly!! per avere n. istanze.. funziona bene Wow
Loggato
franz
AAA1
Hero Member
*
Posts: 829


Guarda Profilo WWW
« Risposta #3 il: Dicembre 17, 2005, 22:19:32 »

uhm ci sto giocherellando un pochino, da quello che ho capito dovrebbe simulare il rimbalzo di una pallina con varie caratteristiche fisiche come gravità, peso ecc...però la pallina non si muove a meno che non gli dia le coordinate precise tramite number box...sarà un problema di [js ] ?

.franz
Loggato

mic
Sr. Member
****
Posts: 401


Guarda Profilo
« Risposta #4 il: Dicembre 17, 2005, 23:14:12 »

..??..non saprei, da me funziona perfettamente..draggo la pallina e lei rimbalza e tutto il resto..non saprei veramente..forse si è incasinato qualcosa nel js copiando e incollando dal browser..controlla nel codice che non si sia incasinato qualcosa alla "function mouse (m)" o subito dopo alla condizione (!dragging)..ti da degli errori nella max window..?
Loggato
franz
AAA1
Hero Member
*
Posts: 829


Guarda Profilo WWW
« Risposta #5 il: Dicembre 17, 2005, 23:23:28 »

bhè certo che se incollo 3/4 di script non funzionerà mai Linguaccia pardon

ora funziona alla perfezione, il trajectory, di cui ti parlavo nell'altro thread ha anche questa funzione comodissima Sorriso
comunque complimenti è davvero carina e utile! Sopratutto complimenti per il javascript, io non saprei proprio dove mettere le mani Linguaccia

.franz
« Ultima modifica: Dicembre 17, 2005, 23:29:30 da .franz » Loggato

lorbi
Full Member
***
Posts: 211


Guarda Profilo
« Risposta #6 il: Dicembre 18, 2005, 11:38:23 »

non ho tempo ora di fare la prova.

ma per i modelli fisici in max e PD consiglio vivamente a tutti le librerie

di cyrille e ali che trovate a questo sito.

besos

http://drpichon.free.fr/pmpd/

lorbi
Loggato
franz
AAA1
Hero Member
*
Posts: 829


Guarda Profilo WWW
« Risposta #7 il: Dicembre 18, 2005, 12:39:05 »

wow anche per pd! E soprtutto utilizzano GEM fantastico!
Loggato

lorbi
Full Member
***
Posts: 211


Guarda Profilo
« Risposta #8 il: Dicembre 18, 2005, 13:21:59 »

 Grossa risata
Loggato
NOwave
Full Member
***
Posts: 233



Guarda Profilo
« Risposta #9 il: Febbraio 05, 2006, 09:16:52 »

Bella ed è anche un bel tutorial . Grazie mic 

Ciao p
« Ultima modifica: Febbraio 05, 2006, 11:22:42 da NOwave » Loggato
Pagine: [1] Stampa 
« precedente successivo »
Salta a:  


Login con username, password e lunghezza della sessione

Powered by MySQL Powered by PHP © Copyright 1996 - 2008 - ConTempoNet Edizioni Musicali ® - P.IVA: 05174251008
Tutti i diritti riservati - Tutti i marchi sono registrati -
È vietata la riproduzione, anche parziale, dei testi e delle immagini.
Powered by SMF 1.1.5 | SMF © 2006-2008, Simple Machines LLC
Traduzione Italiana a cura di SMItalia
XHTML 1.0 Valido! CSS Valido!