Loading...
Logo
Processing Forum

I am creating step by step Processing code examples to introduce novice programmers to object oriented programming. I have written a number of examples where the code for a Circle class is in a separate tab from the main programme. The idea is for students to use the appropriate methods from the class code but without being able to see the underlying code - i.e. to be introduced to the use of objects of the class without worrying about the implementation code. As it stands inquisitive students can click on the Circle tab and see the code. This is fine for students ready to move on to it but might dismay their slower colleagues. My intention was to compile it and add it as a library. I have spent some time trying various approaches but I think maybe I don't understand the use of jar files etc.

Could anyone point me in the right direction?

I attach the code for my first example to illustrate

Thanks in advance!

Ken Brownsey

// Main

Circle C = new Circle(200, 300, 50, 0, 0, 0);

void setup() {

size(500, 500);

C.Draw();

}

 

 

// Circle class in separate tab

 

class Circle {

int Cx,

Cy;

int dx,

dy;

int D;

color FillCol;

Circle(int Cx, int Cy, int D, color FillCol, int dx, int dy) {

this.Cx = Cx;

this.Cy = Cy;

this.dx = dx;

this.dy = dy;

this.D = D;

this.FillCol = FillCol;

}

// PRE TRUE

// POST Circle drawn on canvas

void Draw() {

fill(FillCol);

ellipse(Cx, Cy, D, D);

}

// PRE TRUE

// POST Moves this (dx, dy)

void Move() {

Cx += dx;

Cy += dy;

}

}

 

 

 

Replies(4)

Making a library out of your code might be the right way to go.
We don't know what are your " various approaches " so it is hard to advise without repeating the info you might already have seen.
Have you read the tutorial on making libraries? You might need to use Eclipse to make your library.

An alternative is to obfuscate the code, but it is some work to do it properly...
Have you tried compiling your code and making an executable?
@ekapalka,

 it's not really clear how 

Have you tried compiling your code and making an executable?
 
may help to hide the class implementation from students. But if you were suggesting that exported executable can be used as library, this is not the case. As your tabs are inner classes, they won't be visible to outside client.

I've also been thinking of possibility to hide certain complexity inside of processing library, but the workflow to make library has always been a bit complicated, especially for the beginner: setting up eclipse, numerous imports and so on.

So finally I came up with a simple way to do that. All you have to do: just download zip-template and after copying couple of files (2-3 minutes of tutorial), you can compile your first library. 


I started making videos to explain how to use this template, so here's the list:

Simpliest way to make your Processing 2 library

This is link to the "simplicity" library-template (it has Windows .bat-scripts set up to help you automatically compile the library). Just hit "download ZIP".