Code assignment – week 8 – Bug Spray

In this sketch, I created an interactive simulation where a bug spray chases a cockroach on the screen. The bug spray employs steering behaviors to follow the cockroach, and when the cockroach is within a close proximity, the bug spray visually simulates spraying.

Challenge

One challenge encountered was ensuring smooth steering behavior for the bug spray. Tweaking parameters such as maximum speed, maximum force, and the radius for arrival behavior required careful adjustment to achieve a natural-looking pursuit.

Code Snippet

push();
    translate(this.pos.x, this.pos.y);
    rotate(this.vel.heading());
    noStroke();
    fill(0, 200, 0); // Color for bug spray
    rect(-8, -25, 16, 50); // Bug spray shape
    fill('yellow'); // Color for bug spray nozzle
    ellipse(0, -25, 16, 16); // Bug spray nozzle
    pop();

As seen in the above code, I used push and pop to make it simpler in creating the shapes for the code. I also used the rotate function to make the orientation of the bug spray to correspond to to the cockroach position.

Future Improvements

  1. Particle System: Enhance the spraying effect by adding a particle system to visually represent the spray dispersing.
  2. Obstacle Avoidance: Implement obstacle avoidance behaviors to make the bug spray navigate around obstacles on the canvas.

Leave a Reply

Your email address will not be published. Required fields are marked *