Subdomain Posts
Lisp | 3 days ago
None | 4 days ago
Lisp | 5 days ago
Lisp | 6 days ago
Lisp | 7 days ago
Lisp | 7 days ago
Lisp | 7 days ago
Lisp | 7 days ago
Lisp | 7 days ago
Lisp | 7 days ago
Recent Posts
None | 27 sec ago
C | 2 min ago
None | 3 min ago
None | 4 min ago
PHP | 6 min ago
None | 7 min ago
PHP | 7 min ago
None | 8 min ago
None | 8 min ago
XML | 9 min ago
Sitereport
Find cool info about any domain on the internet?
visit sitereport
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
Learn a little bit about the new Pastebin.com on our help page. hide message
By PhiLho on the 24th of Jul 2008 03:57:10 PM Download | Raw | Embed | Report
  1. /**
  2. Example of Processing sketch using my DataUpload class.
  3. Just a demo / test of that class.
  4.  
  5. by Philippe Lhoste <PhiLho(a)GMX.net> http://Phi.Lho.free.fr & http://PhiLho.deviantART.com
  6. */
  7. /* File/Project history:
  8.  1.00.000 -- 2008/07/23 (PL) -- Creation.
  9. */
  10. /* Copyright notice: For details, see the following file:
  11. http://Phi.Lho.free.fr/softwares/PhiLhoSoft/PhiLhoSoftLicence.txt
  12. This program is distributed under the zlib/libpng license.
  13. Copyright (c) 2008 Philippe Lhoste / PhiLhoSoft
  14. */
  15. //~ import com.sun.image.codec.jpeg.*;
  16. import javax.imageio.*;
  17. import javax.imageio.stream.*;
  18. import java.awt.image.BufferedImage;
  19.  
  20. final color START_COLOR_TOP    = #335533;
  21. final color START_COLOR_BOTTOM = #55AA55;
  22. final color END_COLOR_TOP      = #333355;
  23. final color END_COLOR_BOTTOM   = #5555AA;
  24.  
  25. final int MAX_FRAME_NB = 120;
  26.  
  27. float x = 0, y = 0;
  28. float size = 0;
  29. float top = 0, bottom = 0;
  30. float dx = 0, dy = 0;
  31.  
  32. String currentFormat = "png";
  33.  
  34. color GetRandomColor()
  35. {
  36.   return color(random(0, 256), random(0, 256), random(0, 256));
  37. }
  38. color InterpolateColor(color startC, color endC)
  39. {
  40.   return lerpColor(startC, endC, (float) frameCount / (float) MAX_FRAME_NB);
  41. }
  42.  
  43. void DrawBackground()
  44. {
  45.   color topColor = InterpolateColor(START_COLOR_TOP, END_COLOR_TOP);
  46.   color bottomColor = InterpolateColor(START_COLOR_BOTTOM, END_COLOR_BOTTOM);
  47.   for (int line = 0; line < height; line++)
  48.   {
  49.     color sc = lerpColor(topColor, bottomColor, (float) line / (float) height);
  50.     stroke(sc);
  51.     line(0, line, width - 1, line);
  52.   }
  53. }
  54.  
  55. void setup()
  56. {
  57.   smooth();
  58.   frameRate(24);
  59.   size(400, 400);
  60. }
  61.  
  62. void draw()
  63. {
  64.   DrawBackground();
  65.  
  66.   if (frameCount % 24 == 0)
  67.   {
  68.     fill(GetRandomColor());
  69.     stroke(GetRandomColor());
  70.     strokeWeight(random(1, 8));
  71.     x = random(100, 300); y = random(150, 350);
  72.     size = random(20, 100);
  73.     top = random(20, 80); bottom = random(20, 80);
  74.     dx = random(10, 50); dy = random(20, 60);
  75.   }
  76.  
  77.   beginShape();
  78.  
  79.   // The heart, symmetrical around vertical axis
  80.   // Anchor point (highest sharp point)
  81.   vertex(x, y);
  82.   // Top left part
  83.   bezierVertex(
  84.       x, y - top,
  85.       x - size, y - top,
  86.       x - size, y);
  87.   // Bottom left part
  88.   bezierVertex(
  89.       x - size, y + top,
  90.       x - dx, y + bottom - dy,
  91.       x, y + bottom);
  92.   // Bottom right part
  93.   bezierVertex(
  94.       x + dx, y + bottom - dy,
  95.       x + size, y + top,
  96.       x + size, y);
  97.   // Top right part
  98.   bezierVertex(
  99.       x + size, y - top,
  100.       x, y - top,
  101.       x, y);
  102.  
  103.   endShape();
  104. }
  105.  
  106. void keyPressed()
  107. {
  108.   if (key == 'j')
  109.   {
  110.     currentFormat = "jpg";
  111.   }
  112.   if (key == 'J')
  113.   {
  114.     currentFormat = "jpeg";
  115.   }
  116.   if (key == 'p')
  117.   {
  118.     currentFormat = "png";
  119.   }
  120.   if (key == 's')
  121.   {
  122.     DataUpload du = new DataUpload();
  123.     boolean bOK = false;
  124.     // Upload the currently displayed image with a fixed name, and the chosen format
  125.     if (currentFormat.equals("png"))
  126.     {
  127.       bOK = du.UploadImage("snapshot." + currentFormat, (BufferedImage) g.image);
  128.     }
  129.     else
  130.     {
  131.       // We need a new buffered image without the alpha channel
  132.       BufferedImage imageNoAlpha = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
  133.       loadPixels();
  134.       imageNoAlpha.setRGB(0, 0, width, height, g.pixels, 0, width);
  135.       bOK = du.UploadImage("snapshot." + currentFormat, imageNoAlpha);
  136.     }
  137.     if (!bOK)
  138.       return; // Some problem on Java side. Do nothing
  139.  
  140.     // Get the answer of the PHP script
  141.     int rc = du.GetResponseCode();
  142.     String feedback = du.GetServerFeedback();
  143.     println("----- " + rc + " -----\n" + feedback + "---------------");
  144.  
  145.     // Extract the URL of the image from the PHP feedback
  146.     // I use the hard way, the script could just answer the right URL...
  147.     String[] m = match(feedback, "<img src='([^']+)'");
  148.     if (m != null)  // Found!
  149.     {
  150.       println("\n=> " + m[0] + "\n");
  151.       // Open in a popup window
  152.       link(m[0], "UploadedImage");
  153.     }
  154.   }
  155. }
Submit a correction or amendment below. [ previous version ] | [ difference ] | Make A New Post
To highlight particular lines, prefix each line with @h@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: