How to output to PNG with WordCram 1.0.0, Processing 3.2, and a shape with distinct crams

152 views
Skip to first unread message

blacks...@gmail.com

unread,
Aug 18, 2016, 11:40:34 AM8/18/16
to WordCram
For a while I have been able to make WordCrams pretty happily using the following code format:

import wordcram.*;
import java.awt.*;

import java.util.ArrayList;
import java.util.List;

void setup() {

PImage image = loadImage("../templates/HEART.png");

size(image.width, image.height);
background(#ffffff);

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

new WordCram(this).
fromWords(new Word[] { (WORDS GO HERE!)).
withPlacer(placer).
withNudger(placer).
sizedByWeight(1, 200).
angledAt(radians(0),radians(90),radians(-90)).
minShapeSize(0).
drawAll();
save("../OUTPUT.png");
exit();
}

This works fine, BUT I have decided to have a go recently both at using the new version of both WordCram and Processing and also making some more controlled WordCrams.

Just to start off, I am trying to replicate the "yin-yang" example. I can get the sketch to come up, but I do not seem to be able to work out how to output to PNG... Just putting save() on the end doesn't seem to work anymore, presumably because there are 2 separate "new WordCram(this)..." incidences.

My code as it stands, not outputting to PNG as I would like, is as follows:

import java.io.FileNotFoundException;
import java.util.*;

import processing.core.PApplet;
import processing.pdf.*;
import wordcram.*;
import wordcram.text.*;
import java.awt.*;

void setup() {
  size(600, 600);
  background(255);

  initWordCram();
}

void initWordCram() {
  PImage image = loadImage("yin-yang.png");
  image.resize(width, height);
  
  Shape imageShape = new ImageShaper().shape(image, #000000);
  ShapeBasedPlacer placer = new ShapeBasedPlacer(imageShape);

  new WordCram(this).
    fromWords(repeatWord("flexible", 500)).
    withPlacer(placer).
    withNudger(placer).
    sizedByWeight(4, 40).
    angledAt(0).
    withColor(#F5B502).
    drawAll();
    
  imageShape = new ImageShaper().shape(image, #ffffff);
  placer = new ShapeBasedPlacer(imageShape);
  
  new WordCram(this).
    fromWords(repeatWord("usable", 500)).
    withPlacer(placer).
    withNudger(placer).
    sizedByWeight(4, 40).
    angledAt(0).
    withColor(#782CAF).
    drawAll();
    
    save("OUTPUT.png");
}

Word[] repeatWord(String word, int times) {
  Word[] words = new Word[times];
  for (int i = 0; i < words.length; i++) {
    // Give the words a random weight, so they're sized differently.
    words[i] = new Word(word, random(1));
  }
  return words;
}

Can anyone explain to me why this doesn't work, and how to make it work?

Thanks in advance...

Dan Bernier

unread,
Aug 18, 2016, 3:07:03 PM8/18/16
to blacks...@gmail.com, WordCram

Using save("output.png") should still work just fine…what are you seeing?


--
You received this message because you are subscribed to the Google Groups "WordCram" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wordcram+unsubscribe@googlegroups.com.
To post to this group, send email to word...@googlegroups.com.



--

blacks...@gmail.com

unread,
Aug 19, 2016, 5:33:58 AM8/19/16
to WordCram, blacks...@gmail.com
The sketch comes up and appears to complete, however no file is actually saved. I'm not sure if it is saving to another location but I have looked in both the Processing folder and the sketchbook folder and no file is there.
To unsubscribe from this group and stop receiving emails from it, send an email to wordcram+u...@googlegroups.com.

To post to this group, send email to word...@googlegroups.com.

blacks...@gmail.com

unread,
Aug 19, 2016, 5:34:36 AM8/19/16
to WordCram, blacks...@gmail.com
Also, I should add, there are no errors or other messages of any kind in the console.

blacks...@gmail.com

unread,
Aug 19, 2016, 5:55:13 AM8/19/16
to WordCram, blacks...@gmail.com
Ah, my apologies, I have saved the sketch and now it seems to work.

Dan Bernier

unread,
Aug 19, 2016, 9:34:58 AM8/19/16
to blacks...@gmail.com, WordCram
Ach! That'll do it :)

On Fri, Aug 19, 2016 at 5:55 AM, <blacks...@gmail.com> wrote:
Ah, my apologies, I have saved the sketch and now it seems to work.

--
You received this message because you are subscribed to the Google Groups "WordCram" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wordcram+unsubscribe@googlegroups.com.

To post to this group, send email to word...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages