Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

New beginner needs help

$
0
0
Hi, I discovered Processing a couple of weeks ago, and I am really interested to learn it. My first attempt is to try to visualize sound. So far I have only managed to create a pattern based on the ellipse... 

I have two questions for you:
1. I want to experiement more with the pattern, but my Processing skills are limiting me. Do you have any suggestions for what I might add to make it more visual interesting?

2. I also want to export a pdf when mousePressed, but the exported pdf looks really bad;  it saves the pdf in a square (35mmx35mm) and it only saves parts of the graphics. Do you know what I do wrong?

I really appreciate if you would help me.

  1. import processing.pdf.*;

  2. PGraphicsPDF pdf;

  3. import ddf.minim.*;
  4. float x, y, r, g, b, radius;
  5. int timer;
  6. Minim minim;
  7. AudioInput input;
  8.  
  9. void setup () {
  10. pdf = (PGraphicsPDF)beginRecord(PDF, "Lines.pdf");
  11. beginRecord(pdf);
  12.   size (1620, 440);
  13.   smooth();
  14.   fill (0);
  15.   strokeWeight(0.7);
  16.    
  17.  
  18.   x = 0;
  19.   y = 20;
  20.    
  21.   minim = new Minim (this);
  22.   input = minim.getLineIn (Minim.STEREO, 512);
  23. }
  24.  
  25. void draw () {
  26.   
  27.   x = constrain(x,0,width);
  28.   y = constrain(y,0,height);
  29.   float dim = input.mix.level () * width;
  30.   x += input.mix.level () * 20;
  31. // use frameCount to move x, use modulo to keep it within bounds
  32.   x = frameCount % width;
  33.  
  34.   
  35.   if (millis() - timer >= 5000) {
  36.     y += 10;
  37.     timer = millis();
  38.   }
  39.  
  40.   //change the red color component
  41.   r = noise(frameCount * 1) * 255;
  42.  
  43.   //change the green color component
  44.   g = frameCount % 255;
  45.  
  46.   // change the blue color component
  47.   b = 255 - noise(1 + frameCount * 1) * 255;
  48.  
  49.   // use frameCount and noise to change the radius
  50.   radius = noise(frameCount * 1) * 0.001;
  51.  
  52.   color c = color(r, g, b);
  53.   stroke(c);
  54.   ellipse(x, y, dim, dim); 

  55.    
  56.   if (x > width) {
  57.     x = 0;
  58.     y += 10;

  59.   }
  60.   }
  61.   void mousePressed() {
  62.     endRecord();
  63.     exit();
  64.   }

Viewing all articles
Browse latest Browse all 1768

Trending Articles