 |
Author |
Topic: String to float? (Read 393 times) |
|
_C
|
String to float?
« on: Oct 25th, 2004, 12:57pm » |
|
hi lets say you want to loadStrings() of an parsed ai-file, which contains vector points. then split the String then you have at every odd position the x and at every even position the y coordinates of a point. the only problem i got so far is: how do i convert the Strings in the String[] array into floats/integers? thanks for any help christian
|
|
|
|
michael05
|
Re: String to float?
« Reply #1 on: Oct 25th, 2004, 1:36pm » |
|
hi c it should work with String sValue = "0.99867434"; float fValue = Float.parseFloat(sValue.trim()); i added the sValue.trim() to prevent errors if you get the string-data dynamically from i.e. a website or a textfile. it cuts the whitespaces.
|
°°°°°°°°°°°°°°°°°°°° http://www.m05.de
|
|
|
_C
|
Re: String to float?
« Reply #2 on: Oct 25th, 2004, 1:53pm » |
|
hi michael thank you, that is great. now i only have to consider a method to a. get the data into p5 by automation b. how to draw by which command the outline data bye c
|
|
|
|
_C
|
Re: String to float?
« Reply #3 on: Oct 25th, 2004, 10:40pm » |
|
ok, this is an unusual way but the only one i know so far, working only for closed shapes: a. get some vector outline shape of a picture b. export it as .ai c. look through the .ai file and copy the points into a .txt file removing all non-float elements like chars; i think they are there to tell the parser element that forms are closed eg. d. save this file in the 'data' folder of your project e. use the following class to generate some shape out of the vector data: Code: class Point { float x,y,z; Point(float _x, float _y, float _z) { x=_x; y=_y; z=_z; } Point(float _x, float _y) { x=_x; y=_y; z=0; } Point(Point p) { x=p.x; y=p.y; z=p.z; } } class Outline { String name; String aiList[]; String aiListJoined; String aiListSplit[]; float fList[]; Point p; Point initP; float scales; Outline(String _name, Point _p, float _scales) { p=new Point(_p); initP= new Point(p); //ursprung name=_name; aiList = loadStrings(name); aiListJoined = join(aiList, " "); aiListSplit = split(aiListJoined, " "); fList = new float[aiListSplit.length]; initfList(); scales=_scales; } void initfList() { for(int i=0; i<aiListSplit.length; i++) { fList[i] = Float.parseFloat(aiListSplit[i]); //print(fList[i]+" "); } } void draw() { push(); //translate(width/2, height/2, 0); rotateZ(degrees(90)); scale(scales); for(int i=1; i<fList.length-3; i+=2) { beginShape(POLYGON); vertex( fList[i], fList[i+1]); vertex( fList[i+2], fList[i+3] ); endShape(); } pop(); } } |
|
|
« Last Edit: Oct 25th, 2004, 10:46pm by _C » |
|
|
|
|
|