May 5
Concept Map in Processing Library
This code makes a Concept Map with the Processing library / Java. Processing library makes it easy and quick to make graphical representations and animations, among its many features.
/**
* setup is called implicitly by the library when rdraw is called
* it sets the size, drawing method, then in this case draws the graph
*/
public void setup() {
size(boxSize,boxSize);
smooth();
drawGraph();
}
/**
* Draws the graph. req and neighbors must have been
* previously set through the construtor or the setters
*/
public void drawGraph()
{
int halfBox= 150;
//processing uses radians, not degrees
float angle = 2*PI / neighbors.size();
for(int i = 0; i < neighbors.size(); i++)
{
float cur_angle = i*angle;
String s = neighbors.get(i);
//calculate an even dispersal around the central objet
//it depends on how many objects are in your list
float xpos = halfBox*cos(cur_angle)+center;
float ypos = halfBox*sin(cur_angle)+center;
//color=black, draw a line to new item
stroke(0);
line(center,center, xpos,ypos);
//put the item last, on top of the lines
drawCircle(xpos, ypos, s);
}
//put the item last, on top of the lines
drawCircle(center,center,result);
}
/**
* draws a circle with specified text at (x,y)
* @param x the x position of where the circle will go
* @param y the y position of where the circle will go
* @param word the word that will go in the middle of the circle
*/
public void drawCircle(float x, float y, String word)
{
fill(255);
ellipse(x,y,word.length()*10, 40);
fill(0, 102, 153);
textAlign(CENTER);
text(word,x,y);
}
/**
* Makes a graph with req in the middle, surrounded
* by neighbors n. calls the library's super, Papplet.main
*/
public void rdraw(String req, ArrayList<String> n)
{
result = req;
neighbors = n;
PApplet.main(new String[] { "--bgcolor=#ECE9D8", "BrainH.client.ConceptMap" });
}
Compete Source here [ConceptMap.java].
/**
*
*/
private static final long serialVersionUID = 690002409249816629L;
private int boxSize = 500;
private int center = boxSize / 2;
private static String result = “”;
private static ArrayList<String> neighbors = null;
public ConceptMap() {};
public ConceptMap(String req, ArrayList<String> n)
{
result = req;
neighbors = n;
}
/**
* setup is called implicitly by the library when rdraw is called
* it sets the size, drawing method, then in this case draws the graph
*/
public void setup() {
size(boxSize,boxSize);
smooth();
drawGraph();
}
public void setNeighbors(ArrayList<String> arg)
{
neighbors = arg;
}
public void setObject(String req)
{
result = req;
}
/**
* Draws the graph. req and neighbors must have been
* previously set through the construtor or the setters
*/
public void drawGraph()
{
int halfBox= 150;
//processing uses radians, not degrees
float angle = 2*PI / neighbors.size();
for(int i = 0; i < neighbors.size(); i++)
{
float cur_angle = i*angle;
String s = neighbors.get(i);
//calculate an even dispersal around the central objet
//it depends on how many objects are in your list
float xpos = halfBox*cos(cur_angle)+center;
float ypos = halfBox*sin(cur_angle)+center;
//color=black, draw a line to new item
stroke(0);
line(center,center, xpos,ypos);
//put the item last, on top of the lines
drawCircle(xpos, ypos, s);
}
//put the item last, on top of the lines
drawCircle(center,center,result);
}
/**
* draws a circle with specified text at (x,y)
* @param x the x position of where the circle will go
* @param y the y position of where the circle will go
* @param word the word that will go in the middle of the circle
*/
public void drawCircle(float x, float y, String word)
{
fill(255);
ellipse(x,y,word.length()*10, 40);
fill(0, 102, 153);
textAlign(CENTER);
text(word,x,y);
}
/**
* Makes a graph with req in the middle, surrounded
* by neighbors n. calls the library’s super, Papplet.main
*/
public void rdraw(String req, ArrayList<String> n)
{
result = req;
neighbors = n;
PApplet.main(new String[] { “–bgcolor=#ECE9D8″, “BrainH.client.ConceptMap” });
}
}
No Comments
Leave a comment
