-
Notifications
You must be signed in to change notification settings - Fork 23
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
Comments
It generally feels like psuedo code would be good -- we should come up with guidelines for what this looks like.... |
maybe: no curly brackets, no "of" specificiers, no opengl specific stuff, no variable types, etc:
|
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. |
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 changesvoid 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
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
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
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: 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);
} |
Nice! Do we want to include comments too? Seems like that could go a long way toward making it clear what's going on... |
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. |
more compression:
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);
} |
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 |
I wonder if here, we could even just drop the drawPerturbedRect part of the code and just focus on the draw call.... |
ie: more like this:
|
ie, do we use c++? OF? pseudo code?
this is for the text template that people will see with the visuals...
The text was updated successfully, but these errors were encountered: