animate rotation rect and explotion
in
Programming Questions
•
1 year ago
Hello.
I want a rectangle to spin around it's on center.
my rect is spawning outside the screen and will aim at the center.
I want it to rotate all the way... can figure it out, please help me.
Best to do this in the class or in main?
- class komet{
- int a = 15;
- int b = 15;
- float x = 0;
- float y = 0;
- float komet1,komet2;
- komet(float _x, float _y){
- x = _x;
- y = _y;
- float speed = 1;
- float ang = atan2(height/2-y, width/2-x);
- komet1 = cos(ang)*speed;
- komet2 = sin(ang)*speed;
- }
- void movement(){
- x +=komet1;
- y +=komet2;
- }
- void kometer(){
- rect(x,y,a,b);
- noStroke();
- }
- void collision(){
- if ( dist(x, y, i1, i2) < i3) {
- println("traff");
- x = 1000000;
- y = 1000000;
- i++;
- }
- }
- void smart(){
- movement();
- kometer();
- collision();
- }
- }
this is my mainer
- PImage jorden;
- import simpleML.*;
- int e = 0;
- ArrayList kometer = new ArrayList();
- int x = 0;
- int y = 0;
- int douche = 0;
- int i1 = 503;
- int i2 = 245;
- int i3 = 62;
- int i = 0;
- komet k;
- PFont Font;
- XMLRequest xmlRequest;
- int startTime; // for the timer to make request ever N seconds
- String html = ""; // String to hold data from request
- void setup() {
- // Creating and starting the request
- xmlRequest = new XMLRequest(this, "http://search.twitter.com/search.rss?q=end");
- xmlRequest.makeRequest();
- size(height = 1000, width = 500);
- smooth();
- }
- void draw() {
- background(0);
- ellipse(i1, i2, i3*2, i3*2);
- fill(227, 222, 181);
- // Every 5 seconds, make a new request
- int now = millis();
- if (now - startTime > 2000) {
- xmlRequest.makeRequest();
- println("Making request!");
- startTime = now;
- }
- jorden = loadImage("earth.png"); //Bilden
- imageMode(CENTER);
- image(jorden, 500, 250);
- for (int i = 0; i < kometer.size(); i++) {
- komet k = (komet)kometer.get(i);
- k.smart();
- }
- Font = loadFont("PressStartK-48.vlw");
- textFont(Font,48);
- text(i, 25, 75);
- }
- // When the request is complete
- void netEvent(XMLRequest ml) {
- // Retrieving an array of all XML elements inside "<title*>" tags
- String[] headlines = ml.getElementArray("title");
- for (int i = 0; i < headlines.length; i++) {
- // println(headlines[i]);
- }
- for (String html: headlines) {
- if (html.toLowerCase().contains("2012")) {
- douche++;
- println(douche);
- switch ((int) random(4)) {
- case 0:
- // top edge
- k = new komet( random(width), -10 );
- break;
- case 1:
- // right edge
- k = new komet( width+10, random(height) );
- break;
- case 2:
- // left edge
- k = new komet( -10, random(height) );
- break;
- case 3:
- // bot edge
- k = new komet( random(width), height+10 );
- break;
- }
- kometer.add(k);
- }
- }
- }
I also want to explode the rectangle when it hits my "earth.png"
1