Advertisement
Guest User

Fisica example

a guest
Oct 6th, 2011
717
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  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.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement