 |
Author |
Topic: Placing an Array (Read 610 times) |
|
inadaze
|
Placing an Array
« on: Oct 31st, 2004, 4:29pm » |
|
Hi, I have a class of circles that are drawn each time the user clicks the screen. I would like it so that when the user has nine circles drawn, lines are drawn automatically connecting the circles. I know you have to place the x and y of each drawn circle in an array so that the lines can be drawn, but where would I place the array? Do I place it in the circle class or in a line class or in my mainGame class? Or do I just place it outside of the class definitions? Thanks Jay
|
|
|
|
fjen
|
Re: Placing an Array
« Reply #1 on: Oct 31st, 2004, 7:10pm » |
|
class of circles? or circle class? if your class has all the circles in it already, then there is no need for you to store anything else ... if it's a circle class (that represents one circle) then why don't you just make an array out of that? like: Circle[] circles = new Circle[5]; int cindex = -1; // mouseReleased: cindex++; if (cindex < circles.length) circle[cindex] = new Circle(x,y); // and so on .. so, there's no need to extra store the coordinates, just make sure circles can be accessed from where it's called (probably loop() -> outside the class definitions).
|
« Last Edit: Oct 31st, 2004, 7:11pm by fjen » |
|
|
|
|
inadaze
|
Re: Placing an Array
« Reply #2 on: Oct 31st, 2004, 11:37pm » |
|
I have a class that is calleds circles that I use as a blueprint to create circles with specific colors and size when the user clicks. What I would like to store is where the user clicks and creates these circles. Jay
|
|
|
|
fjen
|
Re: Placing an Array
« Reply #3 on: Nov 1st, 2004, 2:44am » |
|
well, then just store the user-click as coordinates (mouseX, mouseY) in the circle-class when constructing it ( new myCircleClass(mouseX,mouseY,myColor) and have these arranged into an array. just as i posted before. if you post some code i can be more specific .. /F
|
|
|
|
inadaze
|
Re: Placing an Array
« Reply #4 on: Nov 2nd, 2004, 1:27am » |
|
I tried to do it on my own but it doesn't work. Here is my code: /*Jason Smalridge DFAR 451 - Tangible Media Oct. 30 2004 ----------------------------------------------------------------------- The Palm Reader 0.1*/ //Instantiate a new object of type gameLauncher(). GameLauncher currentGame = new GameLauncher(); //===================================================================== //Class definitions //Game Container class GameLauncher { //Properties //Constructor GameLauncher(){ } //Methods } //---------------------------------------------------- //Picture Container class Picture { //properties int Xpos; int Ypos; int PicLength; int PicWidth; String FileName; boolean blackAndWhite; //Constructor Picture(int Xpos,int Ypos,int PicLength,int PicWidth,String FileName){ this.Xpos = Xpos; this.Ypos = Ypos; this.PicLength = PicLength; this.PicWidth = PicWidth; this.FileName = FileName; } //Methods void draw() { BImage Palm; Palm = loadImage(this.FileName); image(Palm,this.Xpos,this.Ypos,this.PicLength,this.PicWidth); } } //------------------------------------------------------- //Moveable points class LinePoint { //properties int Xpos; int Ypos; int size; int lineType; int posInLine; color pointColor; int counter = 0; color redPoint = color(200,0,0); color greenPoint = color(0,200,0); color bluePoint = color(0,0,200); //Constructor LinePoint(int Xpos,int Ypos,int size,int counter) { this.Xpos = Xpos; this.Ypos = Ypos; this.size = size; this.lineType = lineType; this.posInLine = posInLine; this.pointColor = pointColor; this.counter = counter; this.changeColor(this.counter); } //methods void draw() { strokeWeight(1); fill(this.pointColor); ellipse(this.Xpos,this.Ypos,this.size,this.size); } //method to change the point color after a certain amount are drawn void changeColor(int counter) { if(counter == 1) { this.pointColor = this.redPoint; }else if(counter == 2) { this.pointColor = this.greenPoint; }else if(counter == 3) { this.pointColor = this.bluePoint; } } } / ======================================================================== //Setup + Variables + Functions + Arrays void setup() { background(0); size(500,500); ellipseMode(CENTER_DIAMETER); rectMode(CENTER_DIAMETER); imageMode(CENTER_DIAMETER); Picture myPalmPicture = new Picture(250,250,500,500,"myPalm.jpg"); myPalmPicture.draw(); } //Variables //variable to count how many points have been drawn int clickCounter = 0; //variable to control the color of the circle(1 = red, 2 = green, 3 = blue); int clickCounterChanger = 0; //Functions void pointColorControls(){ clickCounter = clickCounter + 1; if(clickCounter <= 3) { clickCounterChanger = 1; }else if(clickCounter >= 4 && clickCounter <= 6) { clickCounterChanger = 2; }else if(clickCounter >= 7 && clickCounter <= 9) { clickCounterChanger = 3; } } //Arrays //******************************************************************** //Controls void mousePressed(){ //Make sure the user cannot have more than 9 points if(clickCounter < 9){ pointColorControls(); LinePoint myPoint = new LinePoint(mouseX,mouseY,10,clickCounterChanger); myPoint.draw(); } //if the user is finished, draw the connecting lines } void loop() { }
|
|
|
|
fjen
|
Re: Placing an Array
« Reply #5 on: Nov 2nd, 2004, 5:37am » |
|
just a hint, don't do this: //Methods void draw() { BImage Palm; Palm = loadImage(this.FileName); image(Palm,this.Xpos,this.Ypos,this.PicLength,this.PicWidth); } make BImage Palm a property, load it in the constructor, just do drwing in draw ... file-access is not fast, this might slow down you app or cause other problems if called in loop over and over again.
|
« Last Edit: Nov 2nd, 2004, 5:38am by fjen » |
|
|
|
|
fjen
|
Re: Placing an Array
« Reply #6 on: Nov 2nd, 2004, 5:45am » |
|
this is just nice! check this line: Code: / ======================================================================== //Setup + Variables + Functions + Arrays |
| it should give an error since the comment is missing it's second slash, but it doesn't. ? make the line start with // then it works. /F
|
|
|
|
inadaze
|
Re: Placing an Array
« Reply #8 on: Nov 2nd, 2004, 4:07pm » |
|
Any ideas about how to set up an array to hold my point positions? As you can see I am not the greatest programmer in the world.=( Thanks Jay
|
|
|
|
fjen
|
Re: Placing an Array
« Reply #9 on: Nov 3rd, 2004, 12:11am » |
|
well, as i posted earlier, just keep your LinePoints in an array. // some examples of how it might look: LinePoint[] lines = new LinePoint[9]; // create empty array of size 9 (0-8 that is) ... lines[clickCounter] = new LinePoint( ...); //put one LinePoint into the array, at position clickCounter ... int x_line_3 = lines[3].Xpos; // read the XPos of LinePoint 4 ... i dont't have the time to fix/rewrite your code, you might wanna look up array-usage somewhere. here for example. /F
|
« Last Edit: Nov 3rd, 2004, 12:13am by fjen » |
|
|
|
|
inadaze
|
Re: Placing an Array
« Reply #10 on: Nov 3rd, 2004, 1:07am » |
|
Well, regardless of your limited time, I appreciate the time you have given to my problem. Hope I can figure things out. Thanks Jay
|
|
|
|
|