We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › I'm new to processing and have a project I need
Page Index Toggle Pages: 1
I'm new to processing and have a project I need (Read 1512 times)
I'm new to processing and have a project I need
Apr 28th, 2010, 2:41pm
 
I have some programming experience but none with Processing and none with 3d.

I would like a processing sketch in  two sections.  a 2d rectangular plain and a 3d cylinder.  I want to draw on the plain and  translate the 2d drawing into 3d on the cylinder in real time.  I simply don't know where to start.  Can anyone help me? please
Re: I'm new to processing and have a project I need
Reply #1 - Apr 28th, 2010, 6:22pm
 
As it happens, I do have a demo of a sketch with both a 2D section and a 3D section:

Quote:
/// "ThreeViews" by TfGuy44 (TfGuy44@gmail.com)
PGraphics BC, GC, RC;
float rot = 0.0;

void setup(){
  size( 400, 200, P2D);
  BC = createGraphics(200, 200, P3D);
  RC = createGraphics(200, 200, P3D);
  GC = createGraphics(200, 200, P3D);
}

void draw(){
  rot=(rot+0.01)%360;
  background(0);
  noStroke();
  fill(color(255,0,0));
  rect(10,40,20,20);
  fill(color(0,0,255));
  rect(70,70,20,20);
  fill(color(0,255,0));
  rect(70,10,20,20);
  if( get( mouseX, mouseY ) == color(255,0,0) ){
    RC.beginDraw();
    RC.background(color(128,0,0));
    RC.fill(color(255,0,0));
    RC.lights();
    RC.translate(100,100,0);
    RC.rotateX(rot);
    RC.rotateY(2*rot);
    RC.box(20);
    RC.endDraw();
    image( RC.get(), 200, 0);
  }
  if( get( mouseX, mouseY ) == color(0,255,0) ){
    GC.beginDraw();
    GC.background(color(0,128,0));
    GC.fill(color(0,255,0));
    GC.lights();
    GC.translate(100,100,0);
    GC.rotateX(rot);
    GC.rotateY(2*rot);
    GC.box(50);
    GC.endDraw();
    image( GC.get(), 200, 0);
  }
  if( get( mouseX, mouseY ) == color(0,0,255) ){
    BC.beginDraw();
    BC.background(color(0,0,128));
    BC.fill(color(0,0,255));
    BC.lights();
    BC.translate(100,100,0);
    BC.rotateX(rot);
    BC.rotateY(2*rot);
    BC.box(80);
    BC.endDraw();    
    image( BC.get(), 200, 0);
  } 
}




Give me a few minutes and I'll see if I can fangle it into something a bit more useful.
Re: I'm new to processing and have a project I need
Reply #2 - Apr 28th, 2010, 6:53pm
 
Quote:
/// "ScribbleTube" by TfGuy44 (TfGuy44@gmail.com)
PGraphics BC;
float rot = 0.0;
PImage twoDpart;

void setup(){
  size( 400, 200, P2D);
  BC = createGraphics(200, 200, P3D);
  background(0);
  twoDpart = createImage(200,200,RGB);
  strokeWeight(3);
}

void draw(){
  stroke(255);
  line(mouseX, mouseY, pmouseX, pmouseY);
  simulateRenderAndDraw3D();
  fill(0,0,0,20);
  noStroke();
  rect(0,0,200,200);
}

void simulateRenderAndDraw3D(){
  rot=(rot+0.01)%360;
  BC.beginDraw();
  BC.background(color(128));
  BC.noFill();//color(0,0,255));
  BC.lights();
  BC.translate(100,100,0);
  BC.rotateX(rot);
  BC.rotateY(2*rot);
  BC.scale(80);
  drawTube();
  BC.endDraw();    
  image( BC.get(), 200, 0);
  twoDpart = get( 0, 0, 200, 200 );
}

void drawTube(){
  drawTube(30);
}
void drawTube(int detail) {
  float angle = 0;
  float angleIncrement = TWO_PI / detail;
  BC.noStroke();
  BC.pushMatrix();
  BC.beginShape(QUAD_STRIP);
  if( twoDpart != null ){    
    texture( twoDpart );
    BC.texture( twoDpart );
  }
  for (int i=0; i<detail+1; ++i) {
    BC.vertex( cos(angle)/2.0, -.5, sin(angle)/2.0, map(angle,0,TWO_PI,0,200), 0 );
    BC.vertex( cos(angle)/2.0,  .5, sin(angle)/2.0, map(angle,0,TWO_PI,0,200), height );
    angle += angleIncrement;
  }
  BC.endShape();
  BC.popMatrix();
}



There we go. Hard part's done. You can work out the rest of the details, I'm sure. Smiley
Re: I'm new to processing and have a project I need
Reply #3 - May 1st, 2010, 3:30pm
 
That's great, I really appreciate the help.  I've been learning and making changes, but I'm stumped by a couple of things:

I want to keep the drawing from fading so that I can save it.

I want to actually apply 3d shapes to the cylinder.  A series of rectangles would work, just to represent the 2d drawing in 3d

Again, I appreciate the help.
Re: I'm new to processing and have a project I need
Reply #4 - May 1st, 2010, 6:38pm
 
The image is fading because a nearly-see-through black rectangle is being drawn over the 2D half every time the scene is drawn:

 fill(0,0,0,20);
 noStroke();
 rect(0,0,200,200);

It's an old trick, and not one of mine. If you want it to do something else instead of fading, you'll first have to stop that rectangle from being drawn!

You certainly could drawn 3D shapes over/around/under/through the cylinder (Which is actually just a bunch of textured rectangles anyway), but how do you plan on specifying, by drawing them in 2D, where the shape appears in 3D?
Re: I'm new to processing and have a project I need
Reply #5 - May 2nd, 2010, 11:04am
 
My assumption is  the UVs of both can be mapped together so that as a curve is drawn on the rectangle, a corresponding bump will emerge on the cylinder.  I use Rhino with grasshopper and I can do it there.  I just don't have a clue in processing
Re: I'm new to processing and have a project I need
Reply #6 - May 12th, 2010, 5:58am
 
Hi am doing project using processing and am new to this, I need some help please, I want to create text box (for example if user enter march month in text box) the output should be shown in screen.In my project i created month.tsv table in this table it has month column.
Thank you.
Page Index Toggle Pages: 1