Static Plus or Minus

If you're having trouble using Context Free or don't understand the language, ask for help here.

Moderators: MtnViewJohn, chris, mtnviewmark

Post Reply
ColorMeImpressed
Posts: 7
Joined: Tue May 05, 2009 5:07 pm

Static Plus or Minus

Post by ColorMeImpressed »

I've been trying to create a function to act as a static plus or minus sign, but I keep getting an error saying there is an unhandled exception.
Here's the code:

Code: Select all

startshape box

staticsign()= if(rand_static()>.5,1,-1)

shape box
{
	SQUARE[h (2*staticsign()) b 1 sat 1]
}
Any idea what's going on or how to create a better static plus or minus?

Thanks

User avatar
MtnViewJohn
Site Admin
Posts: 882
Joined: Fri May 06, 2005 2:26 pm
Location: Mountain View, California
Contact:

Re: Static Plus or Minus

Post by MtnViewJohn »

I get the exception too.

If you want a different static sign at each location then you have to actually invoke rand_static() each time:

Code: Select all

startshape box

sign(n) = if(n>.5,1,-1)

shape box
{
   SQUARE[h (2*sign(rand_static())) b 1 sat 1]
}
However, this code gives an error when it shouldn't. I will fix this and send out beta4 in a few days.

User avatar
MtnViewJohn
Site Admin
Posts: 882
Joined: Fri May 06, 2005 2:26 pm
Location: Mountain View, California
Contact:

Re: Static Plus or Minus

Post by MtnViewJohn »

Try this:

Code: Select all

startshape box

sign(n) = if(n>.5,1,-1)

shape box
{
   SQUARE[h (2*sign(rand_static(1))) b 1 sat 1]
}
Changing rand_static() to rand_static(1) works around the bug in beta3.

ColorMeImpressed
Posts: 7
Joined: Tue May 05, 2009 5:07 pm

Re: Static Plus or Minus

Post by ColorMeImpressed »

It's working great now. Thanks a lot!

murph
Posts: 4
Joined: Wed Jul 20, 2011 5:28 am

Re: Static Plus or Minus

Post by murph »

I am seeing a syntax error when functions are defined... as above. I first saw it while trying out
the demo code from the Symmetry pages...
a_from_bAc( _b, _A, _c) = sqrt(_b^2 + _c^2 - 2* _b*_c*cos(_A)) also when I tried the Ack function from the
documentation:
// Ackerman function
ack(m, n) =
if(m == 0,
n+1,
if(n == 0,
ack(m-1, 1),
ack(m-1, ack(m, n-1))
)
)

How did you get the following to work? :
startshape box

sign(n) = if(n>.5,1,-1)

shape box
{
SQUARE[h (2*sign(rand_static(1))) b 1 sat 1]
}

User avatar
MtnViewJohn
Site Admin
Posts: 882
Joined: Fri May 06, 2005 2:26 pm
Location: Mountain View, California
Contact:

Re: Static Plus or Minus

Post by MtnViewJohn »

Are you sure that you have the latest beta release? I just tried

Code: Select all

startshape box

sign(n) = if(n>.5,1,-1)

shape box
{
   SQUARE[h (2*sign(rand_static(1))) b 1 sat 1]
}
On Windows, Mac, and Unix and it worked fine. Are you running v3 beta4? What is the number in parentheses when you bring up the About dialog?

murph
Posts: 4
Joined: Wed Jul 20, 2011 5:28 am

Re: Static Plus or Minus

Post by murph »

cfg...Help..About... : 3.0a (v23)

How does this relate to alpha, beta, etc.? I thought I had a recent version; but guess I should download again..
I just checked my download folder and found a ...install3.0beta4.exe dated may 7... Maybe I never ran it.. :(
Just ran it. I'm probably all set.. at least the wallpaper sampler rendered!! as a p1.. Which is what i was
originally trying to accomplish. Thanks. Embarassed.... ;)

User avatar
MtnViewJohn
Site Admin
Posts: 882
Joined: Fri May 06, 2005 2:26 pm
Location: Mountain View, California
Contact:

Re: Static Plus or Minus

Post by MtnViewJohn »

No worries. I've done that before.

Post Reply