## Half-circle bumps

Let us know if you have a nice R.U.B.E script to share!
iforce2d
Posts: 860
Joined: Sat Dec 22, 2012 7:20 pm

### Half-circle bumps

Not really sure what to call this one... see this thread for the original topic: viewtopic.php?f=6&t=529

Code: Select all

``````//Name: Half-circle bumps
//Tags: line, bump
//Add body with a line fixture comprising a series of half-circles, offset from each other in x and y to form a row of bumps

float separationX = queryNumericValue('Bump separation X', 2);
float separationY = queryNumericValue('Bump separation Y', 2);
uint numSides = queryNumericValue('Number of sides', 14);
uint numBumps = queryNumericValue('Number of bumps', 4);
if ( numSides >= 3 && numBumps > 0 ) {
string xValues;
string yValues;
float xOffset = 0;
float yOffset = 0;
int rotateDir = -1;
int yOffsetMod = -1;
for (uint i = 0; i < numBumps; i++) {
for (uint n = 0; n < numSides; n++) {
float angle = n * (dr(360) / numSides);
if ( i+n > 0 ) {
xValues += ',';
yValues += ',';
}
vec2 v;
xValues += v.x;
yValues += v.y;
bool firstTime = i+n < numSides/2;
int modulus = n % numSides;
if ( ! firstTime ) {
if ( modulus == (numSides/2) ) {
yOffset += yOffsetMod * separationY;
xOffset += separationX;
rotateDir *= -1;
yOffsetMod *= -1;

xValues += ',' + v.x;
yValues += ',' + v.y;
}
if ( modulus == numSides-1 ) {

angle = (n+1) * (dr(360) / numSides);
xValues += ',' + v.x;
yValues += ',' + v.y;

yOffset += yOffsetMod * separationY;
xOffset += separationX;
rotateDir *= -1;
yOffsetMod *= -1;
}
}
}
}