Carl Vitasa | Gameplay Programmer

Carl Vitasa - Gameplay Programmer Portfolio

NEURONS



Code

# clike
/*  Neurons v1.0
 *  Carl Vitasa
 *  11/26/15
 *
 */

int total = 300;
int lineRange = 30;
ArrayList<Ball> ballList = new ArrayList<Ball>(); 

void setup() 
{
  size (600, 600);
  smooth (8);
  frameRate (60);

  for (int i=0; i<total; i++)
  {
    ballList.add(new Ball((random(100, width-100)),(random(100, height-100)), (random(1.0, 5.0))));
  }
}

void draw() 
{
  background (#272727);
  for (int i=0; i<ballList.size(); i++)
  {
    Ball b = ballList.get(i);
    b.move();
    b.display();
    for (int o=1; o<ballList.size(); o++)
    {
      Ball b2 = ballList.get(o);
      if (abs((b.xPos - b2.xPos)) < lineRange && abs((b.yPos - b2.yPos)) < lineRange)
      {
        strokeWeight(int(1));
        stroke(lerpColor (#99FF99, #009933, random(1)));
        line(b.xPos, b.yPos, b2.xPos, b2.yPos);
      }
    }
  }
}

class Ball
{
  float theta = 0;
  float speed;
  float r = 75;
  float x, y;
  float xOffSet, yOffSet;
  float xPos, yPos;
  int clockWise;

  Ball(float _xOffSet, float _yOffSet, float _speed)
  {
    this.xOffSet = _xOffSet;
    this.yOffSet = _yOffSet;
    this.speed = _speed/100;
    clockWise = int(random(2));
  }

  void display()
  {
    fill (#00FF00);
    noStroke();
    ellipse(xPos, yPos, 3, 3);
  }

  void move()
  {
    xPos = x + xOffSet;
    yPos = y + yOffSet;
    x = r * cos(theta);
    y = r * sin(theta);
    
    if (clockWise == 1)
    {
      theta += speed;
    }
    else 
    {
      theta -= speed;
    }
  }
}

Created with the help from "The Nature of Code" book.

Inspired by the Experiments in Processing Tumblr post


Wallpaper (1920 x 1080)
made in Photoshop

© Carl Vitasa, All rights reserved.