Loading...
Processing Forum
Recent Topics
All Forums
Screen name:
xav1er
xav1er's Profile
3
Posts
1
Responses
0
Followers
Activity Trend
Last 30 days
Last 30 days
Date Interval
From Date :
To Date :
Go
Loading Chart...
Posts
Responses
PM
Show:
All
Discussions
Questions
Expanded view
List view
Private Message
landscape waveform - array size
[1 Reply]
03-Apr-2012 02:55 PM
Forum:
Core Library Questions
Can someone help me limit the array, so I can get something like in this video at 0:51s:
http://vimeo.com/4289626
I'd like to have the landscape with a limited size, so the shapes keep shifting and the older ones are eliminated
import ddf.minim.analysis.*;
import ddf.minim.*;
FFT fftLin;
FFT fftLog;
Waveform myRects;
Minim minim;
AudioPlayer groove;
boolean record;
PFont font;
float camzoom;
float maxX = 0;float maxY = 0;float maxZ = 0;
float minX = 0;float minY = 0;float minZ = 0;
void setup(){
size(1000,500,P3D);
noStroke();
minim = new Minim(this);
groove = minim.loadFile("3.mp3");
//repeat the song
groove.loop();
background(255);
font = loadFont("HelveticaNeue-Bold-48.vlw");
fftLog = new FFT(groove.bufferSize(),groove.sampleRate());
fftLog.logAverages(22,4); //adjust numbers to adjust spacing
float w = float (width/fftLog.avgSize());
float x = w;
float y = 0;
float z = 50;
float radius = 10;
myRects = new Waveform(x,y,z,radius);
}
void draw(){
background(0);
directionalLight(126,126,126,sin(radians(frameCount)),cos(radians(frameCount)),1);
ambientLight(102,102,102);
if (frameCount>1){
for(int i = 0; i < fftLog.avgSize(); i++){
float zoom = 1;
float jitter = (fftLog.getAvg(i)*200);
//println(jitter);
PVector foc = new PVector(myRects.x+jitter, myRects.y+jitter, 0);
PVector cam = new PVector(zoom, zoom, -zoom);
camera(foc.x+cam.x+50,foc.y+cam.y+50,foc.z+cam.z,foc.x,foc.y,foc.z,0,0,1);
}
}
//play the song
fftLog.forward(groove.mix);
myRects.update();
myRects.plotTrace();
}
class Waveform{
float x,y,z;
float radius;
PVector[] pts = new PVector[fftLog.avgSize()];
PVector[] trace = new PVector[0];
Waveform(float incomingX, float incomingY, float incomingZ, float incomingRadius){
x = incomingX;
y = incomingY;
z = incomingZ;
radius = incomingRadius;
}
void update(){
plot();
}
void plot(){
for(int i = 0; i < fftLog.avgSize(); i++){
int w = int(width/fftLog.avgSize());
x = i*w;
y = frameCount*5;
z = height/4-fftLog.getAvg(i)*10;
stroke(0);
point(x, y, z);
pts[i] = new PVector(x, y, z);
//increase size of array trace by length+1
trace = (PVector[]) expand(trace, trace.length+1);
//always get the next to last
trace[trace.length-1] = new PVector(pts[i].x, pts[i].y, pts[i].z);
}
}
void plotTrace(){
//drawing poly surface
stroke(255,80);
int inc = fftLog.avgSize();
for(int i=1; i<trace.length-inc; i++){
if(i%inc != 0){
beginShape(TRIANGLE_STRIP);
float value = (trace[i].z*100);
float m = map(value, -500, 20000, 0, 255);
fill(m*2, 125, -m*2, 140);
vertex(trace[i].x, trace[i].y, trace[i].z);
vertex(trace[i-1].x, trace[i-1].y, trace[i-1].z);
vertex(trace[i+inc].x, trace[i+inc].y, trace[i+inc].z);
vertex(trace[i-1+inc].x, trace[i-1+inc].y, trace[i-1+inc].z);
endShape(CLOSE);
}
}
}
}
Screen Area Record
[1 Reply]
22-Jan-2012 05:36 PM
Forum:
Core Library Questions
In my program I cant record to pdf... I would appreciate some help.
I would like to be able to record only an area of the screen but I dont know if thats possible :(
import processing.pdf.*;
import controlP5.*;
PFont fonte;
PImage img;
PImage controlo;
float peso, altura, margem, angulo;
float ix, iy, fx, fy, fsx, fsy, isx, isy;
int valor=1;
ControlP5 controlP5;
RadioButton radio;
ColorPicker cp;
public int r = 255;
public int g = 255;
public int b = 255;
public int tamanho = 80;
public color cor_logo = 0;
public color cor_fonte = 0;
boolean toggleValue = false;
void setup() {
size(800,400);
frameRate(25);
smooth();
fonte = loadFont( "FedraSansStd-Bold-48.vlw" );
controlo = loadImage("data/www.png");
controlP5 = new ControlP5(this);
controlP5.addToggle("ddd",false,width-70,height-70,20,20);
controlP5.setAutoDraw(false);
cp = controlP5.addColorPicker("picker",40,height-70,100,10);
// Controller mySlider_red = controlP5.addSlider("r",0,255,40,height-70,100,10);
// Controller mySlider_green = controlP5.addSlider("g",0,255,40,height-57,100,10);
// Controller mySlider_blue = controlP5.addSlider("b",0,255,40,height-44,100,10);
radio = controlP5.addRadioButton("radioButton",180,height-70);
radio.setColorForeground(color(0,0,255,0));
radio.setColorBackground(color(255,255,255,0));
radio.setColorActive(color(255,255,0,200));
radio.setColorLabel(color(122));
radio.setItemsPerRow(7);
radio.setSpacingColumn(20);
addToRadioButton(radio,"1",1);
addToRadioButton(radio,"2",2);
addToRadioButton(radio,"3",3);
addToRadioButton(radio,"4",4);
addToRadioButton(radio,"5",5);
addToRadioButton(radio,"6",6);
addToRadioButton(radio,"7",7);
addToRadioButton(radio,"8",8);
addToRadioButton(radio,"9",9);
addToRadioButton(radio,"10",10);
addToRadioButton(radio,"11",11);
addToRadioButton(radio,"12",12);
addToRadioButton(radio,"13",13);
addToRadioButton(radio,"14",14);
}
void addToRadioButton(RadioButton theRadioButton, String theName, int theValue ) {
Toggle t = theRadioButton.addItem(theName,theValue);
t.captionLabel().style().backgroundWidth = 0;
}
void controlEvent(ControlEvent theEvent) {
valor = (int(theEvent.group().value()));
println(valor);
}
void keyPressed() {
switch(key) {
case('1'):
cp.setArrayValue(new float[] {120,0,120,255});
break;
case('2'):
cp.setColorValue(color(255,0,0,255));
break;
}
}
void draw() {
background(cp.getColorValue());
//fundo dos controlos
fill(122);
noStroke();
rect(0,height-100,width,height);
image(controlo,180,330);
controlP5.draw();
if(valor!=0){
altura = 550; //altura do quadro maior
angulo = 25; //curvatura dos quadro
peso = 550/(80/2.5); //espessura do traço dos quadros
ix = peso; //posição inicial x do quadro maior
iy = peso; //posição inicial y do quadro maior
margem = 10; //distancia minima entre quadro maior e menor
//controlo
if (altura*1.66 > width/2){
altura = (width/2)/1.66-peso-margem; //quadro maior com tamanho igual a menos
//de metade do comprimento útil
}
fx = ix+altura*1.66; //posição final x do quadro maior
fy = iy+altura; //posição final y do quadro maior
//calculo aleatorio da posiçao do quadro menor
//que se localizará no interior do quadro maior sem lhe tocar
fsx = (altura/2)*1.37;
fsy = (altura/2);
isx = random(ix+margem,fx-fsx);
isy = random(iy+margem,fy-fsy);
//println((iy+margem)+" "+(fy-margem-fsy));
switch(valor) {
case 1:
cor_logo=color(0); cor_fonte=color(0);
img = loadImage("data/pp.png");
valor=0;
break;
case 2:
cor_logo=color(122); cor_fonte=color(0);
img = loadImage("data/p2.png");
valor=0;
case 3:
cor_logo=color(cp.getColorValue()); cor_fonte=color(0);
img = loadImage("data/p1.png");
valor=0;
break;
case 4:
cor_logo=color(r,g,b); cor_fonte=color(0);
img = loadImage("data/p3.png");
valor=0;
break;
case 5:
cor_logo=color(r,g,b); cor_fonte=color(0);
img = loadImage("data/p4.png");
valor=0;
break;
case 6:
cor_logo=color(r,g,b); cor_fonte=color(0);
img = loadImage("data/p5.png");
valor=0;
break;
case 7:
cor_logo=color(r,g,b); cor_fonte=color(0);
img = loadImage("data/p6.png");
valor=0;
break;
case 8:
cor_logo=color(255); cor_fonte=color(255);
img = loadImage("data/bb.png");
valor=0;
break;
case 9:
cor_logo=color(r,g,b); cor_fonte=color(255);
img = loadImage("data/b1.png");
valor=0;
break;
case 10:
cor_logo=color(r,g,b); cor_fonte=color(255);
img = loadImage("data/b2.png");
valor=0;
break;
case 11:
cor_logo=color(r,g,b); cor_fonte=color(255);
img = loadImage("data/b3.png");
valor=0;
break;
case 12:
cor_logo=color(r,g,b); cor_fonte=color(255);
img = loadImage("data/b4.png");
valor=0;
break;
case 13:
cor_logo=color(r,g,b); cor_fonte=color(255);
img = loadImage("data/b5.png");
valor=0;
break;
case 14:
cor_logo=color(r,g,b); cor_fonte=color(255);
img = loadImage("data/b6.png");
valor=0;
break;
}
}
image(img,ix,iy);
//rectangulo maior
noFill();
//stroke(cor_logo);
//strokeWeight(peso);
//roundedRect(ix, iy, fx, fy, angulo, angulo);
//rectangulo menor
strokeWeight(1);
fill(cor_logo);
roundedRect(isx, isy, fsx, fsy, angulo, angulo);
//texto
String casa = "casa" ;
fill(cor_fonte);
text ( casa , width/2+20, isy+47);
String cinema = "cinema" ;
textFont(fonte,tamanho);
text ( cinema , width/2+20, isy+106);
fill(122);
rect(0,height-38,width,height);
}
//rectangulo arredondado
void roundedRect(float x, float y, float w, float h, float rx, float ry)
{
beginShape();
vertex(x,y+ry); //top of left side
bezierVertex(x,y,x,y,x+rx,y); //top left corner
vertex(x+w-rx,y); //right of top side
bezierVertex(x+w,y,x+w,y,x+w,y+ry); //top right corner
vertex(x+w,y+h-ry); //bottom of right side
bezierVertex(x+w,y+h,x+w,y+h,x+w-rx,y+h); //bottom right corner
vertex(x+rx,y+h); //left of bottom side
bezierVertex(x,y+h,x,y+h,x,y+h-ry); //bottom left corner
endShape(CLOSE);
}
void toggle(boolean theFlag) {
beginRecord(PDF, "filename.pdf");
endRecord();
}
Creating rounded rectangles
[4 Replies]
03-Jan-2012 02:07 PM
Forum:
Programming Questions
What's the best way to create a rounded rectangle with the possibility of using only the stroke?
«Prev
Next »
Moderate user : xav1er
Forum