## JS circle

May 30, 2010 at 9:10pm

# JS circle

Hi,

I´m new at js and I´m trying to draw a circle, but there is still something wrong.
Maybe someone could help…

– Pasted Max Patch, click to expand. –

//the js

inlets = 1;
outlets = 1;

var r = 1;

function msg_float(x)
{
Math.pow(r,2) = Math.pow(y,2)+Math.pow(x,2);
outlet(0, y);
}

//thanks Falk

#50652
May 30, 2010 at 10:20pm

not actually sure what you are trying to do (my math skills are bad!!) but it looks like r2 = x2 + y2. you are trying to assign the result of your equation (y2+x2) to a function Math.pow(r,2), which doesn’t make sense since Math.pow is returning a value. You can only pass it a value inside the (). also y is never defined and you are trying to send it to your outlet.
The below should work and give you r2 (y is a constant right now).
I’m sure someone with more js and math chops will explain it better, but maybe this will get you started.

var y = 2;

function msg_float(x)
{

var r = Math.pow(y,2)+Math.pow(x,2);

outlet(0, r);

}

#181694
May 31, 2010 at 7:06am

Hello maxers,

– Pasted Max Patch, click to expand. –

?
?
?
inlets = 1 ;
outlets = 1 ;

setinletassist (0, “(float) x”) ;
setoutletassist (0, “(float) (x, y1) (x, y2)”) ;

autowatch = 1 ;

var r = 50. ;
var a = 100. ;
var b = 150. ;

/* (a, b) circle center coordinates */

function msg_float (x)
{
var y1, y2 ;

if (x >= (a – r) && x

#181695
May 31, 2010 at 7:24am

Hi MIB,

you got me on the right path, I tried to assign a function to a value, I have to solve the equation for y, then it works, code blow.

thanks a lot

Falk

inlets = 1;
outlets = 1;

var r =1;

function msg_float(x)
{

y = Math.sqrt(Math.pow(r,2) – Math.pow(x,2));

outlet(0, y);

}

#181696
May 31, 2010 at 7:28am

Hi HTH,

thanks too for your nice example

Falk

#181697

You must be logged in to reply to this topic.