wardd13
2006.10.13, 03:33 AM
Guys,
Just to show you I've used your advice I put the code I've developed so far below.
Now I'm looking for a mouse routine I can't quite get a handle on.
In METAL I had a procedure named GetAClick that I called when I wanted the program to wait for a mouse click and then return with the x and y coords.
Can you help me out with this?
Thanks for your time,
d ward
PImage MandMs[];
int Box[];
int Bag[];
int Cx[];
int Cy[];
int Guess[];
int Actual[];
int Diffs[];
boolean NewSet;
int SetsPicked;
void setup()
{
size (700,500);
background(0);
MandMs = new PImage[7];
MandMs[1] = loadImage("Red.jpg");
MandMs[2] = loadImage("Green.jpg");
MandMs[3] = loadImage("Blue.jpg");
MandMs[4] = loadImage("Brown.jpg");
MandMs[5] = loadImage("Yellow.jpg");
MandMs[6] = loadImage("Check.jpg");
Box = new int[101];
Actual = new int[6];
Bag = new int[21];
Cx = new int[21];
Cy = new int[21];
MainProgram();
}
void MainProgram()
{
SetButtons();
MakeBox();
MakeBag();
PickCoords();
ShowBag();
}
void draw(){
}
void ShowBag()
{
for (int i=1; i<=20; i++)
{
image(MandMs[Bag[i]], Cx[i]*50, Cy[i]*50);
}
}
void PickCoords()
{
int SetsPicked;
int Newx;
int Newy;
boolean NewSet;
int CxTemp, CyTemp;
for (int i=1; i<=20; i++)
{
Cx[i]=0;
Cy[i]=0;
}
SetsPicked = 0;
while (SetsPicked <= 19)
{
CxTemp = round(random(11))+1;
CyTemp = round(random(5))+1;
NewSet = true;
for (int i=1; i<=SetsPicked; i++)
{
if (CxTemp == Cx[i] && CyTemp == Cy[i])
{
NewSet=false;
}
}
if(NewSet==true)
{
SetsPicked = SetsPicked + 1;
Cx[SetsPicked] = CxTemp;
Cy[SetsPicked] = CyTemp;
}
}
for (int i=1; i<=20; i++)
{
print (Cx[i]+" "+Cy[i]+"---");
}
}
void MakeBag()
{
for (int i=1; i<=20; i++)
{
Bag[i]=0;
}
for (int i=1; i<=20; i++)
{
int n = round(random(100));
Bag[i]=Box[n];
}
}
void MakeBox()
{
for (int i=0; i<100; i++)
{
Box[i]=0;
}
int a,b,c,d,e;
a=0;
b=0;
c=0;
d=0;
e=0;
while (a+b+c+d+e!=100)
{
a = round(random(1,50));
b = round(random(1,50));
c = round(random(1,50));
d = round(random(1,50));
e = round(random(1,50));
}
Actual[1]=a;
Actual[2]=b;
Actual[3]=c;
Actual[4]=d;
Actual[5]=e;
for (int i=1; i<=a; i++)
{
Box[i] = 1;
}
for (int i=a+1; i<=a+b; i++)
{
Box[i] = 2;
}
for (int i=a+b+1; i<=a+b+c; i++)
{
Box[i] = 3;
}
for (int i=a+b+c+1; i<=a+b+c+d; i++)
{
Box[i] = 4;
}
for (int i=a+b+c+d+1; i<=a+b+c+d+e; i++)
{
Box[i] = 5;
}
}
void SetButtons()
{
image(MandMs[1],200,450);
image(MandMs[2],250,450);
image(MandMs[3],300,450);
image(MandMs[4],350,450);
image(MandMs[5],400,450);
image(MandMs[6],450,450);
}
/*void DrawMs()
{
for(int i=0; i<800; i=i+50) {
for(int j=0; j<600; j=j+50){
int m = round(random(4))+1;
image(MandMs[m], i, j);
}
}
}
*/
Just to show you I've used your advice I put the code I've developed so far below.
Now I'm looking for a mouse routine I can't quite get a handle on.
In METAL I had a procedure named GetAClick that I called when I wanted the program to wait for a mouse click and then return with the x and y coords.
Can you help me out with this?
Thanks for your time,
d ward
PImage MandMs[];
int Box[];
int Bag[];
int Cx[];
int Cy[];
int Guess[];
int Actual[];
int Diffs[];
boolean NewSet;
int SetsPicked;
void setup()
{
size (700,500);
background(0);
MandMs = new PImage[7];
MandMs[1] = loadImage("Red.jpg");
MandMs[2] = loadImage("Green.jpg");
MandMs[3] = loadImage("Blue.jpg");
MandMs[4] = loadImage("Brown.jpg");
MandMs[5] = loadImage("Yellow.jpg");
MandMs[6] = loadImage("Check.jpg");
Box = new int[101];
Actual = new int[6];
Bag = new int[21];
Cx = new int[21];
Cy = new int[21];
MainProgram();
}
void MainProgram()
{
SetButtons();
MakeBox();
MakeBag();
PickCoords();
ShowBag();
}
void draw(){
}
void ShowBag()
{
for (int i=1; i<=20; i++)
{
image(MandMs[Bag[i]], Cx[i]*50, Cy[i]*50);
}
}
void PickCoords()
{
int SetsPicked;
int Newx;
int Newy;
boolean NewSet;
int CxTemp, CyTemp;
for (int i=1; i<=20; i++)
{
Cx[i]=0;
Cy[i]=0;
}
SetsPicked = 0;
while (SetsPicked <= 19)
{
CxTemp = round(random(11))+1;
CyTemp = round(random(5))+1;
NewSet = true;
for (int i=1; i<=SetsPicked; i++)
{
if (CxTemp == Cx[i] && CyTemp == Cy[i])
{
NewSet=false;
}
}
if(NewSet==true)
{
SetsPicked = SetsPicked + 1;
Cx[SetsPicked] = CxTemp;
Cy[SetsPicked] = CyTemp;
}
}
for (int i=1; i<=20; i++)
{
print (Cx[i]+" "+Cy[i]+"---");
}
}
void MakeBag()
{
for (int i=1; i<=20; i++)
{
Bag[i]=0;
}
for (int i=1; i<=20; i++)
{
int n = round(random(100));
Bag[i]=Box[n];
}
}
void MakeBox()
{
for (int i=0; i<100; i++)
{
Box[i]=0;
}
int a,b,c,d,e;
a=0;
b=0;
c=0;
d=0;
e=0;
while (a+b+c+d+e!=100)
{
a = round(random(1,50));
b = round(random(1,50));
c = round(random(1,50));
d = round(random(1,50));
e = round(random(1,50));
}
Actual[1]=a;
Actual[2]=b;
Actual[3]=c;
Actual[4]=d;
Actual[5]=e;
for (int i=1; i<=a; i++)
{
Box[i] = 1;
}
for (int i=a+1; i<=a+b; i++)
{
Box[i] = 2;
}
for (int i=a+b+1; i<=a+b+c; i++)
{
Box[i] = 3;
}
for (int i=a+b+c+1; i<=a+b+c+d; i++)
{
Box[i] = 4;
}
for (int i=a+b+c+d+1; i<=a+b+c+d+e; i++)
{
Box[i] = 5;
}
}
void SetButtons()
{
image(MandMs[1],200,450);
image(MandMs[2],250,450);
image(MandMs[3],300,450);
image(MandMs[4],350,450);
image(MandMs[5],400,450);
image(MandMs[6],450,450);
}
/*void DrawMs()
{
for(int i=0; i<800; i=i+50) {
for(int j=0; j<600; j=j+50){
int m = round(random(4))+1;
image(MandMs[m], i, j);
}
}
}
*/