Functional Stencils() and Brushes()

having a hard time incorporating this into a code, any help would be great.
the directions state to do this for my assignment

  • each key a,s,d,f,g will be assigned to call a different function
  • use noLoop(), loop(), combined with the function mouseReleased() to make the brush a stencil, or not.
  • use booleans to help control mouse and keyboard input.
  • incorporate iterative loops to create sophisticated patterns.
  • create a function that will erase the sketch so you can start again without having to run the program.
// INITIALIZE VARIABLES

// SETUP
  size, background, etc. 
  
// DRAW
  // if the mouse is pressed
      //also, if the 'a' key is pressed
          // call the brush #1
          // and make it so draw() DOES loop
      // else if the 's' key is pressed
          //  call the stencil #2
	  // and make it so draw() DOES NOT loop

// USER DEFINED FUNCTION
    // custom brush #1

// USER DEFINED FUNCTION
    // custom stencil #2

// USE mouseReleased() to turn 
  // each time the mouse is released make sure that draw function is (re)set to loop() if it isn't

Hey, sounds like an interesting project. However it seems like your asking how to do all of your homework. It would be great if you could attempt some of it and then ask if for help if you get stuck.

Here’s two examples that might be a good place to start:
mouse functions example
keyboard functions example

Dan Shiffman’s processing videos are also a great place to learn about specific topics like if statements. Here is a list of all of those.

My advice is to start small and add one thing at a time. Once you get something like detecting keys working then move on to the next thing. Hope that’s enough to get started.

3 Likes

this is what i have so far and im lost.

void setup() {//start void setup

  size(600,600);

  background(255);

}//end void setup

void draw() {//stat draw

int x = 100;

 if (mousePressed && mouseButton ==LEFT) {// start mouse left

   frameRate(10);

   while (x<120) {//start while loop

   fill(179, 255, 0);

  ellipse(mouseX,300,random(300),70);

   x = x+100;

   }//end while loop

 }//end mouse left

 if (mousePressed && mouseButton==RIGHT) {//start mouse right

 for (int y=300; y<=500; y+=200) {//start for loop

   fill(0,255,0);

   rect(y,mouseY,random(150),600);

    fill(random(255),10,10);

   line(200,mouseY,random(600),300);

 }//end for loop

 }//end mouose right

 

  if (mousePressed) {

    stroke(255);

  } else {

    stroke(0);

  }

  line(mouseX-66, mouseY, mouseX+66, mouseY);

  line(mouseX, mouseY-66, mouseX, mouseY+66); 

}//end draw

Read the reference now for keypressed please and check the letters

Set some boolean accordingly

Tip: Format code on the forum by editing your post and using the </> button on the highlighted code.

The references that Chrisir mentioned are here: