We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Drawing machine, some help needed, basic I think.
Page Index Toggle Pages: 1
Drawing machine, some help needed, basic I think. (Read 619 times)
Drawing machine, some help needed, basic I think.
Apr 26th, 2009, 8:05am
 
[font=Verdana][/font]

Hi there, this is my first post so apologies if it's a) annoyingly simple or b) asking too much. Got to start to learn so here goes.

I'm currently learning processing and I'm kind of stuck or in need of a helping hand for my first "proper project" sketch as it were. Basically it's an X,Y plotter. There are some important conceptual and mechanical differences to a normal plotter but right now I'm just trying to sketch up a version to see if I can make happen on screen what I'd like to happen on a wall.

The basic plotter is made, though I have it set to not leave a mark at present. What I'm trying to figure now is how to get the cross-hair to draw a line. I'm thinking to make a shape (void ____) and then have a list of vertices that the cross hair would track, my question is how to make that happen, and also how to control the speed at which that happens.

I was thinking that I'd have to make the vertices into an array of points and that I'd step through that array with a mouseReleased command so that would control the speed. However ideally one keypress would be assigned to each void object and the speed that the crosshair tracked through it would be controlled in some other way, through the framerate?

What I don't want is what's on the animation tutorials where the program is calling frames from pre-existing files as whilst that could be made to look right it obviously wouldn't work when there's motors and real drawing points involved.

Many thanks for any suggestions, sorry if the code is a bit messy.

P.

//int counter; thinking that I might use this for tracking where the
//program is in a given array.

int [] xpos = new int [60]; //these are for the tracking object running just behind the drawing point.
int [] ypos = new int [60];
float x;
float y;
float targetX, targetY;
float easing = 0.2;

void setup ()
{
 size (800, 800);
 background (0);
 smooth();
 frameRate(120); //this is set at present just to make the easing work well, but
 //no doubt a ratio between the two is the important thing so could go up or down.
 noStroke();
 for (int i = 0; i < xpos.length; i++) {
   xpos[i] = 0;
   ypos[i] = 0;
 }
}
//processing site + library for text input.
//make vertices list and calls to that, show erasing device?

void draw () {
 background (0);
 fill(127,127);

 /*void mouseReleased()
 {
 counter = counter + 1;
 } This is something I was thinking to use to track through the array associated with a specific object
*/

 targetX = mouseX;
 float dx = targetX - x;
 if(abs(dx) > 1) {
   x += dx * easing;
 }

 targetY = mouseY;
 float dy = targetY - y;
 if(abs(dy) > 1) {
   y += dy * easing;
 }

 ellipse (x, 0, 20, 20);
 ellipse (x, 800, 20, 20);
 ellipse (0, y, 20, 20);
 ellipse (800, y, 20, 20);
 fill (63,63);

 fill(255);
 ellipse (x, y, 20, 20);
 stroke(125,125);
 line (x, 0, x, 800);
 line (0, y, 800, y);


 for (int i = 0; i < xpos.length-1; i++) {
   xpos[i] = xpos [i+1];
   ypos[i] = ypos [i+1];
 }

 xpos [xpos.length-1] = mouseX;
 ypos [ypos.length-1] = mouseY;

 for (int i = 0; i < xpos.length; i++) {
   noStroke();
   fill (200,20);
  // if(mousePressed) {
     ellipse (xpos [50], ypos [50], 15, 15);
   }
 }

Re: Drawing machine, some help needed, basic I think.
Reply #1 - Apr 26th, 2009, 8:36am
 
Not sure if it can be useful, but I once made a  sketchProgressiveDraw which shown slowly a drawing being drawn. It seems not so far of your needs.
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

Page Index Toggle Pages: 1