PJEvans
YaBB Newbies
Offline
Posts: 2
Re: Drawing machine, some help needed, basic I think.
Reply #2 - May 1st , 2009, 4:49am
Hi there, sorry for delayed response, been busy at the codeface as it were. Thanks for that code, it set me going on the right direction, am a lot further on now after some suggestions and help from tutors, all I need now is to get it not to skip through the path. Can't quite figure out why the if statement isn't really preventing the for loop from incrementing, which is the idea. Here's where I'm at, I've included the function I'm using at the end. import megamu.shapetween.*; Tween ani; float xNew,yNew,xOld,yOld; //list of floats float xCurrent=0; //two more which are now initialized float yCurrent=0; float[] xHistory = new float[3000]; //two arrays with 3000 spaces float[] yHistory = new float[3000]; int p=0; int q=0; int j=0; //boolean c = true; //float c = 0; //int counter = 0; int writing = 0; /* float [] [] theA = { {200, 600}, {400, 200},{600,600},{800,800},{200,300} }; */ float[] theAx = new float[3]; float[] theAy = new float[3]; void setup(){ size(800,800); smooth(); ani = new Tween(this, 180, Tween.FRAMES); ani.setDuration( 180, Tween.FRAMES); theAx [0] = 200.0; theAy [0] = 600.0; theAx [1] = 400.0; theAy [1] = 200.0; theAx [2] = 600.0; theAy [2] = 600.0; //ani.start(); for (int i=0; i<xHistory.length; i++) //initalizes the array with 0's { xHistory[i] = 0; yHistory[i] = 0; } } void draw(){ background(0); noStroke(); fill(255,255,255,255); ellipse(xNew, yNew, 10, 10); xCurrent = lerp( xOld, xNew, ani.time() ); //this is providing a linear interpolation calculated between xOld and xNew based on yCurrent = lerp( yOld, yNew, ani.time() ); //the increment provided by ani.time (between 0 and 1) xHistory[j] = xCurrent; //filling the array with this numbers provided by the lerp yHistory[j] = yCurrent; beginShape(LINES); for(int i=0; i<j; i++)// going through the array. { stroke(255, 255, 255, 200); strokeWeight(5); noFill(); vertex(xHistory[i], yHistory[i]); //from start position in the array vertex(xHistory[i+1], yHistory[i+1]); //to next position drawing the line left behind mr pink ellipse } endShape(); fill(255,100,255,250); noStroke(); ellipse(xCurrent, yCurrent,25,25); //the current just tells the ellipse to be constantly drawing at the point of the tween //println(writing); //println(xCurrent); // println(yCurrent); drawletter(); } //THIS IS WHERE IT DRAWS void keyPressed(){ // println(theAx.length); /*println(xCurrent); println(yCurrent); */ if (key == 'A'){ writing = 1; } if (key == 'B'){ writing = 2; } if (key == 'C'){ writing = 3; } } void mousePressed(){ ani.start(); j = j+1; //xNew = mouseX; //yNew = mouseY; xOld = xCurrent; yOld = yCurrent; xNew = mouseX; yNew = mouseY; } ------------------------------------------ DRAWLETTER function is as follows: void drawletter() { if (writing == 1) { ani.start(); j = j+1; // float c = ani.position(); //return ani.position(); xNew = theAx[0]; yNew = theAy[0]; //if (c = ani.position()) if ((xCurrent == theAx[p]) && (yCurrent == theAy[q])); //if we are not there yet! println("Here we are!!!!!!"); { // p++; // q++; for (int p=0; p < theAx.length; p++) //it's finding this and immediately going to end. { for (int q=0; q < theAy.length; q++) //println("Here we are again !!!!!!"); xNew = theAx[p]; yNew = theAy[q]; println("the x coord: "+ theAx[p] + " @ index: " + p); println("the y coord: " + theAy[q] + " @ index: " + q); println("xCurrent: "+ xCurrent); println("yCurrent: "+ yCurrent); xOld = xCurrent; yOld = yCurrent; // println("we are not there yet"); } } writing = 0; } // end writing if } // end drawletter