GROUP PShape with sphere [solved]

edited December 2014 in How To...

hello all,

I just teach myself PShape with the great tutorial.

  • I want to make a cloud with one big base sphere (wide and flat) and 2 spheres upon.

  • I encounter some problems.

using createShape (SPHERE) I wanted to to pass 6 params, 3 for pos and 3 for size (w,h,d). But it occured to me I can pass only one numerical parameter, size. So to make a flat base sphere for the cloud proves difficult.

2nd I wanted to place the two smaller spheres upon the main part (like a camel looking cloud). But then, I need the 2 spheres have a offset in their Position from 0,0,0 - how when I can't pass pos as params?

this is important since I wanted to use GROUP finally to have the cloud as one shape. For the group I'd need the 3 spheres at different positions.

thank you!

Chrisir ;-)

Tagged:

Answers

  • my code is similar to this

    // Make the parent shape
    PShape alien = createShape(GROUP);
    
    // Make two shapes
    PShape head = createShape(ELLIPSE, 0, 0, 50, 50);
    PShape body = createShape(RECT, 0, 50, 50, 100);
    
    // Add the two "child" shapes to the parent group
    alien.addChild(head);
    alien.addChild(body);
    
    // Draw the group
    translate(width/2, height/2);
    shape(alien);
    
  • Answer ✓

    solved.

  • edited December 2014

    solution:

    use createShape (SPHERE) with one parameter (size), then use scale and translate to modify

    PShape head = createShape(SPHERE, 50);
    head.scale(1.0, 0.7, 1.0); 
    head.translate(20,-30,13);
    
    • for fill and stroke: head.setStroke and head.setFill (gotta use color type!)

    • for noFill and noStroke: head.setStroke(false) and head.setFill(false)

    ;-)

Sign In or Register to comment.