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 & HelpSyntax Questions › How to use println to write " or (
Page Index Toggle Pages: 1
How to use println to write " or ( (Read 421 times)
How to use println to write " or (
Feb 25th, 2009, 7:24pm
 
Hello, I'm new using Processing (or I'm new "again" in fact because I used it long ago), and I keep trying to print the symbol " or the parenthesis and I can't.
In fact, I would like to create a file where there will be a big amount of lines automatically created . There is the program I use :

PrintWriter output;
float x,y,z;
PFont font;

void setup(){
 output = createWriter("coord.pde");
 font = loadFont("Eureka-90.vlw");  
 size(500,500,P3D);
 noLoop();
 camera(0,0,100,
        0,0,0,
        0,1,0);
 stroke(0);

}

void draw()
{
 textFont(font,16);
 for(int i=0; i<100; i++)
 {
    x=random(-50,50);
    y=random(-50,50);
    z=random(-50,50);
    fill(255);
    text("jo",x,y,z);
    line(0,0,0,x,y,z);
    output.println("a"+","+x+","+y+","+z+")");    
    output.println("b"+","+x+","+y+","+z+")");    
 }

 println("fin--");
 }  

void mousePressed() {
 output.flush(); // Cliquer pour créer le fichier
 output.close();
 //Remplacer "a" par " text("jo" "
 //et "b" par " line'"jo" "
 exit();


And the lines that causes the problem are here : output.println("a"+","+x+","+y+","+z+")");    
output.println("b"+","+x+","+y+","+z+")");

because I would like to write : output.println("text("jo""+x+","+y+","+z+")")

but I can't.
Can someone help me please ?!
Re: How to use println to write " or (
Reply #1 - Feb 25th, 2009, 8:11pm
 
You print " with \" the ( should print just fine on it's own.
Re: How to use println to write " or (
Reply #2 - Feb 25th, 2009, 11:27pm
 
I'm sorry, I didn't really understand.
Moreover, Can you tell me how to "call" a program?
In fact, I have 2 files in my folder and I want to call the second one in the principal (executing all what is wrote in the second file like if it was directly written in the first file)?
Thanks for your answer

Ptijo


ps: Ok, I understood what you meant and I replace those lines by :
    output.println("text(\"jo\","+x+","+y+","+z+")");    
    output.println("line(0,0,0,"+x+","+y+","+z+")");
Re: How to use println to write " or (
Reply #3 - Feb 25th, 2009, 11:53pm
 
try this way :

output.println("text(\"jo\""+x+","+y+","+z+")");
Re: How to use println to write " or (
Reply #4 - Feb 26th, 2009, 7:27am
 
Beside your original problem, I think you use a wrong solution. A sketch can't compile another sketch (unless going great lengths). A more classical approach is to generate a data file (eg. in CSV format, for which Processing offers parsing functions) then to use this data to do something on screen.

J'espère que je suis clair... Smiley HTH.
Re: How to use println to write " or (
Reply #5 - Feb 26th, 2009, 8:46am
 
Ok, I didn't really understood (I have a very bad english), so you think I should create a CSV file that I would call in the other program?

Here is the principal program, I have also the data file(that is automatically created with the above program) :

int r = 100;
float t1, t2;
PFont font;
int l=0;

void setup()
{
 size(500,500,P3D);
 background(200);
 stroke(0);
 font = loadFont("Eureka-90.vlw");
 textFont(font,8);
}

void draw()
{
 lights();
 background(200);  

//Here I manually insert the lines which were in the data file, How to make otherwise please?!

text("jo",37.297913,48.94078,-28.680824);
line(0,0,0,37.297913,48.94078,-28.680824);
text("jo",7.151161,36.59278,-24.586279);
line(0,0,0,7.151161,36.59278,-24.586279);
line(0,0,0,-39.17318,-3.186924,17.654419);
text("jo",24.305038,14.645805,-4.409176);
[...]
line(0,0,0,24.305038,14.645805,-4.409176);
text("jo",8.098721,11.970192,28.96045);
line(0,0,0,8.098721,11.970192,28.96045);
text("jo",-44.684143,37.396683,-28.996187);
line(0,0,0,-44.684143,37.396683,-28.996187);

 t1=mouseX-250;
 t1=radians(t1);//t1=-t1;
 t1=map(t1,radians(-250),radians(250),0,PI);
 //println(t1);
 t2=mouseY-250;
 t2=radians(t2);t2=-t2;
 t2=map(t2,radians(-250),radians(250),-PI/2,PI/2);

 camera(r*cos(t1), r*sin(t2), 100,
          0.0, 0.0, 0.0,
          0.0, 1.0, 0.0);
  }
 
void mousePressed()
{
 if ((mousePressed==true)&&(l==0))
 {loop(); l=1;println(l);}
 if ((mousePressed==false)&&(l==1)){noLoop(); l=0;}
}
Re: How to use println to write " or (
Reply #6 - Feb 26th, 2009, 11:59am
 
Ton anglais est très bon... Smiley

I still think the approach is wrong. If you want to create a bunch of random stuff and use it consistently in the draw() routine, you just have to save it (in memory) in setup phase:
Code:
int r = 100;
float t1, t2;
PFont font;
int l=0;

int JO_NB = 100;
// I would use a PVector here instead, not important
float[] x = new float[JO_NB];
float[] y = new float[JO_NB];
float[] z = new float[JO_NB];

void setup()
{
size(500,500,P3D);
background(200);
stroke(0);
// Changed to avoid creating a font...
font = createFont("Verdana", 18);
textFont(font);

for (int i = 0; i < JO_NB; i++)
{
x[i] = random(-50,50);
y[i] = random(-50,50);
z[i] = random(-50,50);
}
}

void draw()
{
lights();
background(200);

for (int i = 0; i < JO_NB; i++)
{
text("jo", x[i], y[i], z[i]);
line(0, 0, 0, x[i], y[i], z[i]);
}

t1=mouseX-250;
// Etc., same code
}

If you really need persistence across runs, I can show how to use CSV.
Re: How to use println to write " or (
Reply #7 - Feb 26th, 2009, 12:11pm
 
Oh, that's very cool, it's a great idea, thanks.
I enjoy this approach to save each variable x[i] (and beacause I'm learning, I found it beautiful).
Thank you very much.
Ptijo
Page Index Toggle Pages: 1