ellipse collision?
in
Programming Questions
•
1 year ago
- can't let the ellipse bounce op rectangles
- can someone help? It's urgent.
- import toxi.geom.*;
- Agent a, b, c, d, e, f, g, h, i, j, k, l, m, n, o;
- //ArrayList agentCollection;
- void setup() {
- size (647, 694);
- PImage img1;
- smooth();
- img1 = loadImage("Klembord01.gif");
- color q = get(520, 420);
- color r = get(200, 280);
- println (q);
- println (r);
- /*
- agentCollection = new Arraylist();
- for(int i = 0; i < 100; i++){
- Vec3D origin = new Vec3D(width/2, random(200), 0);
- agent myAgent = new agent(origin);
- agentCollection.add(myAgent);
- }
- */
- Vec3D startLoc= new Vec3D(90, 60, 0);
- Vec3D startLoc2 = new Vec3D(140, 120, 0);
- Vec3D startLoc3 = new Vec3D(534, 46, 0);
- Vec3D startLoc4 = new Vec3D(528, 300, 0);
- Vec3D startLoc5 = new Vec3D(377, 576, 0);
- Vec3D startLoc6 = new Vec3D(517, 615, 0);
- Vec3D startLoc7 = new Vec3D(88, 564, 0);
- Vec3D startLoc8 = new Vec3D(295, 388, 0);
- Vec3D startLoc9 = new Vec3D(328, 116, 0);
- Vec3D startLoc10 = new Vec3D(356, 308, 0);
- Vec3D startLoc11 = new Vec3D(520, 300, 0);
- Vec3D startLoc12 = new Vec3D(150, 230, 0);
- Vec3D startLoc13 = new Vec3D(140, 210, 0);
- Vec3D startLoc14 = new Vec3D(585, 595, 0);
- Vec3D startLoc15 = new Vec3D(235, 400, 0);
- a = new Agent(startLoc);
- b = new Agent(startLoc2);
- c = new Agent(startLoc3);
- d = new Agent(startLoc4);
- e = new Agent(startLoc5);
- f = new Agent(startLoc6);
- g = new Agent(startLoc7);
- h = new Agent(startLoc8);
- i = new Agent(startLoc9);
- j = new Agent(startLoc10);
- k = new Agent(startLoc11);
- l = new Agent(startLoc12);
- m = new Agent(startLoc13);
- n = new Agent(startLoc14);
- o = new Agent(startLoc15);
- }
- void draw() {
- fill(255, 10);
- PImage img1;
- img1 = loadImage("Klembord01.gif");
- image(img1, 0, 0);
- fill(0);
- rect(0, 0, 37, 694);
- rect(0, 0, 647, 24);
- rect(612, 0, 37, 694);
- rect(0, 660, 647, 33);
- rect(575, 58, 37, 207);
- rect(470, 336, 112, 207);
- rect(242, 168, 253, 68);
- rect(425, 33, 70, 130);
- rect(32, 340, 155, 13);
- rect(32, 428, 155, 13);
- rect(262, 340, 134, 13);
- rect(76, 353, 11, 76);
- rect(263, 418, 55, 8);
- rect(386, 340, 11, 158);
- rect(326, 490, 70, 9);
- rect(326, 490, 13, 170);
- rect(175, 490, 13, 170);
- ellipse(276, 38, 22, 20);
- ellipse(314, 38, 22, 20);
- ellipse(355, 37, 22, 20);
- ellipse(82, 292, 74, 81);
- /*
- for(int i = 0; i < agentCollection.size(); i++){
- agent na = (agent) agentCollection.get(i);
- na.run();
- }*/
- a.run();
- b.run();
- c.run();
- d.run();
- e.run();
- f.run();
- g.run();
- h.run();
- i.run();
- j.run();
- k.run();
- o.run();
- }
- float z = random(1, 10);
- class Agent {
- Vec3D loc;
- Vec3D vel = new Vec3D(z, z, 0);
- Vec3D acc = new Vec3D(z, z, 0);
- Agent(Vec3D _loc) {
- loc = _loc;
- }
- void run() {
- display();
- update();
- followMouse();
- botsen();
- }
- void followMouse() {
- Vec3D target = new Vec3D(width/3, height+40, 0);
- Vec3D dif = target.sub(loc);
- float distance = dif.magnitude();
- dif.normalize();
- dif.scaleSelf(100/distance);
- acc.addSelf(dif);
- }
- void update() {
- vel.addSelf(acc);
- vel.limit(5);
- loc.addSelf(vel);
- acc = new Vec3D();
- }
- void display() {
- stroke(0);
- fill(255);
- ellipse(loc.x, loc.y, 10, 10);
- }
- void botsen() {
- if (loc.x > width-35 || loc.x<35)
- {
- vel.x = vel.x * -1;
- }
- if (loc.y > height-40 || loc.y <40)
- {
- vel.y = vel.y * -1;
- }
- }
- }
1