Simple editor to create custom node network graphs aka ontologies
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. int linkCount;
  2. boolean dragLink; //state of dragging a link
  3. int dragOriginLet = 0; //dragging from inlet: -1. dragging from outlet: 1.
  4. int dragOriginId = -1; //which nodes out- / inlet did user click on?
  5. void Link(int parentNode, int targetNode) {
  6. /**
  7. * Check if user is adding or removing a link
  8. */
  9. int exists = -1;
  10. for (int i = 0; i < linkCount; i++) {
  11. if (links[i].parentNode == parentNode && links[i].targetNode == targetNode) {
  12. exists = i;
  13. break;
  14. }
  15. }
  16. if (exists != -1) {
  17. /**
  18. * !active state is pretty much the same as deleted state that the node-class comes with
  19. */
  20. links[exists].active = !links[exists].active;
  21. } else {
  22. links[linkCount] = new Link(parentNode, targetNode);
  23. linkCount++;
  24. }
  25. }
  26. class Link {
  27. int parentNode, targetNode;
  28. boolean active;
  29. PVector link = new PVector(0, 0);
  30. Link(int parentNode_, int targetNode_) {
  31. parentNode = parentNode_;
  32. targetNode = targetNode_;
  33. active = true;
  34. }
  35. /**
  36. * This could be an event that only gets called when nodes are moved or resized.
  37. */
  38. void update() {
  39. link.x = nodes[targetNode].inletCenter.x - nodes[parentNode].outletCenter.x;
  40. link.y = nodes[targetNode].inletCenter.y - nodes[parentNode].outletCenter.y;
  41. }
  42. void display() {
  43. stroke(darkMode? 255 : 0);
  44. strokeWeight(2);
  45. pushMatrix();
  46. translate(nodes[parentNode].outletCenter.x, nodes[parentNode].outletCenter.y);
  47. line(0, 0, link.x, link.y);
  48. translate(-nodes[parentNode].outletCenter.x+(nodes[parentNode].outletCenter.x+nodes[targetNode].inletCenter.x)/2, -nodes[parentNode].outletCenter.y+(nodes[parentNode].outletCenter.y+nodes[targetNode].inletCenter.y)/2);
  49. rotate(link.heading());
  50. fill(darkMode? 0 : 255);
  51. triangle(0, textSize/2, textSize, 0, 0, -textSize/2);
  52. popMatrix();
  53. }
  54. }