Loading...
Logo
Processing Forum
sujkha's Profile
5 Posts
7 Responses
0 Followers

Activity Trend

Last 30 days

Loading Chart...

Show:
Private Message
    Hi everyone, 


    I am trying to write a header for my blog with processing.js. It uses two different fonts, 
    so it has 

      font_name = loadFont("futura_light.vlw");
      font_pattern = loadFont("CourierNew.vlw");
    lines in it. Eerything works ok, but when I try exporting it in javascript mode, both the fonts are gone in all browsers I tried. Is there a way to fix that, or should i use the standart fonts?

    www.alsoko.net
    Hello!

    I try to get String data from JSON from  multicolr, and I cannot seem to extract it. I was using  this and  this as my reference, but everything I try returns an error.
    I include my JSON output lower down the post.
    I also include a piece of JavaScript which works for that web which inspired me.
    I guess the problem is that I dont adress the {objects} properly, but I am extremely new to this ( week of coding ) and i can't really use Java Docs or udnerstand how Java syntax for libraries applies for Processing.


    1. import org.json.*;

    2.   color colorOne = color(int(random(1, 255)), int(random(1, 255)), int(random(1, 255)));
    3.   String col = ( hex( colorOne, 6 ));

    4. String url = "http://labs.ideeinc.com/rest/?method=flickr_color_search&limit=60&offset=0&colors[0]=" + col + "&weights[0]=1";

    5. void setup() {
    6.   getOJ();
    7.   };


    8. void getOJ() {
    9.   try {
    10.     JSONObject idee = new JSONObject(join(loadStrings(url), ""));
    11.     //println(idee.toString(2));
    12.       
    13.     JSONArray results = idee.getJSONArray("result");
    14.     //println("results: " + results.toString(2) );
    15.     String filepath = idee.getString("filepath");
    16.     // I also tried
    17.     // String filepath = results.getString("filepath");
    18.     

    19.   
    20.   }

    21.   catch (JSONException e) {
    22.     println ("json parsing error");
    23.   };

    24.   
    25. };
          JSON:
    1. {
    2.   "error": [],
    3.   "method": "flickr_color_search",
    4.   "result": [
    5.     {
    6.       "filepath": "images_08/___________________________________________________202507602.jpg",
    7.       "height": 240,
    8.       "id": "202507602",
    9.       "photosite": "http://www.flickr.com/photos/62824001@N00/202507602",
    10.       "score": "99.30",
    11.       "width": 180,
    12.       "x": 0,
    13.       "y": 0
    14.     },
    15.     {
    16.       "filepath": "images_16/____________________________________________________65136343.jpg",
    17.       "height": 171,
    18.       "id": "65136343",
    19.       "photosite": "http://www.flickr.com/photos/94778205@N00/65136343",
    20.       "score": "95.70",
    21.       "width": 240,
    22.       "x": 0,
    23.       "y": 0
    24.     },
    25.     // Skipped a lot of same JSON objects
    26.     {
    27.       "filepath": "images_04/__________________________________________________2052555864.jpg",
    28.       "height": 180,
    29.       "id": "2052555864",
    30.       "photosite": "http://www.flickr.com/photos/36045027@N00/2052555864",
    31.       "score": "84.90",
    32.       "width": 240,
    33.       "x": 0,
    34.       "y": 0
    35.     },
    36.     {
    37.       "filepath": "images_14/___________________________________________________471046850.jpg",
    38.       "height": 180,
    39.       "id": "471046850",
    40.       "photosite": "http://www.flickr.com/photos/24509941@N00/471046850",
    41.       "score": "84.80",
    42.       "width": 240,
    43.       "x": 0,
    44.       "y": 0
    45.     }
    46.   ],
    47.   "status": "ok"
    48. }
          JS:
    1.       
    2. // Script author peko [peko@gasubasu.com]
    3. // http://gasubasu.com


    4. importPackage(java.net); 
    5. importPackage(java.io); 

    6. var bg='FFFFFF';

    7. var item = document.selectedItems[0]; 
    8. var color = item.fillColor;
    9. var R = (Math.round(color.red  *255)).toString(16); if (R.length<2) R='0'+R;
    10. var G = (Math.round(color.green*255)).toString(16); if (G.length<2) G='0'+G;
    11. var B = (Math.round(color.blue *255)).toString(16); if (B.length<2) B='0'+B;
    12. var hex = R+G+B;

    13. if (item && hex) {

    14.     var url = new URL('http://labs.ideeinc.com/coloursearch/services/rest/?method=color.search&quantity=50&page=0&colors='+bg+','+hex+'&imageset=flickr');
    15.     var stream = new DataInputStream(url.openStream());
    16.     var json = '';
    17.     var line;
    18.     while ((line = stream.readLine()) != null) {
    19.         json += line;
    20.     };
    21.     var data = Json.decode(json);
    22.     var i = 0;
    23.     for (n in data.result) {
    24.         url = new java.net.URL(data.result[n][1]); 
    25.         var image = new PlacedFile(url);

    26.         image.bounds.width  = 80;
    27.         image.bounds.height = 80;
    28.         image.bounds.center = new Point(i*81, Math.floor(i/10)*81);

    29.         document.redraw(); 
    30.         i++;
    31.     }
    32. }