Really simple program, for a newbie.

hey, I'm trying to create a program that will prompt the user for 3 options and depending on the selection one out of the 3 codes excutes. Each his a draw or eclipse type. I'm fairly new to programming so any help will be appreciated.

My road block is at the prompting the users and some errors here and there. Here is what I have so far, not sure how to proceed. This was done in the processing app:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//code1

void setup(){
 size(1000,1000); 
 int answer = factorial(5); 
 println(answer); 
}

float angle = 0;
void draw(){
  angle = angle - 0.03;
  background(0);
  float xmover = 255*cos ( angle ) ;
  float ymover = 255*sin ( angle ) ;
  int xval = 20;
  int yval = 20;
  while (xval < 500){
   xval = xval + 40;
   while ( yval < 420  ) {
    yval = yval + 40;
    fill(128+ xmover/2, 128+ ymover/2, xval/2 - yval/2);
    ellipse(xval + xmover , yval + ymover , xmover/2,ymover/4);     
   } 
   yval = 20;
  }
}

int factorial(int input){
  int xval = 1;
  int fac = 1;
  while ( xval < input ){
   xval = xval + 1;
   fac = fac * xval;
   }
   return fac; 
}






//code 2


float x1 = 45;
float y1 = 145;
float x2 = 145;
float y2 = 245;
float speed1x = 3;
float speed2x = 4;
float speed1y = 5;
float speed2y = 4;
void setup(){
 size(500,500);
}


void draw(){
  ellipse(x1,y1, 150,150);
  ellipse(x2,y2,50,50);
  
  x1 = x1 + speed1x;
  x2 = x2 +  speed2x;
  y1 = y1 +  speed1y;
  y2 = y2 +  speed2y;
  
  if ( x1 > width ) speed1x = -4;
  if ( x2 > width ) speed2x = -2;
  if ( y1 > height) speed1y = -4;
  if ( y2 > height ) speed2y = -6;
  
  if ( x1 < 0 ) speed1x = 8;
  if ( x2 < 0 ) speed2x = 8;
  if ( y1 < 0) speed1y = 2;
  if ( y2 < 0 ) speed2y = 2;
  
  float distance =sqrt( (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) );
  if (  distance < 100) {
    speed2x = - speed2x; 
    speed2y = - speed2y; 
    speed1x = - speed1x; 
    speed1y = - speed1y; 
  }
  
}

//code3

PFont f;
String typing = "";
void setup(){
  size(500,500);
  f = createFont("Arial", 48);
  textFont(f);
}
int x = 50;
int y = 50;
void draw(){
  text(typing, mouseX, mouseY);
  for(int i = 0; i < 100; i++){
   line(x+i*10, y, i*10, 400) ;
  }
  
}
void keyPressed(){
  if( key > 32 && key < 126) {
    typing = typing + key;
    
  }
  if ( key == 8){
     println("in delete");
      background(100);
     typing = typing.substring(0, typing.length()-2);
  }
  if( key == 'p'){
    x++;
  }
  if( key == 'c'){
    background(100);
  }
  
}
What are the errors? And could you point out where in the code you're having trouble?
It's complaining about more than one setup so I'm trying to remove that. Each code was created in a separate session so I am trying to combine them into one and give the user a option between each to select .. Something like " What would you like to see? 1, 2 or 3? _ _ "

ok updated code..now just getting some overflow errors, how do I go about letting the user choose between each code?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
void setup(){
 size(1000,1000); 
 int answer = factorial(5); 
 println(answer); 
}

float angle = 0;
void draw(){
  angle = angle - 0.03;
  background(0);
  float xmover = 255*cos ( angle ) ;
  float ymover = 255*sin ( angle ) ;
  int xval = 20;
  int yval = 20;
  while (xval < 500){
   xval = xval + 40;
   while ( yval < 420  ) {
    yval = yval + 40;
    fill(128+ xmover/2, 128+ ymover/2, xval/2 - yval/2);
    ellipse(xval + xmover , yval + ymover , xmover/2,ymover/4);     
   } 
   yval = 20;
  }
}

int factorial(int input){
  int xval = 1;
  int fac = 1;
  while ( xval < input ){
   xval = xval + 1;
   fac = fac * xval;
   }
   return fac; 
}









float x1 = 45;
float y1 = 145;
float x2 = 145;
float y2 = 245;
float speed1x = 3;
float speed2x = 4;
float speed1y = 5;
float speed2y = 4;


{
  ellipse(x1,y1, 150,150);
  ellipse(x2,y2,50,50);
  
  x1 = x1 + speed1x;
  x2 = x2 +  speed2x;
  y1 = y1 +  speed1y;
  y2 = y2 +  speed2y;
  
  if ( x1 > width ) speed1x = -4;
  if ( x2 > width ) speed2x = -2;
  if ( y1 > height) speed1y = -4;
  if ( y2 > height ) speed2y = -6;
  
  if ( x1 < 0 ) speed1x = 8;
  if ( x2 < 0 ) speed2x = 8;
  if ( y1 < 0) speed1y = 2;
  if ( y2 < 0 ) speed2y = 2;
  
  float distance =sqrt( (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) );
  if (  distance < 100) {
    speed2x = - speed2x; 
    speed2y = - speed2y; 
    speed1x = - speed1x; 
    speed1y = - speed1y; 
  }
  
}



PFont f;
String typing = "";
{
  size(500,500);
  f = createFont("Arial", 48);
  textFont(f);
}
int x = 50;
int y = 50;
{
  text(typing, mouseX, mouseY);
  for(int i = 0; i < 100; i++){
   line(x+i*10, y, i*10, 400) ;
  }
  
}
void keyPressed(){
  if( key > 32 && key < 126) {
    typing = typing + key;
    
  }
  if ( key == 8){
     println("in delete");
      background(100);
     typing = typing.substring(0, typing.length()-2);
  }
  if( key == 'p'){
    x++;
  }
  if( key == 'c'){
    background(100);
  }
  
}
Anyone? I just want to turn all these codes into a KeyPressed action now so if a user pressed 1, it goes to code 1 and executes and so on...anyone? :/
Topic archived. No new replies allowed.