Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.6.1 Release #51

Merged
merged 19 commits into from
Aug 30, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .classpath
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry excluding="**/.svn/*" kind="src" path="src"/>
<classpathentry excluding="**/.svn/*" kind="src" path="ideExample"/>
<classpathentry excluding="**/.svn/*" kind="src" path="test"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="ideExample"/>
<classpathentry kind="src" path="test"/>
<classpathentry kind="lib" path="lib/processing/core.jar"/>
<classpathentry kind="lib" path="lib/junit/junit-4.8.2.jar"/>
<classpathentry kind="lib" path="lib/mockito-all-1.8.5.jar"/>
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
bin
build
build.json
target
target
*.swp
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ruby-1.9.3-p429
ruby-2.1.2
14 changes: 8 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
GEM
remote: https://rubygems.org/
specs:
aws-sdk (1.8.3.1)
aws-sdk (1.52.0)
aws-sdk-v1 (= 1.52.0)
aws-sdk-v1 (1.52.0)
json (~> 1.4)
nokogiri (>= 1.4.4)
uuidtools (~> 2.1)
json (1.7.3)
nokogiri (1.5.6)
rake (0.9.2.2)
uuidtools (2.1.3)
json (1.8.1)
mini_portile (0.6.0)
nokogiri (1.6.3.1)
mini_portile (= 0.6.0)
rake (10.3.2)

PLATFORMS
ruby
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.6.0
0.6.1
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ void report() {
Word word = words[i];
if (word.wasSkipped()) {

int skipReason = word.wasSkippedBecause().intValue();
WordSkipReason skipReason = word.wasSkippedBecause();

switch(skipReason) {
case WordCram.WAS_OVER_MAX_NUMBER_OF_WORDS:
case WAS_OVER_MAX_NUMBER_OF_WORDS:
tooMany++;
break;
case WordCram.SHAPE_WAS_TOO_SMALL:
case SHAPE_WAS_TOO_SMALL:
tooSmall++;
break;
case WordCram.NO_SPACE:
case NO_SPACE:
couldNotPlace++;
break;
}
Expand Down
2 changes: 2 additions & 0 deletions example/OtherExamples/renderToPdf/renderToPdf.pde
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ void setup() {
.minShapeSize(1)
.withWordPadding(1)
.drawAll();

println("Done! Open usconst.pdf to see the results.");

exit();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import wordcram.*;

void setup() {
size(1000, 500);
smooth();
background(255);

new WordCram(this)
.fromTextFile("../kari-the-elephant.txt")
.drawAll();
}

void wordsCounted(Word[] words) {
println("counted " + words.length + " words!");
}

void beginDraw() {
println("beginDraw: drawing the sketch...");
}

int wordsDrawn = 0;
void wordDrawn(Word word) {
wordsDrawn++;
}

int wordsSkipped = 0;
void wordSkipped(Word word) {
wordsSkipped++;
}

void endDraw() {
println("endDraw!");
println("- skipped: " + wordsSkipped);
println("- drawn: " + wordsDrawn);
}

2 changes: 1 addition & 1 deletion example/tutorial/K_howDidItGo/K_howDidItGo.pde
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void setup() {
if (word.wasSkipped()) {
println(word.word + " was skipped!");

if (word.wasSkippedBecause() == WordCram.NO_SPACE) {
if (word.wasSkippedBecause() == WordSkipReason.NO_SPACE) {
println(word.word + " was skipped because there was no room");
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import wordcram.*;
import java.awt.*;

void setup() {
PImage image = loadImage("../heart.png");
size(image.width, image.height);

background(128);

Shape imageShape = new ImageShaper().shape(image, #000000);
ShapeBasedPlacer placer = new ShapeBasedPlacer(imageShape);

new WordCram(this).
fromTextFile("../kari-the-elephant.txt").
withPlacer(placer).
withNudger(placer).
sizedByWeight(7, 40).
withColor(#ffffff).
drawAll();


imageShape = new ImageShaper().shape(image, #ffffff);
placer = new ShapeBasedPlacer(imageShape);

new WordCram(this).
fromTextFile("../kari-the-elephant.txt").
withPlacer(placer).
withNudger(placer).
sizedByWeight(7, 40).
withColor(#000000).
drawAll();
}

Binary file added example/tutorial/heart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
141 changes: 141 additions & 0 deletions src/wordcram/PlacerHeatMap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package wordcram;

import java.awt.Color;
import java.awt.Shape;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.HashMap;

import processing.core.PApplet;
import processing.core.PFont;
import processing.core.PGraphics;
import processing.core.PGraphicsJava2D;
import processing.core.PVector;

public class PlacerHeatMap {

private Word[] words;
private WordFonter fonter;
private WordSizer sizer;
private WordAngler angler;
private WordPlacer placer;
private WordNudger nudger;
private WordShaper shaper;

PlacerHeatMap(Word[] words, WordFonter fonter, WordSizer sizer, WordAngler angler, WordPlacer placer, WordNudger nudger, WordShaper shaper) {

this.fonter = fonter;
this.sizer = sizer;
this.angler = angler;
this.placer = placer;
this.nudger = nudger;
this.shaper = shaper;
this.words = words;
}

class RectStack {
ArrayList<Rectangle2D> rects = new ArrayList<Rectangle2D>();

void add(int x, int y, int w, int h) {
rects.add(new Rectangle2D.Float(x, y, w, h));
}

int howManyIntersect(int x, int y, int w, int h) {
int sum = 0;

for (Rectangle2D r : rects) {
if (r.intersects(x, y, w, h)) {
sum++;
}
}

return sum;
}
}

class RectGrid {
RectStack stack;
HashMap<Rectangle2D, Integer> levels = new HashMap<Rectangle2D, Integer>();

RectGrid(RectStack stack) {
this.stack = stack;
}

void measure(int x, int y, int w, int h) {
Rectangle2D plot = new Rectangle2D.Float(x, y, w, h);
int level = stack.howManyIntersect(x, y, w, h);
levels.put(plot, level);
}

int maxLevel() {
int maxLevel = 0;
for (Integer level : levels.values()) {
if (level > maxLevel) {
maxLevel = level;
}
}
return maxLevel;
}

void draw(PApplet sketch) {
int rowHeight = 10;
int colWidth = 10;
int rows = (int)(sketch.height / (float)rowHeight);
int cols = (int)(sketch.width / (float)colWidth);

for (int i = 0; i < rows; i++) {
int y = i * rowHeight;
for (int j = 0; j < cols; j++) {
int x = j * colWidth;

measure(x, y, colWidth, rowHeight);
}
}

sketch.colorMode(PApplet.HSB);

int max = maxLevel();
for (Rectangle2D rect : levels.keySet()) {
Integer level = levels.get(rect);

int c = sketch.color(0);
if (level > 0) {
float scaled = (float)level / 8;
int hue = (int)PApplet.map(scaled, 0, 1, 85, 0); // 85 = pure green
c = sketch.color(hue, 255, 255);
}

sketch.fill(c);
sketch.rect((float)rect.getX(), (float)rect.getY(), (float)rect.getWidth(), (float)rect.getHeight());
}
}
}

public void draw(PApplet sketch) {
RectStack rectStack = new RectStack();

for (int i = 0; i < words.length; i++) {
Word word = words[i];
PFont wordFont = word.getFont(fonter);
float wordSize = word.getSize(sizer, i, words.length);
float wordAngle = word.getAngle(angler);

Shape shape = shaper.getShapeFor(word.word, wordFont, wordSize, wordAngle);
Rectangle2D rect = shape.getBounds2D();
//return r.getHeight() < minShapeSize || r.getWidth() < minShapeSize;

int wordImageWidth = (int)rect.getWidth();
int wordImageHeight = (int)rect.getHeight();

PVector desiredLocation = word.getTargetPlace(placer, i, words.length,
wordImageWidth, wordImageHeight, sketch.width, sketch.height);

//sketch.rect(desiredLocation.x, desiredLocation.y, wordImageWidth, wordImageHeight);
rectStack.add((int)desiredLocation.x, (int)desiredLocation.y,
wordImageWidth, wordImageHeight);
}

RectGrid grid = new RectGrid(rectStack);
grid.draw(sketch);
}
}
7 changes: 2 additions & 5 deletions src/wordcram/ShapeBasedPlacer.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ public ShapeBasedPlacer(Shape shape) {
public PVector place(Word w, int rank, int count, int ww, int wh, int fw,
int fh) {

w.setProperty("width", ww);
w.setProperty("height", wh);

for (int i = 0; i < 1000; i++) {
float newX = randomBetween(minX, maxX);
float newY = randomBetween(minY, maxY);
Expand All @@ -46,8 +43,8 @@ public PVector nudgeFor(Word word, int attempt) {
PVector target = word.getTargetPlace();
float wx = target.x;
float wy = target.y;
float ww = (Integer) word.getProperty("width");
float wh = (Integer) word.getProperty("height");
float ww = word.getRenderedWidth();
float wh = word.getRenderedHeight();

for (int i = 0; i < 1000; i++) {
float newX = randomBetween(minX, maxX);
Expand Down
Loading