Advertisement
Guest User

registerDraw

a guest
Apr 11th, 2012
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.88 KB | None | 0 0
  1. package com.danbrookes.main;
  2.  
  3. import java.util.ArrayList;
  4. import processing.core.*;
  5.  
  6. public class Base extends PApplet {
  7.  
  8.     private static final long serialVersionUID = -7052994455601885135L;
  9.     private ArrayList<TestObject> list = new ArrayList<TestObject>();
  10.     private PApplet app = this;
  11.     private int amount = 2500;
  12.     private float rnd;
  13.     private float ms;
  14.    
  15.     // main
  16.     public static void main(String[] args) {
  17.         PApplet.main(new String[] {Base.class.getName()});
  18.     }
  19.    
  20.     // setup
  21.     @Override
  22.     public void setup() {
  23.         size(640, 360);
  24.         frameRate(60);
  25.         fill(255, 128);
  26.         strokeWeight(1);
  27.         stroke(0, 128);
  28.         textSize(48);
  29.         smooth();
  30.         for (int i = 0; i < amount; i++) {
  31.             rnd = random(10);
  32.             list.add(new TestObject(app, random(width), random(height), rnd, rnd));
  33.         }
  34.     }
  35.  
  36.     // draw
  37.     @Override
  38.     public void draw() {
  39.         background(255);
  40.         fill(0, 64);
  41.         ms = millis();
  42.         for (int i = 0; i < amount; i++) {
  43.             list.get(i).setPos(list.get(i).getX() + random(-2,2), list.get(i).getY() + random(-2,2));
  44.         }
  45.         fill(255,0,0);
  46.         text(millis() - ms + "", 10, 10, 200, 200);
  47.     }
  48. }
  49.  
  50. ---------------------------------------------
  51.  
  52. package com.danbrookes.main;
  53.  
  54. import processing.core.*;
  55.  
  56. public class TestObject {
  57.    
  58.     private PApplet pro;
  59.     private float x;
  60.     private float y;
  61.     private float w;
  62.     private float h;
  63.    
  64.     public TestObject(PApplet processing, float tX, float tY, float tW, float tH) {
  65.         pro = processing;
  66.         pro.registerDraw(this);
  67.         x = tX;
  68.         y = tY;
  69.         w = tW;
  70.         h = tH;
  71.     }
  72.  
  73.     public void draw() {
  74.         pro.ellipse(x, y, w, h);
  75.     }
  76.    
  77.     public void setPos(float x, float y) {
  78.         this.x = x;
  79.         this.y = y;
  80.     }
  81.    
  82.     public float getX() {
  83.         return x;
  84.     }
  85.  
  86.     public float getY() {
  87.         return y;
  88.     }
  89.  
  90.     public void setScale(float w, float h) {
  91.         this.w = w;
  92.         this.h = h;
  93.     }
  94.    
  95.     public float getW() {
  96.         return w;
  97.     }
  98.  
  99.     public float getH() {
  100.         return h;
  101.     }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement