Commit a22b5842 authored by Max H's avatar Max H

Initial commit

parents
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/
<component name="libraryTable">
<library name="controlP5">
<CLASSES>
<root url="jar://$USER_HOME$/sketchbook/libraries/controlP5/library/controlP5.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="core">
<CLASSES>
<root url="jar:///usr/share/processing/core/library/core.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_13" default="false" project-jdk-name="14" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/project-one.iml" filepath="$PROJECT_DIR$/project-one.iml" />
</modules>
</component>
</project>
\ No newline at end of file
[
{
"name": "Pam Hart English",
"topic": "Founder,Project One,Main frame systems"
},
{
"name": "Lee Felsenstein",
"topic": "Commuity Memory,Project One"
},
{
"name": "Efrem Lipkin",
"topic": "Commuity Memory,Project One"
},
{
"name": "Jude Milhorn",
"topic": "Commuity Memory,Project One"
},
{
"name": "Chris Macie",
"topic": "Social Services Referral Directory,Project One,Founder"
},
{
"name": "Mary Janowitz",
"topic": "Social Services Referral Directory,Information Gathering,Project One"
},
{
"name": "Mya Shine",
"topic": "Social Services Referral Directory,Project One"
},
{
"name": "Sherry Reason",
"topic": "Social Services Referral Directory,Project One"
},
{
"name": "Joan Lefkowitz",
"topic": "Social Services Referral Directory,Project One"
},
{
"name": "Noname Marine",
"topic": "Child care taker,Project One"
},
{
"name": "Charles Raisch",
"topic": "Writer,Project One"
},
{
"name": "Mya Shine",
"topic": "Project One"
},
{
"name": "Chris Neustrup",
"topic": "Berkeley computer science student,Project One"
},
{
"name": "Grace Hopper",
"topic": "Main frame systems"
},
{
"name": "Betty Holberton",
"topic": "Main frame systems"
},
{
"name": "Jane Speiser",
"topic": "Project One"
},
{
"name": "Annie Liebowitz",
"topic": "Photographer,Project One"
},
{
"name": "Steward Brand",
"topic": "Writer,Project One"
},
{
"name": "Charlie Bolton",
"topic": "Organizer,Project One"
}
]
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="core" level="project" />
<orderEntry type="library" name="controlP5" level="project" />
</component>
</module>
\ No newline at end of file
import processing.core.PApplet;
import processing.core.PImage;
import processing.data.JSONArray;
import processing.data.JSONObject;
import processing.data.StringDict;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class ProjectOne extends PApplet {
// data
JSONArray protagonists;
StringDict topicsDict = new StringDict();
StringDict peopleDict = new StringDict();
StringDict keyvalDict = new StringDict();
// hover data
List<String> hoverTopics = new ArrayList<>();
List<String> hoverPerson = new ArrayList<>();
// state vars
boolean splashscreen = true;
boolean aboveEnterButton = false;
boolean initialised = false;
boolean hover = false;
boolean hoverBuffer = false;
// imgs
PImage imgPeople;
PImage imgMemory;
public static void main(String[] args) {
String[] processingArgs = {"ProjectOne"};
ProjectOne projectOne = new ProjectOne();
PApplet.runSketch(processingArgs, projectOne);
}
public void settings() {
size(1000, 1000);
// load json
protagonists = loadJSONArray("protagonists.json");
filterData();
// load images
imgPeople = loadImage("people.jpg");
imgMemory = loadImage("community-memory.jpg");
// calculate positions
calcTopicPos();
calcNamePos();
}
public void draw() {
// splashscreen
if (splashscreen) {
// draw image once
if (!initialised) {
image(imgMemory, 100, 0);
image(imgPeople, 365, 290, 260, 220);
textSize(35);
textAlign(CENTER);
rect(200, 50, 600, 100);
fill(0);
text("Enter project ones community memory\nby pressing the ON button", 500, 80);
textAlign(LEFT);
}
splashscreenHover();
initialised = true;
} else {
initialised = false;
}
// after splashscreen
if ((!initialised || (hover != hoverBuffer)) && !splashscreen) {
// reset canvas
background(255, 255, 255);
drawConnections();
drawTopics();
drawPeople();
textSize(35);
text("Project One Community Memory 2020", 230, 50);
initialised = true;
hoverBuffer = hover;
}
// check hover
if (hover()) {
hover = true;
hoverBuffer = false;
} else {
hover = false;
resetHover();
}
}
private void filterData() {
// get people and filter topics
for (int i = 0; i < protagonists.size(); i++) {
// get json object and data
JSONObject person = protagonists.getJSONObject(i);
String name = person.getString("name");
String topic = person.getString("topic");
// save person name in people StringDict
peopleDict.set(name, "0,0");
// save topics of individual person in StringDict
keyvalDict.set(name, topic);
// get topics of person
String[] topicList = split(topic, ',');
for (String s : topicList) {
// if topic is not in topic list create new topic
if (!topicsDict.hasKey(s)) {
// save topic with empty position
topicsDict.set(s, "0,0");
}
}
}
}
// calculations
private void calcTopicPos() {
String[] topicNames = topicsDict.keyArray();
int offset = 300, posX = 250, posY = 400;
for (int i = 0; i < topicNames.length; i++) {
// max. 3 topics per row
if (i % 2 == 0) {
posX = 250;
posY += 50;
}
// set position
topicsDict.set(topicNames[i], String.format("%s,%s", posX, posY));
// increase x
posX += offset;
}
}
private void calcNamePos() {
int circleCenterX = 450, circleCenterY = 550, radius = 420;
String[] peopleNames = peopleDict.keyArray();
for (int i = 0; i < peopleNames.length; i++) {
// Compute the angle around the circle
float angle = 2 * PI * i / peopleNames.length;
// Compute position
float x = circleCenterX + sin(angle) * radius;
float y = circleCenterY + cos(angle) * radius;
// set position
peopleDict.set(peopleNames[i], String.format("%s,%s", x, y));
}
}
// drawing
private void drawConnections() {
String[] persons = keyvalDict.keyArray();
for (String person : persons) {
// get topics of person
String[] topics = split(keyvalDict.get(person), ',');
// get position of person name
String[] namePos = split(peopleDict.get(person), ',');
float x1 = Float.parseFloat(namePos[0]), y1 = Float.parseFloat(namePos[1]);
for (String topic : topics) {
String[] topicPos = split(topicsDict.get(topic), ',');
float x2 = Float.parseFloat(topicPos[0]), y2 = Float.parseFloat(topicPos[1]);
// hover?
if (hoverTopics.contains(topic) || hoverPerson.contains(person)) {
stroke(255, 0, 0);
}
line(x1, y1, x2, y2);
// reset stroke
stroke(126);
}
}
}
private void drawTopics() {
// draw topic names in the middle of canvas
String[] topicNames = topicsDict.keyArray();
for (String topicName : topicNames) {
// get pos
String[] topicPos = split(topicsDict.get(topicName), ',');
float x = Float.parseFloat(topicPos[0]), y = Float.parseFloat(topicPos[1]);
// draw box
// hover?
if (hoverTopics.contains(topicName)) {
fill(0);
} else {
fill(255);
}
// border box
rect(x - 5, y - 20, 50 + topicName.length() * 7, 30, 7);
// info box
rect(x - 18, y - 26, 16, 16);
// draw topic title
textSize(18);
fill(0, 102, 153);
text(topicName, x, y);
text("i", x - 12, y - 12);
}
}
private void drawPeople() {
String[] peopleNames = peopleDict.keyArray();
for (String person : peopleNames) {
// get pos
String[] namePos = split(peopleDict.get(person), ',');
float x = Float.parseFloat(namePos[0]), y = Float.parseFloat(namePos[1]);
// draw box
// hover?
if (hoverPerson.contains(person)) {
fill(255);
} else {
fill(0);
}
// border box
rect(x - 10, y - 20, 140, 30, 7);
// info box
rect(x - 18, y - 26, 16, 16);
// draw name and info icon
fill(255, 102, 153);
textSize(18);
text(person, x, y);
text("i", x - 12, y - 12);
}
}
// hover
private void resetHover() {
hoverTopics = new ArrayList<>();
hoverPerson = new ArrayList<>();
}
private void splashscreenHover() {
int offset = 25, x = 727, y = 364;
if (dist(mouseX, mouseY, x, y) < offset) {
fill(255, 50, 0);
aboveEnterButton = true;
} else {
aboveEnterButton = false;
fill(255, 0, 0);
}
circle(x, y, 50);
fill(0);
textSize(25);
text("ON", x - 18, y + 10);
}
private boolean hover() {
int offset = 25;
resetHover();
// check for hover over person name
String[] peopleNames = peopleDict.keyArray();
for (String person : peopleNames) {
// get pos
String[] personPos = split(peopleDict.get(person), ',');
float x = Float.parseFloat(personPos[0]), y = Float.parseFloat(personPos[1]);
if (dist(mouseX, mouseY, x, y) < offset) {
// get topic
hoverTopics = Arrays.asList(split(keyvalDict.get(person), ','));
hoverPerson.add(person);
return true;
}
}
// check for topic hover
String[] topicNames = topicsDict.keyArray();
for (String topic : topicNames) {
// get pos
String[] topicPos = split(topicsDict.get(topic), ',');
float x = Float.parseFloat(topicPos[0]), y = Float.parseFloat(topicPos[1]);
if (dist(mouseX, mouseY, x, y) < offset) {
hoverTopics.add(topic);
// check for people at this topic
for (String person : peopleNames) {
String[] personTopics = split(keyvalDict.get(person), ',');
if (Arrays.asList(personTopics).contains(topic)) {
hoverPerson.add(person);
}
}
return true;
}
}
return false;
}
public void mousePressed() {
// if in splashscreen mode check button click
if (splashscreen) {
if (aboveEnterButton) {
splashscreen = false;
}
return;
}
if (hoverPerson.size() != 0) {
for (String person : hoverPerson) {
String url = "https://www.google.com/search?q=" + person + "+resource+one";
// replace "space" with "plus" for url encoding
url = url.replaceAll(" ", "+").toLowerCase();
link(url);
}
}
}
}
[
{
"name": "Pam Hart English",
"topic": "Founder,Project One,Main frame systems"
},
{
"name": "Lee Felsenstein",
"topic": "Commuity Memory,Project One"
},
{
"name": "Efrem Lipkin",
"topic": "Commuity Memory,Project One"
},
{
"name": "Jude Milhorn",
"topic": "Commuity Memory,Project One"
},
{
"name": "Chris Macie",
"topic": "Social Services Referral Directory,Project One,Founder"
},
{
"name": "Mary Janowitz",
"topic": "Social Services Referral Directory,Information Gathering,Project One"
},
{
"name": "Mya Shine",
"topic": "Social Services Referral Directory,Project One"
},
{
"name": "Sherry Reason",
"topic": "Social Services Referral Directory,Project One"
},
{
"name": "Joan Lefkowitz",
"topic": "Social Services Referral Directory,Project One"
},
{
"name": "Noname Marine",
"topic": "Child care taker,Project One"
},
{
"name": "Charles Raisch",
"topic": "Writer,Project One"
},
{
"name": "Mya Shine",
"topic": "Project One"
},
{
"name": "Chris Neustrup",
"topic": "Berkeley computer science student,Project One"
},
{
"name": "Grace Hopper",
"topic": "Main frame systems"
},
{
"name": "Betty Holberton",
"topic": "Main frame systems"
},
{
"name": "Jane Speiser",
"topic": "Project One"
},
{
"name": "Annie Liebowitz",
"topic": "Photographer,Project One"
},
{
"name": "Steward Brand",
"topic": "Writer,Project One"
},
{
"name": "Charlie Bolton",
"topic": "Organizer,Project One"
}
]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment