Assignment / Extra credit program

I was given a task to create a digital landscape! with the following criteria
Criteria:
● At least 3 different shapes used
● At least 3 different colors used
● 1 custom shape
● Minimum of 6 elements (ie tree, house, bird etc)
● At least 2 elements must move on their own
● User can interact with your scene via mouse and
keyboard
● Comments on EVERY line that draws something on the
screen. Loops and if statements must also be
commented.

i already have all my codes but how do I put each of them separately on the canvas.

-a- actually that is not part of the above shown specification

-b- many ways

  • make something like stages
    • int stage = 0;
    • on key press " " go next : stage++;
  • or use a timer

-c- what does that title mean?

Extra credit program

i not see any connection to your criteria or question

2 Likes

oh sorry, the title is Extra credit program because if i manage to complete it i get extra credits at school.

It sounds like you have several sketches, each of which is drawing one thing, and you want to put them all together into one sketch.

I would suggest you write a class for each of your things. The format would be this:

class Thing {
  // Variables for this thing.
  Thing(){
    // Setup the thing here.
  }
  void draw(){
    // Draw the thing here.
  }
}

Thing a_thing = new Thing();

Do the above for each Thing you want to draw. Name the Thing differently, of course! You’ll want the last lines to look like:

House a_house = new House();
Cat a_cat = new Cat();
Tree a_tree = new Tree();
// etc

And then you can just draw them all:

void draw(){
  background(0);
  a_tree.draw();
  a_house.draw();
  a_cat.draw();
  // etc
}
2 Likes
int stage = 0;

void setup(){
  size(500,500);
}
void draw(){
  if(stage == 1){
    fill(0);
    rect(200,200,100,100);
    fill(0,255,0);
    ellipse(100,100,100,100);
    fill(255,0,0);
    triangle(400,50,350,90,450,90);
  }
  else if( stage == 2){
    noStroke();
    beginShape();
   beginShape();
vertex(100,50);
vertex(200,20);
vertex(200,100);
vertex(50,75);
vertex(25,50);
endShape();




  
}
}
  void keyPressed(){
    
    if (key == '1'){
      stage = 1;
    }else if (key == '2'){
      stage = 2;
    }else if (key == '3'){
      stage = 3;


  }
  }

this is what i have written so far and i wanted to ask if there is a way to make the previous shapes disappear when i press for the next stage?

yes, good start

int stage = 0;

void setup() {
  size(500, 500);
}

void draw() {
  background(200,200,0);
  if      ( stage == 0) text("press 1,2,3",width/2,height/2);
  else if ( stage == 1) draw1();
  else if ( stage == 2) draw2(); 
  else if ( stage == 3) draw3(); 
}

void draw1() {
  fill(0);
  rect(200, 200, 100, 100);
  fill(0, 255, 0);
  ellipse(100, 100, 100, 100);
  fill(255, 0, 0);
  triangle(400, 50, 350, 90, 450, 90);
}

void draw2() {
    noStroke();
    beginShape();
    beginShape();
    vertex(100, 50);
    vertex(200, 20);
    vertex(200, 100);
    vertex(50, 75);
    vertex(25, 50);
    endShape();  
}

void draw3() {
  text("future",width/2,height/2);
}

void keyPressed() {
  if      (key == '1') stage = 1;
  else if (key == '2') stage = 2;
  else if (key == '3') stage = 3;
}

1 Like

the third draw…did you write future meaning a future code i put there?

? not ask me ?
you make the key 1,2,3 code,
so what you want do if user press ‘3’

but i have a idea what help to get extra credits

click here

int stage = 0;

void setup() {
  size(500, 500);
}

void draw() {
  background(200, 200, 0);
  if      ( stage == 0) text("press 1,2,3", width/2, height/2);
  else if ( stage == 1) draw1();
  else if ( stage == 2) draw2(); 
  else if ( stage == 3) draw3();
}

void draw1() {
  fill(0);
  rect(200, 200, 100, 100);
  fill(0, 255, 0);
  ellipse(mouseX, mouseY, 100, 100);
  fill(255, 0, 0);
  triangle(400, 50, 350, 90, 450, 90);
}

void draw2() {
  noStroke();
  beginShape();
  beginShape();
  vertex(100, 50);
  vertex(200, 20);
  vertex(200, 100);
  vertex(mouseX, mouseY);
  vertex(25, 50);
  endShape();
}

void draw3() {
  stroke(200, 0, 200);
  fill(0, 200, 0);
  rectMode(CENTER);
  for (int i = 0; i < many; i++)  draw_rect(i);
}

int x = 100, y = x, w = 20, h = 10;           // rectangle spec
int grid = 6, many = grid*grid;               // grid spec
int offset = 0;                               // add offset between objects          mouseY
float ang = 0;                                // angle rotation                      mouseX

void draw_rect(int i) {
  offset = int(map(mouseY, 0, height, 0, 100));
  ang = map(mouseX, 0, width, 0, PI);
  int posx = x+(i%grid)*(w+offset);
  int posy = y+(floor(i/grid))*(h+offset);
  push();
  translate(posx, posy);
  rotate(ang); //+0.05*i);
  rect(0, 0, w, h);
  pop();
}


void keyPressed() {
  if      (key == '1') stage = 1;
  else if (key == '2') stage = 2;
  else if (key == '3') stage = 3;
}

1 Like

can you explain to me what the criteria 6 different elements is? Are they pictures/ images?

hey,could you explain to me what elements are?

that is not a processing question,
who am i to interpret the wording of your basic assignment,
if i tell you and i did understand that also wrong: YOU FAIL.

in your stage 1 canvas you used 3 shapes ( rect / ellipse / triangle )
at a random position without any meaning.
but your job might be to draw a LANDSCAPE picture

  • ground
  • mountains
  • sky
  • sun

with something called ‘elements’ where he give examples

  • tree
  • house
  • +++
  • minimum 6 of this elements…

so one rect, ellipse, triangle is far from that idea?

but as i say, why should i know about your assignment,
ask your teacher.

1 Like