Loading...
Logo
Processing Forum
I am reviewing for a final exam which I have on Thursday for my Intro to Programming class.  My instructor gave us a few practice problems.  I completed most but I am very confused about two of them, so I figured I'd post them on here before I go read through the reference book to teach myself.  If anyone can offer and advice or perhaps even give me a resolution that way I can study the program, to either one,  I'd be very grateful. Thanks - JM

1. Write a small program that retreives data from a site such as espn.com, yahoo etc. and display that data as scrolling or animated text.

2.  Write a program that simulates a "clicker" to count attendance. Your program should display a sequence of digits (initially all 0s) in the center of the window. Two marked areas inside the window represent “count” and “reset” 
buttons. When the user clicks on the “count” button, the numeric counter should increase by 1. When the user clicks on the “reset” button, the counter should reset itself to 0. Your counter must have at least 4 digits; when the counter reaches all 9s, clicking on the “count” button should cause it to roll over to all 0s and begin counting up from 1 again. You can use the text display functions from Chapter 17 to do this, or you can display your counter using image files. For free sets of digit image files, visit the Digit Mania Web site at http://www.digitmania.holowww.com/

Replies(5)

Let me correct my self, I am not confused. I honestly have no idea how to approach either. 

so I figured I'd post them on here before I go read through the reference book to teach myself.
That's like the complete opposite of what you should do.

Anyways here are the things i would read up on:
1)
http://processing.org/reference/XMLElement.html
and maybe have a look here (to find some sweet library): http://processing.org/reference/libraries/#data_protocols
Basically you're just looking for a way to retrieve data from the web and then it's just a matter of text(myText,xPos,height/2); or something like that.

2) A counter is the easiest thing ever, your only problem is making it 4 digits constantly so here:
http://processing.org/reference/nf_.html
As far as buttons go, shouldn't be so hard, it's just a matter of increasing or resetting a int to 0 and then use the above method to convert it to a 4 letter string and then put it on the screen.
I know that. But considering the time and most likely the insignificance of this problem in the big picture, I would prefer to just have a slight idea opposed to mastering it.   Anyways thank you very much!
the second problem is easy.... took me an hour though... hmm... i'm too much of a novice. 
the below code uses a bunch of else if conditions. i'm sure there could be a cleaner way to do this. i have implemented for 3 digits. you can try for 4. testing the sketch basically involves clicking a lot :P

btw, are you really using processing for your intro to comp? 


void setup() {
  background(150); //some light shaded background
  size(100,100);
  PFont displayFont = createFont("ArialNarrow",20); //you can use ArialNarrow or any other font from your system
  textFont(displayFont);
  text("000",30,60);
}

int [] counter = {0, 0 , 0};
int clicks = 0;

void draw() { 
  
}

void mouseClicked() {
  background(150); //paint the background again to erase the previous value
  
  
  if (clicks<9) { //prints a value 00c where 0<c<9
    clicks++;
    counter[2]= clicks % 10;
    text(str(counter[0])+str(counter[1])+str(counter[2]),30,60);
  }
  else if (clicks<99) {//prints a value 0bc where 1<b<9 and 0<c<9
    clicks++;
    counter[2]= clicks % 10;
    counter[1]= clicks/10;
    text(str(counter[0])+str(counter[1])+str(counter[2]),30,60);
  }
  else if (clicks<999) {//prints a value ac where 10<a<90 and 0<c<9
    clicks++;
    counter[2]= clicks % 10;
    counter[0]= clicks/10;
    text(str(counter[0])+str(counter[2]),30,60);
  }
  else {
    int [] counter = {0, 0 , 0};
    text("000",30,60);
  }
}


i really don't know how to grab text data off a website. if you come to know about it please post it here. it would be useful for me to know. thanks. 

best,

sam
ha! i'm so slow. 

much better ways do exist.