|
Author |
Topic: Converting a String to a Float (Read 335 times) |
|
st33d
|
Converting a String to a Float
« on: Jun 2nd, 2004, 1:10am » |
|
I'm in the early stages of developing a little surrealist drawing program. Previously I was unable to have users enter parameters into it because Processing doesn't seem to have a text input command so I wrote some JavaScript that uses document.write('<tag>'); to build the html and query the user, thus putting param tags in as it builds the page. Which made me feel clever until I tried to find out how to convert strings into floats. I try to export the thing and it won't have it. It says there's an error during export. It's a bloody simple program so what is it I'm doing wrong? code- String randxo= param("randxage"); Float randx = float.parseFloat(randxo); String randyo= param("randyage"); Float randy = float.parseFloat(randyo); String marko= param("markage"); int marks = Integer.parseInt(marko); int mem = 4; size(400,400); background(255, 255, 255); stroke(0); int [] x=new int[mem]; int [] y=new int[mem]; for(int j=0; j<(mem); j++) { x[j]=int (noise((randx*j),(randy*PI))*width); y[j]=int (noise((randx*PI),(randy*j))*height); } for(int i=1; i<marks; i++) { int choice=int (noise(randx,i)*3); for(int j=1; j<(mem); j++) { x[j-1]=x[j]; y[j-1]=y[j]; } x[mem-1]=int (noise((randx*i),(randy*PI))*width); y[mem-1]=int (noise((randx*PI),(randy*i))*height); print(noise((randx*i),(randy*PI))*width); stroke ((noise(randy*i)*255),(noise(randy*i)*255),(noise(randy*i)*255)); if (choice==0){ point (x[3],y[3]); } if (choice==1){ line (x[2],y[2],x[3],y[3]); } if (choice==2){ bezier (x[2],y[2],x[0],y[0],x[1],y[1],x[3],y[3]); } }
|
I could murder a pint.
|
|
|
arielm
|
Re: Converting a String to a Float
« Reply #1 on: Jun 2nd, 2004, 2:13am » |
|
the problem seems to come from this syntax: Float randy = float.parseFloat(randyo); 1) it should be Float.parseFloat() 2) Float.parseFloat() is returning a float, so it should be: float randy = Float.parseFloat(randyo); but... if you want your applet to work on most of the browsers out there (i.e. using the old 1.1 microsoft vm), this one won't work anyway cause it's "here since 1.2" one syntax that will work for sure: float randy = Float.valueOf(randyo).floatValue();
|
Ariel Malka | www.chronotext.org
|
|
|
st33d
|
Re: Converting a String to a Float
« Reply #2 on: Jun 2nd, 2004, 2:35am » |
|
Mucking Farvelous, I never would have figured that out in years. It exports okay and JavaScript param handover works beautifully. Thank you with knobs on. In case anyone needs to know how to ask users for params here's the page that went with my applet just remember that document.write doesn't like the use of the return key (untidy I know, if anyone's got it neater, pass it on). html- <html> <head> <title>auto1 : Built with Processing</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script language="JavaScript"> var marks = prompt ("Enter Quantity of Marks (try not to be ambitious):", ""); var xrand = prompt ("Enter Number for Horizontal Randomness (can be a decimal fraction):", ""); var yrand = prompt ("Enter Number for Vertical Randomness (can be a decimal fraction):", ""); document.write ('<BODY BGCOLOR="#666666" text="#FFFFFF" link="#CCCC00" vlink="#CCCC00" alink="#999900"><center>'); document.write ('<table width="400" border="0" cellspacing="0" cellpadding="10"><tr><td><font face="Arial, Helvetica, sans-serif">Drawing Brain Mark 3.2</font>'); document.write ('</td></tr><tr><td><applet code="auto32" archive="auto32.jar" width=400 height=400><param name="markage" value='+marks+'>'); document.write ('<param name="randxage" value='+xrand+'><param name="randyage" value='+yrand+'></applet>'); document.write ('</td></tr><tr><td><font size="2" face="Arial, Helvetica, sans-serif">Marks: '+marks+' '+'randx: '+xrand+' randy: '+yrand+' '+'<a href="../index.html">back</a></font>'); document.write ('</td></tr><tr><td><a href="auto32.pde">'); document.write ('<font face="Arial, Helvetica, sans-serif" size="2">Source code</font></a></td></tr>'); document.write ('<tr><td><font size="2" face="Arial, Helvetica, sans-serif">Built with <a href="http://processing.org">Processing</a></font></td& gt;</tr></table></center></body>'); </script> </html>
|
I could murder a pint.
|
|
|
|