Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


                <script type="application/processing">
Flocker[] flock = new Flocker[3];

void setup() {
  size(200, 200);

  for (int i = 0; i < flock.length; i++) {
    flock[i] = new Flocker();

void draw() {


  for (int i = 0; i < flock.length; i++) {

class Flocker {

  float x = random(width);
  float y = random(height);
  float heading = random(TWO_PI);
  float speed = random(1, 3); 
  float radius = random(10, 20);

  void step() {

    //find the closest Flocker
    float closestDistance = 100000;
    Flocker closestFlocker = null;
    for (int i = 0; i < flock.length; i++) {
      //make sure not to check against yourself
      if (flock[i] != this) {
        float distance = dist(x, y, flock[i].x, flock[i].y);
        if (distance < closestDistance) {
          closestDistance = distance;
          closestFlocker = flock[i];

    float angleToClosest = atan2(closestFlocker.y-y, closestFlocker.x-x);

    //prevent case where heading is 350 and angleToClosest is 10
    if (heading-angleToClosest > PI) {
      angleToClosest += TWO_PI;
    } else if (angleToClosest-heading > PI) {
      angleToClosest -= TWO_PI;

    //turn towards closest
    if (heading < angleToClosest) {
    } else {

    //move in direction
    x += cos(heading)*speed;
    y += sin(heading)*speed;

    //wrap around edges
    if (x < 0) {
      x = width;
    if (x > width) {
      x = 0;

    if (y < 0) {
      y = height;
    if (y > height) {
      y = 0;

  void draw() {
    ellipse(x, y, radius, radius);
<canvas> </canvas>