FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   help! with if(){----}
« Previous topic | Next topic »

Pages: 1 2 
   Author  Topic: help! with if(){----}  (Read 1599 times)
fry


WWW
Re: help! with if(){----}
« Reply #15 on: Jun 28th, 2003, 4:13pm »

it gets better.
 
Code:
int letter(int key) {
  return ((key >> 6) == 1) ? (1 << ((key & 0x31)-1)) : (1 << 30);
}

ascii 'A' is decimal 65. ascii 'a' is 97. you might recognize these numbers as 2^6 + 1 and 2^6 + 1 + 2^5. so the letter is in the lower 5 bits of the code (numbered 1..26), so the byte looks like:
 
Code:
letter? lowercase? letter code
0 1 . . X . . . .  X X X X X

if it's a letter, the top two bits are 0 and 1. if it's uppercase, the next bit is zero, otherwise it's 1. then the letter is smushed into the 5 bits that follow.
 
letters larger than 26 get into punctuation, but since they're being ignored in the program, we don't care about them being "misinterpreted" as a letter.
 
the "if" statement needs to be modified since A is now at bit 1 instead of bit zero, so just add one to each:
Code:
if ((alphabet & (1<<1)) != 0) {  // a  
  // so fancy it my hurt your head
}

edit -- nevermind that last part, i modified the code to just subtract it down by 1.
« Last Edit: Jun 28th, 2003, 4:22pm by fry »  
arielm

WWW
Re: help! with if(){----}
« Reply #16 on: Jun 28th, 2003, 9:03pm »

so how do you feel benelek? 3 hours left from the countdown!
 
or maybe it's just the middle of the night right now in australia, and you are in the middle of a dream about little crosses and circles?
 

Ariel Malka | www.chronotext.org
flight404

WWW Email
Re: help! with if(){----}
« Reply #17 on: Jun 28th, 2003, 10:53pm »

I came up with an amazing three line solution.  It came to me in a dream filled with wingspans and precipitation.  It had all the elegance of Michell Kwan executing a quad combined with the brute in-your-faceness of a Slash power chord.  It was simple in its complexity and complex in its ease of implementation.  It spoke in three tiered metaphors and needed little punctuation.
 
But my computer crashed and I didn't save it.  You will just have to take my word for it.  It would have blown your collective minds.
 

 
UPDATE----------
So, like Arielm, I got to thinking.  What if Processing23 is actually someone else, in the guise of a 10 year old, trying to get someone to solve a problem for him without actually having to ask.
 
So, along the same 'white washing the fence' vein, I bet none of you can make an applet which references sound from the audio input, uses a fast fourier transform with all frequencies audible by humans, and outputs the results realtime in the form of an array with each element having a range from -100 to 100.  You have three days.  
« Last Edit: Jun 28th, 2003, 11:02pm by flight404 »  
arielm

WWW
Re: help! with if(){----}
« Reply #18 on: Jun 29th, 2003, 12:32am »

on Jun 28th, 2003, 10:53pm, flight404 wrote:
I came up with an amazing three line solution.  It came to me in a dream filled with wingspans and precipitation...

starts to sound like a David Lynch movie, i like it!
 
 
on Jun 28th, 2003, 10:53pm, flight404 wrote:
What if Processing23 is actually someone else...

yeah, i would say that the Processing23 case is a mystery that still needs to be solved...
 
is there anyone in this community who is _ in addition of being a java programmer _ also a private detective
 
 
on Jun 28th, 2003, 10:53pm, flight404 wrote:
I bet none of you can make an applet which...

thanks for the generous offer, but i think i will limit my participation in programming contests to once a quarter!
 

Ariel Malka | www.chronotext.org
arielm

WWW
Re: help! with if(){----}
« Reply #19 on: Jun 29th, 2003, 1:05am »

it's been a mess to deal with the interpretation of "sunday at 12:00AM GMT"... anyway, here is my version of what you know:
http://www.chronotext.org/processing/shortest
 
(don't forget to click on the applet if you want the 1..9 keys to work)
 
Code:

int[][] nums =
{
  {3, 2, 2, 2, 7},
  {7, 4, 7, 1, 7},
  {7, 4, 7, 4, 7},
  {5, 5, 7, 4, 4},
  {7, 1, 7, 4, 7},
  {7, 1, 7, 5, 7},
  {7, 4, 4, 4, 4},
  {7, 5, 7, 5, 7},
  {7, 5, 7, 4, 7}
};
int[] cross = {17, 10, 4, 10, 17};
int[] circle = {14, 17, 17, 17, 14};
boolean keys[] = new boolean[9];
 
void keyPressed()
{
  foo(true);
}
 
void keyReleased()
{
  foo(false);
}
 
void foo(boolean bar)
{
  if (key >= '1' && key <= '9')
  {
    keys[key - '1'] = bar;
  }
}
 
void loop()
{
  stroke(0);
  noFill();
  for (int j = 0; j < 3; j++)
  {
    for (int i = 0; i < 3; i++)
    {
 shape(9 + i * 33, 3 + j * 33, j * 3 + i, keys[j * 3 + i]);
    }
  }
  rect(0, 0, 99, 99);
  rect(0, 33, 99, 33);
  rect(33, 0, 33, 99);
}
 
void shape(int x, int y, int n, boolean on)
{
  int[] shape = n < 0 ? (on ? cross : circle) : nums[n];
  for (int j = 0; j < 5; j++)
  {
    int b = shape[j];
    for (int i = 0; i < 5; i++)
    {
 if ((b & 1) == 1)
 {
   if (n < 0)
   {
     point(x + i, y + j);
   }
   else
   {
     shape(x + i * 6, y + j * 6, -1, on);
   }
 }
 b = b >> 1;
    }
  }
}

 
maybe it could have been a bit shorter than this but i thought a respectable programming contest code should include at least one recursive function
 
now our eyes all point towards oceania!
 

Ariel Malka | www.chronotext.org
benelek

35160983516098 WWW Email
Re: help! with if(){----}
« Reply #20 on: Jun 29th, 2003, 2:56am »

ha! i believe mine looks more interesting:
Code:

boolean[] nd = new boolean[9];  
String[][][] tn = {{
  {"001", "111", "111"},
  {"001", "001", "001"},
  {"001", "111", "111"},
  {"001", "100", "001"},
  {"001", "111", "111"}
  }, {
  {"101", "111", "111"},
  {"101", "100", "100"},
  {"111", "111", "111"},
  {"001", "001", "101"},
  {"001", "111", "111"}
  }, {
  {"111", "111", "111"},
  {"001", "101", "101"},
  {"001", "111", "111"},
  {"010", "101", "001"},
  {"010", "111", "001"}
  }};
 
void c(boolean st) { for(int i=0; i<10; i++) if (i+49==key) nd[i]=st; }
 
void dc(boolean on, int x, int y) {
  if(!on) ellipse(x,y,10,10); else {
    line(x,y,x+10,y+13);
    line(x+10,y,x,y+13);
  }
}
   
void setup() {  
  size(299, 299); //by bnlk
  noFill();
}
 
void keyPressed() { c(true); }  
void keyReleased() { c(false); }
 
void loop() {
  for(int i=0; i<3; i++) {
    for(int j=0; j<5; j++) {
 for(int k=0; k<3; k++) {
   rect(k*100-1, i*100-1, 100,100);
   for(int q=0; q<3; q++) if(tn[i][j][k].charAt(q)=='1') dc(nd[i*3+k], k*100+q*15+27, i*100+j*15+12);
 }
    }
  }
}  

 
strangely, it has decided not to run from my webspace (try it here: http://users.bigpond.net.au/schwartz/numDown/applet/ ), but it will work from a local folder (download the bits here: http://users.bigpond.net.au/schwartz/numDown/applet/numDown.zip ). is anyone able to view it from my webspace as well as from a local folder?
 
arielm

WWW
Re: help! with if(){----}
« Reply #21 on: Jun 29th, 2003, 10:59am »

as a participant in the contest, i won't make any judgment
 
but if i would be a programming teacher, i would ask to my students to think about the ways to store and access the data of the 1..9 numbers!
 
now a note about the java language: it striked me that i had to use ints instead of bytes (otherwise, bitwise operation won't work) to store the data, which in this case is never more than 8 bits!
 
also, it kills me that it's not possible to do a simple thing like:
 
if (b & 1)
 
java prefers something overkill like:
 
if ((b & 1) == 1)
 
because a byte or an int apparently can't be converted into a boolean!
 
well, we know that java is overkill anyway, dont' we?
 
 
benelek, it has been a lot of fun! see you around...
 
 
---
 
your applet doesn't work online because its jar file is corrupted... (if you post instead the jar file which is in the alternative zip file, it will work!)
« Last Edit: Jun 29th, 2003, 11:06am by arielm »  

Ariel Malka | www.chronotext.org
pokemon#1

WWW Email
Re: help! with if(){----}
« Reply #22 on: Jul 3rd, 2003, 11:15am »

Thank you so much. Proce55ing23 is at sleep away camp, and I am working on the applet while he's gone.
 
Let me get this straight. int letter returns an integer depending on what key(s) are pressed, and then you use if() statements to make something happining depending on what the integer is?
 
benelek

35160983516098 WWW Email
Re: help! with if(){----}
« Reply #23 on: Jul 3rd, 2003, 3:13pm »

yeah, that works. one of the biggest differences between your first applet and the stuff we came up with, is that our applets record which keys are down, during the keyReleased() event. this is because during that event, the variable 'key' can tell you that more than one key are pressed. otherwise, it only holds information for one key.
 
i think Ben's method of bit packing is the neatest/coolest, but any of our methods of storing which keys are pressed will work for what you want. if you want to post the next version of your applet's code on this thread, i'll be happy to help you.
 
Pages: 1 2 

« Previous topic | Next topic »