-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
p5.dom CSS transforms #389, translate() rotate() #745
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
Conversation
this.elt.style.transform = this.elt.style.transform.replace(substr, ''); | ||
} | ||
} | ||
this.elt.style.transform += 'translate3d('+x+'px,'+y+'px,'+z+'px)'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would probably be good to check here whether there are 2 or 3 arguments, and use regular translate rather than translate3d if only x and y are provided.
style wise, when there is a variable number of arguments, we generally leave the params empty and use arguments.length
to test how many there and arguments[0]
etc to grab them.
@futuremarc this looks great at quick glance! @shiffman do you have time to review this and merge if all looks good? |
Yes, apologies, I am under crushing Learning Processing 2nd Edition deadline this Friday 4pm EST. Will come up for air and take a closer look after. |
3a3412c
to
fb51d83
Compare
Sorry, this pull request was done with my master branch resulting in additional changes ... next time i'll make a branch of my fork for each PR. |
c02b13c
to
fb51d83
Compare
Awesome! I'll be reviewing this over the weekend / Monday and will let @lmccart know if I have questions. Looks like there are some merge conflicts so you might want to check re: pulling any updates processing/p5.js. Apologies if my delays are the root of this. |
Ok, I've played with this a bit. This is what I've tested so far:
By the way, if we don't already we should probably support. .
Where the loaded image's context is bound to the callback (if I'm using the right terminology). @futuremarc let me know if I'm missing stuff, we can jump on hangout or switch to e-mail thread for debugging if preferable. |
|
Do you think we really need the |
I tested everything and it's working great. Two questions @lmccart.
I think the p5 precedent is callback always last? |
|
this._pInst.scale(this._pInst._pixelDensity, this._pInst._pixelDensity); | ||
for (var prop in j) { | ||
this.elt.getContext('2d')[prop] = j[prop]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you explain what's happening here with this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!important
was breaking size()
for Chrome and Firefox
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little uncomfortable using !important
internally within our generated elements. There are cases when I'd imagine a user of p5 would want to be able to control some of this via styling; this change makes that more difficult.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this styling is to handle the scaling for retina (canvases are created at a multiple size based on device pixel ratio, then scaled down with style attributes), but i'm not sure the !important is actually needed. @futuremarc could you test without and see if it still works without?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, sure
var k = this.elt.getContext('2d'); | ||
for (var prop in k) { | ||
j[prop] = k[prop]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a minor thing, but in general it's best to avoid defining variables (i.e., using var
) inside a conditional block: these two functions are exactly the same in operation
function one() {
var a;
if ( this.elt instanceof HTMLCanvasElement ) {
a = true;
}
}
// and
function one() {
if ( this.elt instanceof HTMLCanvasElement ) {
var a = true;
}
}
and the former is usually considered preferable because it avoids the risk of unintuitive behavior due to variable hoisting.
Additionally, it would be best to avoid uninformative variable names like j
and k
: when p5 gets minified all variable names will be cleaned up anyway, so within the p5 code itself we try to use descriptive variable names like autoWidth
or 2dDrawingContext
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These actually weren't my changes (merge was messed up), but good to know re: variable hoisting
ok awesome, looks like this one is good to go now. thanks for all the work with the revisions. |
p5.dom CSS transforms #389, translate() rotate()
yay, great work @futuremarc! |
Adds translate() and rotate() features to the dom add-on.