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.
IndexProgramming Questions & HelpPrograms › Peeing in the snow program
Page Index Toggle Pages: 1
Peeing in the snow program (Read 724 times)
Peeing in the snow program
Oct 5th, 2008, 5:59am
 
My program simulates peeing in the snow. I have the bulk of my code done, but I'm running into some problems.

1.) I want to add some off-white to my white snow background. I'm using a nested for loop in draw():

  for (int i = 1; i =< 399; i = i + 5) {
     for (int j = 1; j =< 399; j = l + 5) {
       color antiquewhite = color(250, 235, 215);
       set(i, j, antiquewhite);
     }
   }
---

When I compile, I get this error message:

unexpected token: <

I don't understand what this is telling me since I'm not literally using a "<" in my code and am formatting a for loop correctly (to my knowledge.) Also, are there more interesting ways to add texture without using an image or something like that?

2.) The main part of my code should be drawing streams of yellow while the mouse is pressed down and leaving only a trail following only where the cursor has been when the mouse is released. As of right now, I have the streams being drawn as well as the pixels following the cursor:

Code:

boolean Dragging;
boolean Pressed;

// setup

void setup(){
size(400, 400);
smooth();
frameRate(60);
background(255);//white background for looking down at snow
}

void draw() {
/**for (int i = 1; i =< 399; i = i + 5) {
for (int j = 1; j =< 399; j = l + 5) {
color antiquewhite = color(250, 235, 215);
set(i, j, antiquewhite);
}
}*/

//draw boy
color blue = color(0, 0, 255);//blue sweater
fill(blue);
noStroke();
rect(100, 360, 200, 60);
ellipse(103, 364, 10, 10);//smoothing shoulders
ellipse(297, 364, 10, 10);//smoothing shoulders
rect(102, 359, 197, 4);//smoothing shoulders
rect(98, 365, 4, 55);//smoothing shoulders
rect(298, 365, 4, 55);//smoothing shoulders
color brown = color(165, 42, 42);//brown hair
fill(brown);
ellipse(200, 400, 120, 120);//top of head

if (Pressed) {
color yellow = color(255, 255, 0);
stroke(yellow);
line(201, 339, mouseX, mouseY);//stream
set(mouseX, mouseY, yellow);//trail
}

if (Dragging) {
color yellow = color(255, 255, 0);
stroke(yellow);
line(201, 339, mouseX, mouseY);
set(mouseX, mouseY, yellow);
}

}

//draw stream

void mousePressed() {
Pressed = true;
if (mouseY < 339) {
color yellow = color(255, 255, 0);
stroke(yellow);
line(201, 339, mouseX, mouseY);
set(mouseX, mouseY, yellow);
}
}

void mouseDragged() {
Dragging = true;
if (mouseY < 339) {
color yellow = color(255, 255, 0);
fill(yellow);
line(201, 339, mouseX, mouseY);
set(mouseX, mouseY, yellow);
}
}

void mouseReleased() {
Dragging = false;
Pressed = false;
}

void keyPressed() {
setup();
}

---

I'm having a really hard time trying to figure out how to use a combonation of loop(), noLoop(), draw(), redraw(), and frameRate() so that only the most recently drawn stream (yellow line) is displayed, but all of the pixels that have been drawn are displayed. What should I use? This is the key to my program.

3.) I don't want a pixel or line to be drawn is the mouse's y position is more than 339, since then it would be drawn on the illustration of the boy or beside or behind him, which isn't realistic. Hence, I have the if statements in mousePressed() and mouseDragged(). This doesn't seem to be effecting anything at all, though. What am I doing wrong?

Thanks so much for any help.
Re: Peeing in the snow program
Reply #1 - Oct 5th, 2008, 12:27pm
 
The answer for part 1 is easy, you've put =< but the correct syntax is <=
Re: Peeing in the snow program
Reply #2 - Oct 5th, 2008, 5:42pm
 
Wow, I'm silly. Thanks so much. I don't know why I said I wasn't using a "<" when I obviously am.
Re: Peeing in the snow program
Reply #3 - Oct 5th, 2008, 5:48pm
 
Ok. When I implement the for statement correctly, the program won't run. If I put it in draw(), the display window comes up blank and freezes. If I put it in setup, no display window comes up. There aren't any compiler errors, though.
???
Re: Peeing in the snow program
Reply #4 - Oct 5th, 2008, 10:56pm
 
When you write j = l + 5, I don't see where the l come from.

Beside, it is not incorrect, but I would put the constant color (antiquewhite) out of the double loop, for performance reasons.
Re: Peeing in the snow program
Reply #5 - Oct 6th, 2008, 3:38am
 
Thanks. I've fixed a couple of things, but I still can't figure out the key to my program. I want only the most recently drawn line to be displayed, but I want all the pixels ever drawn to to displayed. Here's my code:

Code:

boolean Dragging;
boolean Pressed;

// setup

void setup(){
size(400, 400);
smooth();
frameRate(60);
}

void draw() {

background(255);//white background for looking down at snow

color antiquewhite = color(250, 235, 215);
for (int i = 1; i <= 399; i = i + 5) {
for (int j = 1; j <= 399; j = j + 5) {
set(i, j, antiquewhite);
}
}

//draw boy
color blue = color(0, 0, 255);//blue sweater
fill(blue);
noStroke();
rect(100, 360, 200, 60);
ellipse(103, 364, 10, 10);//smoothing shoulders
ellipse(297, 364, 10, 10);//smoothing shoulders
rect(102, 359, 197, 4);//smoothing shoulders
rect(98, 365, 4, 55);//smoothing shoulders
rect(298, 365, 4, 55);//smoothing shoulders
color brown = color(165, 42, 42);//brown hair
fill(brown);
ellipse(200, 400, 120, 120);//top of head

if (Pressed) {
color yellow = color(255, 255, 0);
stroke(yellow);
line(201, 339, mouseX, mouseY);//stream
set(mouseX+1, mouseY+1, yellow);//trail
}

if (Dragging) {
color yellow = color(255, 255, 0);
stroke(yellow);
line(201, 339, mouseX, mouseY);
set(mouseX+1, mouseY+1, yellow);
}

}

//draw stream

void mousePressed() {
Pressed = true;
if (mouseY < 339) {
color yellow = color(255, 255, 0);
stroke(yellow);
line(201, 339, mouseX, mouseY);
set(mouseX+1, mouseY+1, yellow);
}
}

void mouseDragged() {
Dragging = true;
if (mouseY < 339) {
color yellow = color(255, 255, 0);
fill(yellow);
line(201, 339, mouseX, mouseY);
set(mouseX+1, mouseY+1, yellow);
}
}

void mouseReleased() {
Dragging = false;
Pressed = false;
}

void keyPressed() {
setup();
}


Where do I implement redraw just for the set() functions?
Re: Peeing in the snow program
Reply #6 - Oct 6th, 2008, 4:00am
 
I've decided to use the pixel array instead of set() because I think it'll be easier to fix my problem of wanting to keep the lines, but not the dots.

Code:

boolean Dragging;
boolean Pressed;

// setup

void setup(){
size(400, 400);
smooth();
frameRate(60);
}

void draw() {

background(255);//white background for looking down at snow

color antiquewhite = color(250, 235, 215);
for (int i = 1; i <= 399; i = i + 5) {
for (int j = 1; j <= 399; j = j + 5) {
set(i, j, antiquewhite);
}
}

//draw boy
color blue = color(0, 0, 255);//blue sweater
fill(blue);
noStroke();
rect(100, 360, 200, 60);
ellipse(103, 364, 10, 10);//smoothing shoulders
ellipse(297, 364, 10, 10);//smoothing shoulders
rect(102, 359, 197, 4);//smoothing shoulders
rect(98, 365, 4, 55);//smoothing shoulders
rect(298, 365, 4, 55);//smoothing shoulders
color brown = color(165, 42, 42);//brown hair
fill(brown);
ellipse(200, 400, 120, 120);//top of head

if (Pressed) {
color yellow = color(255, 255, 0);
stroke(yellow);
line(201, 339, mouseX, mouseY);//stream
loadPixels();
pixels[mouseY*width+mouseX]=yellow;
pixels[(mouseY+1)*width+(mouseX+1)]=yellow;//trail
updatePixels();
}

if (Dragging) {
color yellow = color(255, 255, 0);
stroke(yellow);
line(201, 339, mouseX, mouseY);
loadPixels();
pixels[mouseY*width+mouseX]=yellow;
pixels[(mouseY+1)*width+(mouseX+1)]=yellow;
updatePixels();
}

}

//draw stream

void mousePressed() {
Pressed = true;
if (mouseY < 339) {
color yellow = color(255, 255, 0);
stroke(yellow);
line(201, 339, mouseX, mouseY);
loadPixels();
pixels[mouseY*width+mouseX]=yellow;
pixels[(mouseY+1)*width+(mouseX+1)]=yellow;
updatePixels();
}
}

void mouseDragged() {
Dragging = true;
if (mouseY < 339) {
color yellow = color(255, 255, 0);
fill(yellow);
line(201, 339, mouseX, mouseY);
loadPixels();
pixels[mouseY*width+mouseX]=yellow;
pixels[(mouseY+1)*width+(mouseX+1)]=yellow;
updatePixels();
}
}

void mouseReleased() {
Dragging = false;
Pressed = false;
updatePixels();
}

void keyPressed() {
setup();
}


Unfortunately, this didn't fix anything. Can this work somehow? Sorry for all the posts, but this is due tonight...
Re: Peeing in the snow program
Reply #7 - Oct 7th, 2008, 10:42am
 
Hi, I am a total beginner but I checked out your code and made some adjustments.  I think I fixed the problem of the pee stream leaving behind its history by putting a background(255) at the beginning of the code block labeled if pressed.  because the code blocks run continuously, if mouse is pressed then the code is always refreshing the background and one pee stream remains onscreen at all times.  

This posed a problem that every time I pressed the mouse the boy would disappear under the white background() that I created.  I fixed that by moving the boy code block below the If pressed code, that way the boy will always remain on top of the refreshing background.

I deleted some unneeded code (I think) as well as your for loop because you don't need to restrict what has been written in the snow to an area because if you keep moving the draw boy code closer to the bottom of the whole program the boy will remain on top and he can't pee on himself, so to speak.

As for drawing the line in the snow.  I am not quite there yet.

Here is my adjusted code.  I hope this helps.

Here is the code:


boolean Dragging;
boolean Pressed;

// setup

void setup(){
   size(400, 400);
   smooth();
   frameRate(60);
   background(255);//white background for looking down at snow
}

void draw() {
   

   if (Pressed) {
     background(255);
color yellow = color(255, 255, 0);
stroke(yellow);
line(201, 339, mouseX, mouseY);//stream
set(mouseX, mouseY, yellow);//trail
 }
   
       //draw boy
   color blue = color(0, 0, 255);//blue sweater
   fill(blue);
   noStroke();
   rect(100, 360, 200, 60);
   ellipse(103, 364, 10, 10);//smoothing shoulders
   ellipse(297, 364, 10, 10);//smoothing shoulders
   rect(102, 359, 197, 4);//smoothing shoulders
   rect(98, 365, 4, 55);//smoothing shoulders
   rect(298, 365, 4, 55);//smoothing shoulders
   color brown = color(165, 42, 42);//brown hair
   fill(brown);
   ellipse(200, 400, 120, 120);//top of head
   
 
}

//draw stream

void mousePressed() {
   Pressed = true;
   if (mouseY < 339) {
color yellow = color(255, 255, 0);
stroke(yellow);
line(201, 339, mouseX, mouseY);
set(mouseX, mouseY, yellow);
   }
}

void mouseDragged() {
   Dragging = true;
   if (mouseY < 339) {
color yellow = color(255, 255, 0);
fill(yellow);
line(201, 339, mouseX, mouseY);
set(mouseX, mouseY, yellow);
 }
}

void mouseReleased() {
 background(255);
 Dragging = false;
 Pressed = false;
}

void keyPressed() {
 setup();
}
Page Index Toggle Pages: 1