Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Fisica example

By: a guest on Oct 6th, 2011  |  syntax: None  |  size: 1.13 KB  |  views: 363  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /**
  2.  *  ContactRemove
  3.  *
  4.  *  by Ricard Marxer
  5.  *
  6.  *  This example shows how to use the contact events in order to remove bodies.
  7.  */
  8.  
  9. import fisica.*;
  10.  
  11. FWorld world;
  12.  
  13. void setup() {
  14.   size(400, 400);
  15.   smooth();
  16.  
  17.   Fisica.init(this);
  18.  
  19.   world = new FWorld();
  20.   world.setGravity(0, 100);
  21.   world.setEdges();
  22. }
  23.  
  24. void draw() {
  25.   background(255);
  26.  
  27.   if (frameCount % 50 == 0) {
  28.     float sz = random(30, 60);
  29.     FCircle b = new FCircle(sz);
  30.     b.setPosition(random(0+30, width-30), 50);
  31.     b.setVelocity(0, 100);
  32.     b.setRestitution(0.7);
  33.     b.setDamping(0.01);
  34.     b.setNoStroke();
  35.     b.setFill(200, 30, 90);
  36.     world.add(b);
  37.   }
  38.  
  39.   world.draw();
  40.   world.step();
  41. }
  42.  
  43. void contactEnded(FContact c) {  
  44.   if (!c.getBody1().isStatic()) {
  45.     FCircle b = (FCircle)c.getBody1();
  46.     if (b.getSize()>5) {
  47.       b.setSize(b.getSize()*0.9);
  48.     }
  49.   }
  50.  
  51.   if (!c.getBody2().isStatic()) {
  52.     FCircle b = (FCircle)c.getBody2();
  53.     if (b.getSize()>5) {
  54.       b.setSize(b.getSize()*0.9);
  55.     }
  56.   }
  57. }
  58.  
  59. void keyPressed() {
  60.   try {
  61.     saveFrame("screenshot.png");
  62.   }
  63.   catch (Exception e) {
  64.   }
  65. }
  66.  
  67.  
  68.  
clone this paste RAW Paste Data