A simple graphing program using Processing

A little while ago I was playing with some sensors I had, and though how nice it’d be if I could graph their outputs on my computer. So I wrote a simple program in the Processing language to do just that. Although the code I wrote was able to get strings of data from my Arduino, the code I am posting here is somewhat stripped out to be as understandable as possible to beginners. Instead of displaying data from sensors, this program graphs your mouse’s x- and y-coordinates. It is still capable of plotting data from sensors, but you’ll have to write the code to fetch and handle the data. As is explained in the comments in the code, there are three variables (integers) to store incoming data points (newDataPoint1, newDataPoint2 and newDataPoint3), each of which corresponds to one of the graphs. Your data-handling code will have to feed each of these variables one new integer each iteration of the draw loop in order for this program to function properly. Currently, newDataPoint1 and newDataPoint2 are being set to the mouse’s x- and y-coordinate respectively and newDataPoint3 is just set to “0” (not being used). Thus for users with a little experience with Processing it should be quite easy to modify this code to your needs.

Here’s what it looks like (the blue line at the top is the third graph which is currently not being used):

Continuous Graph

Before you can run my code, you’ll have to download and install Processing. Once you have done that, you can download my code here.



2 thoughts on “A simple graphing program using Processing

  1. Hi, I saw your code..I need your help with my problem..So my problem is that there two balls colliding and I want their potential energies to be plotted with their positions respectively(a simple classical problem which is easily done manually). I have written the code for the two balls colliding..
    float circleX1;
    float circleX2;
    float xspeed1 = 2;
    float xspeed2 = 2;
    void setup(){
    circleX1 = 12;
    circleX2 = 500;

    void draw(){

    circleX1 = circleX1 + xspeed1;
    circleX2 = circleX2 – xspeed2;

    if(circleX1 == circleX2-24){
    xspeed1 = xspeed1* -1;
    xspeed2 = xspeed2* -1;
    if(circleX1 width-12){
    xspeed2 = xspeed2* -1;

    this is a simple code,the speeds are not changing here..I have a different code for that.
    please revert.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s