Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make decisions about the type of "code" to show #3

Open
ofZach opened this issue Nov 14, 2015 · 10 comments
Open

make decisions about the type of "code" to show #3

ofZach opened this issue Nov 14, 2015 · 10 comments

Comments

@ofZach
Copy link
Owner

ofZach commented Nov 14, 2015

ie, do we use c++? OF? pseudo code?

this is for the text template that people will see with the visuals...

@ofZach
Copy link
Owner Author

ofZach commented Nov 14, 2015

It generally feels like psuedo code would be good -- we should come up with guidelines for what this looks like....

@ofZach
Copy link
Owner Author

ofZach commented Nov 14, 2015

maybe: no curly brackets, no "of" specificiers, no opengl specific stuff, no variable types, etc:

for ( i = 0; i < 10; i++){
     rect ( i, i, 10, 10);
}

@mayakraft
Copy link
Collaborator

wondering about how many lines of code to include, I'm thinking about only including what gives the piece character.

for instance my vera molnar scene is a 6x6 grid of the jumbly squares. it's clear to the viewer that there are 36 copies of a thing. i can leave out that code that says "make 36 copies, arrange them x y 6x6", then i can focus on what makes just one of the squares.

thinking about bridget riley, however, her pieces are all about copies, with small changes each time, so it makes sense to have the loop that makes copies of a thing.

@mayakraft
Copy link
Collaborator

I've gone down a rabbit hole, not sure how productive this is, here's a couple iterations of code turning into pseudo-code.

Do any of these sound like good ideas / just too much work?

no changes

void veraRect::drawPerturbedRect(float x, float y, float width, float height,
                                 float X_PERTURB_TL, float Y_PERTURB_TL,
                                 float X_PERTURB_TR, float Y_PERTURB_TR,
                                 float X_PERTURB_BR, float Y_PERTURB_BR,
                                 float X_PERTURB_BL, float Y_PERTURB_BL){

    float topLeftX = (x + (width*X_PERTURB_TL) - (width*X_PERTURB_TL*.5));
    float topLeftY = (y + (height*Y_PERTURB_TL) - (height*Y_PERTURB_TL*.5));
    float topRightX = (x + width + (width*X_PERTURB_TR) - (width*X_PERTURB_TR*.5));
    float topRightY = (y + (height*Y_PERTURB_TR) - (height*Y_PERTURB_TR*.5));
    float bottomRightX = (x + width + (width*X_PERTURB_BR) - (width*X_PERTURB_BR*.5));
    float bottomRightY = (y + height + (height*Y_PERTURB_BR) - (height*Y_PERTURB_BR*.5));
    float bottomLeftX = (x + (width*X_PERTURB_BL) - (width*X_PERTURB_BL*.5));
    float bottomLeftY = (y + height + (height*Y_PERTURB_BL) - (height*Y_PERTURB_BL*.5));

    ofDrawLine(topLeftX, topLeftY, topRightX, topRightY);
    ofDrawLine(topRightX, topRightY, bottomRightX, bottomRightY);
    ofDrawLine(bottomRightX, bottomRightY, bottomLeftX, bottomLeftY);
    ofDrawLine(bottomLeftX, bottomLeftY, topLeftX, topLeftY);
}

void veraRect::draw(int numRects, float d){
    for(int i = 0; i < numRects; i++){
        drawPerturbedRect(centerX - radius[i]*.5, centerY - radius[i]*.5, radius[i], radius[i],
                          d*(perturb[i*8+0] + an[i*8+0]*sinf(an[i*8+1]*ofGetElapsedTimef())), d*(perturb[i*8+1] + an[i*8+0]*cosf(an[i*8+1]*ofGetElapsedTimef())),
                          d*(perturb[i*8+2] + an[i*8+2]*sinf(an[i*8+3]*ofGetElapsedTimef())), d*(perturb[i*8+3] + an[i*8+2]*cosf(an[i*8+3]*ofGetElapsedTimef())),
                          d*(perturb[i*8+4] + an[i*8+4]*sinf(an[i*8+5]*ofGetElapsedTimef())), d*(perturb[i*8+5] + an[i*8+4]*cosf(an[i*8+5]*ofGetElapsedTimef())),
                          d*(perturb[i*8+6] + an[i*8+6]*sinf(an[i*8+7]*ofGetElapsedTimef())), d*(perturb[i*8+7] + an[i*8+6]*cosf(an[i*8+7]*ofGetElapsedTimef())));
    }
}

changes 1

  • make openframeworks calls generic, ofdrawline() = line()
  • get rid of types
  • get rid of c++ class notation, double colon stuff
  • make sinf() into sin()
drawPerturbedRect(x, y, width, height, X_PERTURB_TL, Y_PERTURB_TL, 
                                       X_PERTURB_TR, Y_PERTURB_TR, 
                                       X_PERTURB_BR, Y_PERTURB_BR, 
                                       X_PERTURB_BL, Y_PERTURB_BL){

    topLeftX = (x + (width*X_PERTURB_TL) - (width*X_PERTURB_TL*.5));
    topLeftY = (y + (height*Y_PERTURB_TL) - (height*Y_PERTURB_TL*.5));
    topRightX = (x + width + (width*X_PERTURB_TR) - (width*X_PERTURB_TR*.5));
    topRightY = (y + (height*Y_PERTURB_TR) - (height*Y_PERTURB_TR*.5));
    bottomRightX = (x + width + (width*X_PERTURB_BR) - (width*X_PERTURB_BR*.5));
    bottomRightY = (y + height + (height*Y_PERTURB_BR) - (height*Y_PERTURB_BR*.5));
    bottomLeftX = (x + (width*X_PERTURB_BL) - (width*X_PERTURB_BL*.5));
    bottomLeftY = (y + height + (height*Y_PERTURB_BL) - (height*Y_PERTURB_BL*.5));

    line(topLeftX, topLeftY, topRightX, topRightY);
    line(topRightX, topRightY, bottomRightX, bottomRightY);
    line(bottomRightX, bottomRightY, bottomLeftX, bottomLeftY);
    line(bottomLeftX, bottomLeftY, topLeftX, topLeftY);
}

draw(numRects, d){
    for(i = 0; i < numRects; i++){
        drawPerturbedRect(centerX - radius[i]*.5, centerY - radius[i]*.5, radius[i], radius[i],
                          d*(perturb[i*8+0] + an[i*8+0]*sinf(an[i*8+1]*time())), 
                          d*(perturb[i*8+1] + an[i*8+0]*cosf(an[i*8+1]*time())),
                          d*(perturb[i*8+2] + an[i*8+2]*sinf(an[i*8+3]*time())), 
                          d*(perturb[i*8+3] + an[i*8+2]*cosf(an[i*8+3]*time())),
                          d*(perturb[i*8+4] + an[i*8+4]*sinf(an[i*8+5]*time())), 
                          d*(perturb[i*8+5] + an[i*8+4]*cosf(an[i*8+5]*time())),
                          d*(perturb[i*8+6] + an[i*8+6]*sinf(an[i*8+7]*time())), 
                          d*(perturb[i*8+7] + an[i*8+6]*cosf(an[i*8+7]*time())));
    }
}

changes 2

  • made spacing the same
  • changed variable names to more like English
draw(numberOfRectangles, disarray){
    for(i = 0; i < numberOfRectangles; i++){
        drawPerturbedRect(centerX - radius[i]*.5, centerY - radius[i]*.5, 
                          radius[i], radius[i],
                          disarray * ( wobble[i*8+0] + magnitude[i*8+0] * sin(magnitude[i*8+1] * time() ) ), 
                          disarray * ( wobble[i*8+1] + magnitude[i*8+0] * cos(magnitude[i*8+1] * time() ) ),
                          disarray * ( wobble[i*8+2] + magnitude[i*8+2] * sin(magnitude[i*8+3] * time() ) ), 
                          disarray * ( wobble[i*8+3] + magnitude[i*8+2] * cos(magnitude[i*8+3] * time() ) ),
                          disarray * ( wobble[i*8+4] + magnitude[i*8+4] * sin(magnitude[i*8+5] * time() ) ), 
                          disarray * ( wobble[i*8+5] + magnitude[i*8+4] * cos(magnitude[i*8+5] * time() ) ),
                          disarray * ( wobble[i*8+6] + magnitude[i*8+6] * sin(magnitude[i*8+7] * time() ) ), 
                          disarray * ( wobble[i*8+7] + magnitude[i*8+6] * cos(magnitude[i*8+7] * time() ) ) );
    }
}

drawPerturbedRect(x, y, width, height, X_PERTURB_TL, Y_PERTURB_TL, 
                                       X_PERTURB_TR, Y_PERTURB_TR, 
                                       X_PERTURB_BR, Y_PERTURB_BR, 
                                       X_PERTURB_BL, Y_PERTURB_BL){

    topLeftX =     (x + (width  * X_PERTURB_TL)         - (width  * X_PERTURB_TL * .5));
    topLeftY =     (y + (height * Y_PERTURB_TL)         - (height * Y_PERTURB_TL * .5));
    topRightX =    (x + width   + (width*X_PERTURB_TR)  - (width  * X_PERTURB_TR * .5));
    topRightY =    (y + (height * Y_PERTURB_TR)         - (height * Y_PERTURB_TR * .5));
    bottomRightX = (x + width   + (width*X_PERTURB_BR)  - (width  * X_PERTURB_BR * .5));
    bottomRightY = (y + height  + (height*Y_PERTURB_BR) - (height * Y_PERTURB_BR * .5));
    bottomLeftX =  (x + (width  * X_PERTURB_BL)         - (width  * X_PERTURB_BL * .5));
    bottomLeftY =  (y + height  + (height*Y_PERTURB_BL) - (height * Y_PERTURB_BL * .5));

    line(topLeftX, topLeftY, topRightX, topRightY);
    line(topRightX, topRightY, bottomRightX, bottomRightY);
    line(bottomRightX, bottomRightY, bottomLeftX, bottomLeftY);
    line(bottomLeftX, bottomLeftY, topLeftX, topLeftY);
}

changes 3

  • make changes that break the code, but get the point across, like this:
drawPerturbedRect(x, y, width, height, X_PERTURB_TL, Y_PERTURB_TL, 
                                       X_PERTURB_TR, Y_PERTURB_TR, 
                                       X_PERTURB_BR, Y_PERTURB_BR, 
                                       X_PERTURB_BL, Y_PERTURB_BL){

becomes: drawPerturbedRect(x, y, width, height, perturb){

draw(numberOfRectangles, disarray){
    for(i = 0; i < numberOfRectangles; i++){
        drawPerturbedRect(centerX - radius[i]*.5, centerY - radius[i]*.5, 
                          radius[i], radius[i],
                          disarray * ( wobble[i*8+0] + magnitude[i*8+0] * sin(magnitude[i*8+1] * time() ) ), 
                          disarray * ( wobble[i*8+1] + magnitude[i*8+0] * cos(magnitude[i*8+1] * time() ) ),
                          disarray * ( wobble[i*8+2] + magnitude[i*8+2] * sin(magnitude[i*8+3] * time() ) ), 
                          disarray * ( wobble[i*8+3] + magnitude[i*8+2] * cos(magnitude[i*8+3] * time() ) ),
                          disarray * ( wobble[i*8+4] + magnitude[i*8+4] * sin(magnitude[i*8+5] * time() ) ), 
                          disarray * ( wobble[i*8+5] + magnitude[i*8+4] * cos(magnitude[i*8+5] * time() ) ),
                          disarray * ( wobble[i*8+6] + magnitude[i*8+6] * sin(magnitude[i*8+7] * time() ) ), 
                          disarray * ( wobble[i*8+7] + magnitude[i*8+6] * cos(magnitude[i*8+7] * time() ) ) );
    }
}

drawPerturbedRect(x, y, width, height, perturb){

    topLeftX =     (x + perturb.TopLeft              );
    topLeftY =     (y + perturb.TopLeft              );
    topRightX =    (x + perturb.TopRight    + width  );
    topRightY =    (y + perturb.TopRight             );
    bottomRightX = (x + perturb.BottomRight + width  );
    bottomRightY = (y + perturb.BottomRight + height );
    bottomLeftX =  (x + perturb.BottomLeft           );
    bottomLeftY =  (y + perturb.BottomLeft  + height );

    line(topLeftX, topLeftY, topRightX, topRightY);
    line(topRightX, topRightY, bottomRightX, bottomRightY);
    line(bottomRightX, bottomRightY, bottomLeftX, bottomLeftY);
    line(bottomLeftX, bottomLeftY, topLeftX, topLeftY);
}

@andyinabox
Copy link
Collaborator

Nice! Do we want to include comments too? Seems like that could go a long way toward making it clear what's going on...

@ofZach
Copy link
Owner Author

ofZach commented Nov 16, 2015

it feels like it's getting closer ! I agree that comments would help... it feels like if it can fit in one or two functions like this it's good.

@mayakraft
Copy link
Collaborator

more compression:

  • whenever this is a line that looks like it's copied 8 times, replace it with one. (stride)
  • break the code if necessary (yes/no?)
  • Andy's suggestion: add comments
draw(numberOfRectangles, disarray){
// wobble and magnitude used in trig functions to slightly affect the position of the corners (disarray)
    for(i = 0; i < numberOfRectangles; i++){
        drawPerturbedRect(centerX - radius[i]*.5, centerY - radius[i]*.5, 
                          radius[i], radius[i],
                          disarray * ( wobble[i*8] + magnitude[i*8] * sin(magnitude[i*8] * time() ) ) );

    }
}

drawPerturbedRect(x, y, width, height, perturb){
// "perturb" contains values to offset each corner of the square,
// making it irregular, but consistent between each frame
    topLeftX =     (x + perturb.TopLeft              );
    topLeftY =     (y + perturb.TopLeft              );
    topRightX =    (x + perturb.TopRight    + width  );
    topRightY =    (y + perturb.TopRight             );
    bottomRightX = (x + perturb.BottomRight + width  );
    bottomRightY = (y + perturb.BottomRight + height );
    bottomLeftX =  (x + perturb.BottomLeft           );
    bottomLeftY =  (y + perturb.BottomLeft  + height );

    line(topLeftX, topLeftY, topRightX, topRightY);
    line(topRightX, topRightY, bottomRightX, bottomRightY);
    line(bottomRightX, bottomRightY, bottomLeftX, bottomLeftY);
    line(bottomLeftX, bottomLeftY, topLeftX, topLeftY);
}

@ofZach
Copy link
Owner Author

ofZach commented Nov 24, 2015

Looking good! Anything you can do to feature your params is also good. Code can break for sure no one will be trying this code out :) it's more showing the idea

@ofZach
Copy link
Owner Author

ofZach commented Dec 10, 2015

I wonder if here, we could even just drop the drawPerturbedRect part of the code and just focus on the draw call....

@ofZach
Copy link
Owner Author

ofZach commented Dec 10, 2015

ie: more like this:

// wobble and magnitude used in trig functions to slightly affect the position of the corners (disarray)
    for(i = 0; i < numberOfRectangles; i++){
        drawPerturbedRect(centerX - radius[i]*.5, centerY - radius[i]*.5, 
                          radius[i], radius[i],
                          disarray * ( wobble[i*8] + magnitude[i*8] * sin(magnitude[i*8] * time() ) ) );

    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants