Most cases of premature ejaculation do not have a clear cause. With sexual experience and age, men often learn to delay orgasm. Premature ejaculation may occur with a new partner, only in certain sexual situations, or if it has been a long time since the last ejaculation. Psychological factors such as anxiety, guilt, or depression can cause premature ejaculation. In some cases, premature ejaculation may be related to a medical cause such as hormonal problems, injury, or a side effect of certain medicines. Quick flash to our customers: order cialis online uk with no prescription if you need generic cialis and get fast delivery to uk. Worrying that you won't be able to perform in bed can make it harder for you to do just that. Anxiety from other parts of your life can also spill over into the bedroom. Full information about Kamagra product line by Adjanta - buy kamagra oral jelly online in australia.

Sloppy worm knot

February 10th, 2009

Here’s a knot of 20 worms of 500 segments each, branching from the same seed segment. The code below has smaller, child-proof default values.

MEL code follows:

//--start--

// find the center of a face
proc vector centerOfFace(string $face) {
  // get locations of all the face's vertices
  float $pos[] = `xform -q -ws -t ($face)`;
  // get length of the array: # vertices * 3
  int $posSize = size($pos);
  // put the average of all vectors into 1st vector 
  for ($i = 0; $i < 3; $i++){
    for ($j = $i + 3; $j < $posSize; $j += 3){
      $pos[$i] += $pos[$j];
    }
    $pos[$i] /= ($posSize / 3);
  }
  return <<$pos[0], $pos[1], $pos[2]>>;
}

//get angle between two vertices with respect to a third point
proc float getAngle(string $vertA, string $vertB, vector $orig) {
  // get location of both vertices
  vector $aLoc = `xform -q -ws -t $vertA`;
  vector $bLoc = `xform -q -ws -t $vertB`;
  // normalize locations to the face center
  vector $aOrig = <<$aLoc.x - $orig.x, $aLoc.y - $orig.y, $aLoc.z - $orig.z>>; 
  vector $bOrig = <<$bLoc.x - $orig.x, $bLoc.y - $orig.y, $bLoc.z - $orig.z>>; 
  // use law of cosines via dot product
  float $dot = dotProduct( $aOrig, $bOrig, 1 );
  float $angle = rad_to_deg(acos($dot));
  //round answer down to two decimal places
  return (floor(($angle+.005)*100))/100;
}

proc string[] copyCone(string $old) {
  // copy cone
  $new = `duplicate $old`;
  // pick a random face on $old that isn't the base
  int $r = rand(3)+1;
  $selectedFace = ($old + ".f[" + $r + "]");
  // move $new to selected face
  vector $fc = centerOfFace($selectedFace);
  xform -a -t ($fc.x) ($fc.y) ($fc.z) $new[0];
  // aim $new at face with a temporary normal constraint
  string $tmpConst[] = `normalConstraint -aim 0 1 0 $selectedFace $new`;
  delete $tmpConst[0];
  // pick a vertex on each pyramid
  $newVertex = $new[0]+".vtx[0]"; // 0 is on the base
  $oldVertex = $old+".vtx[3]"; // 3 is the tip
  // get angle between two vertices
  $angle = getAngle($newVertex, $oldVertex, $fc);
  if ($angle > 0) { // if not already aligned
    // rotate $new to align the corners
    xform -r -os -ro 0 $angle 0 $new[0];
    // check the result
    $angle2 = getAngle($newVertex, $oldVertex, $fc);
    // if still not aligned, go the other way twice
    if ($angle2 > 0) {
      $angle3 = $angle * -2;
      xform -r -os -ro 0 $angle3 0 $new[0];
    }
  }
  return $new;
}

proc doit() {
  // make a regular tetrahedron and select it
  select `polyCone -r 1 -h 1.414214 -sx 3`;
  // move its pivot point to the bottom face
  xform -rp 0 -0.707107 0;
  // move to orig and freeze xforms
  xform -t 0 0.707107 0;
  makeIdentity -apply true -t 1;

  //delete the bottom face to lighten the load
  string $old[] = `ls -sl`;
  $selectedFace = ( $old[0] + ".f[0]" );
  delete $selectedFace;

  string $list[];
  int $numBranches = 10;
  int $branchLength = 50;

  int $i,$j;
  //initialize branches
  for ($i=0; $i<$numBranches; ++$i) {
    $new = copyCone($old[0]);
    $list[$i] = $new[0];
    //print("$list["+$i+"]: "+$list[$i]+"\n");
    //animate visibility
    setKeyframe -attribute "visibility" -v 0 -t 0 $new; 
    setKeyframe -attribute "visibility" -v 1 -t 1 $new;
  }

  for ($i=0; $i<$branchLength; ++$i) {
    for ($j=0; $j<$numBranches ; ++$j) {
      $new = copyCone($list[$j]);
      $list[$j] = $new[0];
    //animate visibility
    setKeyframe -attribute "visibility" -v 0 -t 0 $new; 
    setKeyframe -attribute "visibility" -v 1 -t ($i+2) $new;
    }
  }
}
doit();
print("done!");

//--end---
« previously: 50,000 Tetrahedrons | Home | next: Semi-polite worm »

2 Responses to “Sloppy worm knot”

  1. arnaud Says:

    Hey Peter,
    How did you got familiar with mel by the way? Just geeky fits? Or are you seduced by the poetry of obscure coding since you was a kid?
    :) ))

    I should try to tamper with mel also. I’m supposed to know how it works because I got a few courses.

  2. zoomy Says:

    “Geeky fits” describes my life pretty well. I have other coding experience, so I’ve just been picking a goal, digging through the documentation, and looking for examples online until I either figure it out or determine that my goal was crazy.

    This process has only changed a little since I started in HyperCard on my dad’s Mac Plus. These days my goals have less to do with space comedy.

Leave a Reply