Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ArrayList<Concept> concepts;
Concept activeConcept;
import processing.video.*;
void movieEvent(Movie m) {
m.read();
}
Movie mov;
void loadConcepts() {
concepts = new ArrayList();
String[] catalogue = loadStrings("https://docs.google.com/spreadsheets/d/17Czz_pRZAxHClsk0j7fPaRk55Hf-9Wnyllris60FP50/pub?output=tsv" ); // TAB SEPARATED (TSV FILE) for (int i=1; i<catalogue.length; i++) { String row = catalogue[i]; String[] columns = splitTokens(row, "\t"); if (columns.length > 7) { Concept newConcept = new Concept(columns[0], columns[1], columns[2], columns[4], columns[5], columns[6], columns[7]);
concepts.add(newConcept);
} else {
Concept newConcept = new Concept(columns[0], columns[1], columns[2], columns[4], columns[5], "", "");
concepts.add(newConcept);
}
} //mov = new Movie(this, "mov/MECHANICAL.mov"); }
Concept findConceptByName(String thisName) {
for (Concept concept : concepts) {
if (concept.name.equals(thisName)) return concept;
}
println(thisName+" not found");
return null;
}
void makeActive(Concept thisConcept) {
activeConcept.active = false;
activeConcept = thisConcept;
thisConcept.active = true;
thisConcept.startTime = millis();
}
class Concept {
long startTime;
PVector location = new PVector(0, 0);
float s = 1, targetS;
String name, noun, adjective, content, imageName;
ArrayList<Concept> attractors = new ArrayList();
ArrayList<Concept> repulsors = new ArrayList();
Particle particle;
PImage img;
// String noun, adjective; boolean over, active, visible;
String attractorsString, repulsorsString;
Concept(String name, String attractor, String repulsor, String noun, String adjective, String content, String imageName) {
name = name;
attractorsString = attractor;
repulsorsString = repulsor;
noun = noun;
adjective = adjective;
content = content;
imageName = imageName;
init();
//imageName= ("TOOL.jpg");
if (imageName != "" && !imageName.equals("blank.jpeg")) {
img = loadImage("data/img/"+imageName);
visible = true;
}
}
void init() {
location = new PVector(100+random(width-200), 100+random(height-200));
if (particle != null) {
physics.removeParticle(particle);
}
particle = createParticle(location);
}
void createSprings() {
attractors = new ArrayList();
repulsors = new ArrayList();
String[] attractorNames = splitTokens(attractorsString, ",");
String[] repulsorNames = splitTokens(repulsorsString, ",");
for (int i=0; i<attractorNames.length; i++) {
attractorNames[i] = removeSpaces(attractorNames[i]);
Concept attractor = findConceptByName(attractorNames[i]);
boolean flag = false;
for (Concept thisAttractor : attractor.attractors) {
if (thisAttractor == this) {
flag = true; // println("found redundant attractor "+attractor.name+" TO "+thisAttractor.name); } } if (!flag) attractors.add(attractor); } for (int i=0; i<repulsorNames.length; i++) { repulsorNames[i] = removeSpaces(repulsorNames[i]); Concept repulsor = findConceptByName(repulsorNames[i]); boolean flag = false; for (Concept thisRepulsor : repulsor.repulsors) { if (thisRepulsor == this) { flag = true; // println("found redundant repulsor "+repulsor.name+" TO "+thisRepulsor.name); } } if (!flag) repulsors.add(repulsor); } }
void display() {
location.x = particle.x;
location.y = particle.y;
over = (dist(mouseX, mouseY, location.x, location.y) < 20);
if (over && clicked) {
if (activeConcept != null) activeConcept.active = false;
activeConcept = this;
active = true;
clicked = false;
startTime = millis();
}
if (!over && clicked && activeConcept == this) {
activeConcept = null;
active = false;
for (Concept concept : concepts) {
concept.visible = true;
}
}
if (activeConcept == this) {
for (Concept concept : concepts) {
concept.visible = false;
}
for (Concept concept : attractors) {
concept.visible = true;
}
for (Concept concept : repulsors) {
concept.visible = true;
}
visible = true;
//image(img, location.x, location.y);
if (millis() - startTime > 19000) {
makeActive( attractors.get((int)random(attractors.size())));
}
}
targetS = active ? 5 : 1; //////click:orignal
s = attract ( s, targetS, .001, .001);
if (visible) {
pushMatrix();
translate(location.x, location.y);
if (img != null && active) {
pushMatrix();
//scale(s);
tint(255);
image(img, 0, 0); //////////// content
popMatrix();
}
if (mov != null && active) {
image(mov, 0, 0); //////////// video
mov.volume(0);
//mov.resize(200, 0);
tint(0, 0, 255);
mov.loop();
}
fill(255, 255, 255);
textFont(mainFont);
textAlign(CENTER, CENTER);
pushMatrix();
//pushMatrix();
//scale(s);
textSize(12);
text(noun, 0, 0, 255, 255); //////////// noun
//popMatrix();
//fill(0, 0, 255,255);
//text(adjective, 100, 50); //////////// adjective
popMatrix();
if (content != null && active) {
textAlign(LEFT);
translate(-200, 75, 20);
fill(255, 255, 255);
textFont(subFont);
textSize(30);
textLeading(70);
text(breakLine(content, 20), 0, 0); //////////// content///88 character length
}
popMatrix();
}
}
}
String breakLine(String str, int l) {
String result = "";
int counter = 0;
for (int i=0; i<str.length(); i++) {
if (counter > l && str.charAt(i) == ' ') {
result += "\n";
counter = 0;
} else {
result += str.charAt(i);
counter++;
}
} // println(result);
return result;
}
float attract(float val, float target, float ratio, float snap) {
return val + ((target-val)*ratio);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.