PVector pozicija; PVector brzina; PVector ubrzanje; float d = 40; float ugao = 0; void setac(float xc, float yc, float r, float u) { ellipseMode(RADIUS); translate(xc, yc); rotate(u); stroke(0); strokeWeight(2); fill(255,227,159); ellipse(0, 0, r, r); fill(255); ellipse(r/3, -r/2, r/3, r/3); ellipse(-r/3, -r/2, r/3, r/3); fill(255,227,159); ellipse(0, -r, r/5, r/5); ellipse(r/2, -2*r/3, 2, 2); ellipse(-r/2, -r/2, 2, 2); } void setup() { size(600,400); background(0); frameRate(30); smooth(); pozicija = new PVector(d + random(width - 2* d), d + random(height - 2* d)); brzina = new PVector(-0.5 + random(1), - 0.5 + random(1)); ubrzanje = new PVector(-0.5 + random(1), - 0.5 + random(1)); ellipseMode(RADIUS); setac(pozicija.x, pozicija.y, d, random(TWO_PI)); } void draw() { background(0); pozicija.add(brzina); brzina.add(ubrzanje); float u = 0; if (brzina.x != 0) { u = atan(brzina.y/brzina.x) + HALF_PI; if (brzina.x < 0) u += PI; } else if (brzina.y < 0) u = -HALF_PI; else u = HALF_PI; setac(pozicija.x, pozicija.y, d, u); if (abs(brzina.x) > 8) ubrzanje.x = -0.2 * brzina.x/abs(brzina.x); if (abs(brzina.y) > 6) ubrzanje.y = -0.2 * brzina.y/abs(brzina.y); int sudar = 0; if (pozicija.x > width-d) { pozicija.x = width - d; brzina.x = -brzina.x; sudar = 1; } if (pozicija.x < d) { pozicija.x = d; brzina.x = -brzina.x; sudar = 1; } if (pozicija.y > height-d) { pozicija.y = height - d; brzina.y = -brzina.y; sudar = 1; } if (pozicija.y < d) { pozicija.y = d; brzina.y = -brzina.y; sudar = 1; } if ((sudar == 1) || (frameCount % (10* frameRate) == 0)) ubrzanje = new PVector(-0.5 + random(1), - 0.5 + random(1)); }