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

Make it easy to re-render a wordcram, without re-parsing all the text #17

Open
danbernier opened this issue Feb 24, 2013 · 3 comments
Open

Comments

@danbernier
Copy link
Owner

I'm thinking something like this:

def draw_all
  reset_words
  while has_more
    draw_next
  end
end

def reset_words
  words.each(&:reset)
end

(...except in java, not ruby.)

We want a way to reset the progress when you're drawing incrementally (call reset_words when you're done), and a way to reset it if you just call draw again.

@danbernier
Copy link
Owner Author

This is done - it works.

In retrospect, I'm not sure it's a feature WordCram should have.

The main motivation was to avoid re-loading the URL. (Loading a file from the harddrive is plenty fast, and so is parsing text with cue.language.) That can also be accomplished in-sketch, by caching the contents, or saving the file. Also, WebPage can be made to cache its text, and you can construct a WordCram with your own WebPage object.

This code complicates the internals a bit, and given the motivation and work-arounds, I'm not sure it's worth it.

@danbernier
Copy link
Owner Author

See the cache-web-pages branch for an alternative. Here's about how a sketch would look:

import wordcram.*;
import wordcram.text.*;  // <-  Ick: it requires an extra import

WebPage webPage;    // <- global variable for the WebPage

void setup() {
  webPage = new WebPage("http://en.wikipedia.org/wiki/Special:Random", this);
  // Ick: have to pass `this` to WebPage, so it can load the URL.  ------^
  // Could improve that: WordCram.getEngine() could set a ref to parent on all the components.
}

void draw() {
  new WordCram(this)   // <- Look Ma, a new WordCram every frame!
    .fromText(webPage)  // <- Not in love with this method name
    .drawAll();
}

@danbernier
Copy link
Owner Author

@danbernier thanks for writing down your thoughts, because I totally forgot all this stuff.

@danbernier danbernier mentioned this issue Jul 16, 2013
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant