We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexDiscussionExhibition › javadvent 2009 - a little processing toy a day!
Pages: 1 2 
javadvent 2009 - a little processing toy a day! (Read 4473 times)
javadvent 2009 - a little processing toy a day!
Dec 1st, 2009, 11:10am
 
So inspired by the Advent Calendars I had as a kid, the Lego ones they have now, and the Perl Advent site, I've made an advent Calendar -  

http://kisrael.com/java/advent2009/

Every day there will be a little holiday-themed toy or game to play with (22 of the 25 are done so I'm not too worried  Wink )

Anyway, some of the little things came out really neat, so I hope you enjoy!
Re: javadvent 2009 - a little processing toy a day!
Reply #1 - Dec 1st, 2009, 12:23pm
 
Funny little toy (the first one). I suppose they are not too hard to do, but it must be a feat of imagination to create all these!
Nice page too!
Re: javadvent 2009 - a little processing toy a day!
Reply #2 - Dec 1st, 2009, 11:34pm
 
Hah! I love this! It brings back the joy of anticipation of the advent calendar for me, that I remember from when I was a kid. I guess static images don't do it for me any more.
Re: javadvent 2009 - a little processing toy a day!
Reply #3 - Dec 2nd, 2009, 12:49am
 
Yes, thats really nice.. much better than a little piece of chocolate
Re: javadvent 2009 - a little processing toy a day!
Reply #4 - Dec 2nd, 2009, 7:07am
 
Very nice, good physics in both games!
Re: javadvent 2009 - a little processing toy a day!
Reply #5 - Dec 2nd, 2009, 8:43am
 
Thanks for the kind words!

I've always been charmed with the physics you can get with super-simple xspeed/yspeed calculations.

All 25 of these are completely self-contained, in terms of not using any fonts or sounds or additional libraries - i even invented a "14 segment LCD"-like font for the few that needed a bit of text.

Re: javadvent 2009 - a little processing toy a day!
Reply #6 - Dec 2nd, 2009, 2:43pm
 
that is cool I would love to see the code for the letters. Have you put in numbers (I'm at school and they have blocked your site unfortunately).
Re: javadvent 2009 - a little processing toy a day!
Reply #7 - Dec 2nd, 2009, 3:28pm
 
So I threw together a mildly cleaned up version and some test code:
it's pretty rough in some ways, but does wordwrap and stuff in a way not entirely differently than normal fonts in processing...

Code:
/*
the basic idea is you have characters made up of
-----
|\|/|
-- --
|/|\|
-----
   *
the patterns for each stored in a hashmap of arrays,
keyed on the letter, value is an array of which segments
to display, numbered thus:


----1----
|\   |  / |
2 3  4 5 6
--7--  -8--
9 10 11 12 13
| /  |  \ |
----14----
         0
*/

HashMap font = new HashMap();

void setup(){
  size(250,250);
 setupFont();
 strokeWeight(2);
 drawText("the quick brown fox 'jumps' over the lazy dog?!... - 0 1 2 3 4 5 6 7 8 9 ",10,10,200,8,16);
}


void drawText(String s,float x, float y, float maxwidth ,float w, float h){
 float origx =x ;
 s = s.toUpperCase();
 String[] words = s.split(" ");
   for(int  wordptr = 0; wordptr < words.length; wordptr++){
      String word = words[wordptr];
      if(x + word.length()*w > origx+maxwidth){
         x = origx;
         y += h * 1.5;
      }
     for(int i = 0; i < word.length();i++){
       drawChar(word.substring(i,i+1),x,y,w-3,h);
       x += w;
   }
     x += w;
   }
   
}  

void setupFont(){
font.put("0",new int[] {1,2,5,6,9,10,13,14});
font.put("1",new int[] {4,11} );
font.put("2",new int[] {1,6,8,7,9,14} );
font.put("3",new int[] {1,6,8,7,13,14} );
font.put("4",new int[] {2,7,8,6,13} );
font.put("5",new int[] {1,2,7,8,13,14} );
font.put("6",new int[] {1,2,7,8,13,14,9} );
font.put("7",new int[] {1,6,13} );
font.put("8",new int[] {1,2,6,7,8,9,13,14} );
font.put("9",new int[] {1,2,6,7,8,13,14} );
font.put("A",new int[] {9,2,1,6,13,7,8} );
font.put("B",new int[] {1,14,4,6,11,13,8} );
font.put("C",new int[] {1,2,9,14} );
font.put("D",new int[] {1,14,4,11,6,13} );
font.put("E",new int[] {1,2,7,9,14} );
font.put("F",new int[] {1,2,7,9} );
font.put("G",new int[] {1,2,9,14,13,8} );
font.put("H",new int[] {2,9,6,13,7,8} );
font.put("I",new int[] {1,4,11,14} );
font.put("J",new int[] {9,14,13,6} );
font.put("K",new int[] {2,9,7,5,12} );
font.put("L",new int[] {2,9,14} );
font.put("M",new int[] {9,2,3,5,6,13} );
font.put("N",new int[] {9,2,3,12,13,6} );
font.put("O",new int[] {1,2,9,14,13,6} );
font.put("P",new int[] {1,2,6,7,8,9} );
font.put("Q",new int[] {1,2,6,9,14,13,12} );
font.put("R",new int[] {1,2,6,7,8,9,12} );
font.put("S",new int[] {1,2,7,8,13,14} );
font.put("T",new int[] {1,4,11} );
font.put("U",new int[] {2,9,14,13,6} );
font.put("V",new int[] {2,9,10,5} );
font.put("W",new int[] {2,9,14,13,6,11} );
font.put("X",new int[] {3,10,5,12} );
font.put("Y",new int[] {3,5,11} );
font.put("Z",new int[] {1,5,10,14} );

font.put(" ",new int[] {} );
font.put(".",new int[] {0} );
font.put(",",new int[] {10} );
font.put("!",new int[] {4,11,0} );
font.put("'",new int[] {4} );

font.put("?",new int[] {1,2,6,8,11,0} );
font.put("&",new int[] {1,3,6,8,9,12,14} );
font.put("+",new int[] {4,7,8,11} );
font.put("-",new int[] {7,8} );
}

void drawChar(String c, float x, float y, float w, float h){

  int[] segs = (int[])font.get(c);
  if(segs == null) return;
  for(int i = 0; i < segs.length; i++){

     switch(segs[i]){
        case 1:
        line(x,y,x+w,y); break;
        case 2:
        line(x,y,x,y+(h/2));break;
        case 3:
        line(x,y,x+(w/2),y+(h/2));break;
        case 4:
        line(x+(w/2),y,x+(w/2),y+(h/2));break;
        case 5:
       line(x+w,y,x+(w/2),y+(h/2));  break;      
       case 6:
       line(x+w,y,x+w,y+(h/2));break;
        case 7:
         line(x,y+(h/2),x+(w/2),y+(h/2));break;
         case 8:
         line(x+(w/2),y+(h/2),x+w,y+(h/2));break;
         case 9:
         line(x,y+(h/2),x,y+h);break;
         case 10:
         line(x,y+h,x+w/2,y+h/2);break;
         case 11:
         line(x+w/2,y+h/2,x+w/2,y+h);break;
         case 12:
         line(x+w/2,y+h/2,x+w,y+h);break;
         case 13:
         line(x+w,y+h/2,x+w,y+h);break;
         case 14:
         line(x,y+h,x+w,y+h);break;
         case 0:
         line(x+w/2-w/6,y+h+h/4,x+w/2+w/6,y+h+h/4);break;
         
       default:
      break;
     }
   
   
  }
}
Re: javadvent 2009 - a little processing toy a day!
Reply #8 - Dec 2nd, 2009, 4:05pm
 
thats cool I'd love to use it as part of an internet based program that doesn't need to load anything but the code.

I also haven't come across the text.put command before. nice work.
Re: javadvent 2009 - a little processing toy a day!
Reply #9 - Dec 3rd, 2009, 2:13am
 
kirk, look at charAt() for getting characters from strings - so much neater than substring(a, a+1).

you can also store all your character definitions in a single short rather than using an int[] for each of them - each segment only needs one bit to store, not an int. you'll need to look into bitwise operations...

(kids today and their gigabytes. in my day we had 16k...)

day 2 was a nice little sketch, i do like a good particle system.

day 3 great too.
Re: javadvent 2009 - a little processing toy a day!
Reply #10 - Dec 3rd, 2009, 2:28am
 
very fun sketches! :-D
Re: javadvent 2009 - a little processing toy a day!
Reply #11 - Dec 3rd, 2009, 4:31am
 
Cool games!
Re: javadvent 2009 - a little processing toy a day!
Reply #12 - Dec 3rd, 2009, 5:03am
 
@Beatsy You're welcome to it. A shoutout in the comments is nice but not required ;-)

By text.put, do you mean my "font.put()" In which case you're talking about a good old HashMap() - an EXTREMELY useful concept to get your head around, storing simple key/value pairs turns out to be a good thing to do over and over in programming.

@koogy ok, gramps... ...no, you're totally correct.

Heh, my one attempt at REALLY efficient coding was when I wrote a game for the 4K-ROM, 128-byte Atari 2600 - JoustPong. I get most of my exercise in processing at http://glorioustrainwrecks.com , making games in little 2 hour sprints, and you learn some bad habits like running with the first bit of code that possibly works ...
Re: javadvent 2009 - a little processing toy a day!
Reply #13 - Dec 3rd, 2009, 6:00am
 
(ha, i spent november doing a nanowrimo-like sketch-a-day thing so i know the quick and dirty feeling. but there were also days when it turned out small and elegant and those were the better days)
Re: javadvent 2009 - a little processing toy a day!
Reply #14 - Dec 3rd, 2009, 7:55am
 
koogy wrote on Dec 3rd, 2009, 6:00am:
(ha, i spent november doing a nanowrimo-like sketch-a-day thing so i know the quick and dirty feeling. but there were also days when it turned out small and elegant and those were the better days)

Oh yeah Do you have a link for your sketch-a-days

Some of these things are reasonably nicely done, structurally, but the code has very little cleanup. I think the worst is my habit of just starting to type anywhere without always sticking to general niceities like "variables at top, local classes below" etc. I'm not super crazy about the Processing IDE, but also too lazy to do the whole Eclipse configuration thing.
Pages: 1 2