an option to repeat/duplicate words

74 views
Skip to first unread message

HxnHng

unread,
Oct 7, 2014, 11:55:06 AM10/7/14
to word...@googlegroups.com
Hi, I was wondering if there is an option to repeat words? I would like for a few words to show up more than once. Tagul has an option to duplicate words so I was wondering if there was something similar in WordCram? I've gone through all of the tutorials and wasn't able to find anything on allowing duplicates. If not, how would I go about building or writing my own Placer? (sorry this is my first day with Processing and WordCram).

One alternative I've tried was creating 2 WordCrams, but they are overlapping each other as I expected. Maybe if there was a way to place the 2nd wordcram around the first?

Cheers 

HxnHng

unread,
Oct 7, 2014, 12:02:01 PM10/7/14
to word...@googlegroups.com
I forgot to mention that I found this here which I think refers to what I am wanting to do: https://github.com/danbernier/WordCram/issues/25

It looks like there is code to do this, but I still don't know how to use it.

simpsus

unread,
Oct 8, 2014, 7:06:21 AM10/8/14
to word...@googlegroups.com
It is true that I did code this feature, as it was/is something that I want to use myself.
However, Dan did not include it into Wordcram for various reasons.

So the only way for you to use this would be to take the FiniteTextSource File that I coded and use that. 
Of course that would require you to switch to a non-packaged usage of Wordcram, something that I can neither support you with nor incourage to do.

Dan Bernier

unread,
Oct 8, 2014, 7:46:54 AM10/8/14
to word...@googlegroups.com
Shoot! I replied directly to HxnHng last night, when I meant to post to the forum.

Simpsus isn't quite right - it's really easy to do this without using a forked version of WordCram. This sketch does it in only a few lines (a sample output is attached):

void setup() {
  size(800, 550);
  new WordCram(this).
    fromWords(repeatWords(100, "hello", "there")).
    drawAll();
}

Word[] repeatWords(int numWords, String... wordStrings) {
  Word[] words = new Word[numWords];
  float distributionPower = 2;
  for (int i = 0, wsi = 0; i < numWords; i++, wsi = (wsi + 1) % wordStrings.length) {
    float weight = pow(random(1), distributionPower);
    String word = wordStrings[wsi];
    words[i] = new Word(word, weight);
  }
  return words;
}

Also, I built it into WordCram last night, on a branch: https://github.com/danbernier/WordCram/tree/word-bag With that, the above sketch code becomes this:

import wordcram.*;

void setup() {
  size(800, 550);
  new WordCram(this).
    fromWords(new WordBag(100, "hello", "there").weightDistributionPower(2)).
    drawAll();
}

(And actually, that .weightDistributionPower(2) is only there for illustration, because it defaults to 2.)
wc1.png

HxnHng

unread,
Oct 9, 2014, 1:11:07 AM10/9/14
to word...@googlegroups.com
Thanks dan and simpsus for responding! Simpsus, I tried compiling your code with FiniteTextSource but it seems to be missing batik. I tried including it and it eventually compiled but I don't think I linked it correctly so it was unable to work in Processing. I'm still very new to this compiling and programming so I was just happy to finally run rake without any errors lol. 

I will take a look at Dan's 2 approaches above and try them as it looks like it is the solution I am looking for. I will report back with any failures and or successes :)  

cheers

Yuan Lu

unread,
Feb 11, 2016, 5:44:19 PM2/11/16
to WordCram
Hi Dan! I'm using WordCram 1.0.0 and Processing 3, and can't seem to get WordBag to work (Processing protests class doesn't exist, but I've already saved WordBag.java in the src/wordcram folder - am I doing it wrong?) Thank you!!

Dan Bernier

unread,
Feb 12, 2016, 9:41:04 PM2/12/16
to Yuan Lu, WordCram
Hi Yuan Lu,

Yeah, WordBag never made it on to the master branch, so it's not part of WordCram 1.0.0. I don't think saving the file into the src/wordcram folder will be enough - though you *might* be able to copy it right into your Processing sketch folder.

I looked over the source again, and I'm not sure why I never merged in this branch - so I merged it in now. If you download WordCram 1.0.1, you can use WordBag, just like you were trying to. Here's the link: https://wordcram.s3.amazonaws.com/downloads/wordcram.zip

Cheers!

--
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+u...@googlegroups.com.
To post to this group, send email to word...@googlegroups.com.



--

lynn lu

unread,
Feb 13, 2016, 11:54:54 AM2/13/16
to Dan Bernier, yuan lu, WordCram
Hi Dan

Thank you so much for your reply and for updating this awesome library - 1.0.1 works perfectly!!

Best,

Yuan

Dan Bernier

unread,
Feb 14, 2016, 11:03:01 AM2/14/16
to lynn lu, WordCram
Glad to hear it! Have fun. :)
Reply all
Reply to author
Forward
0 new messages