Page 1 of 1
Gradient Rotation
Posted: Sat May 08, 2010 9:39 am
by WaltBrown
Hi! Is there any way to make the fill gradient for a graphic object oriented relative to the object's rotation? I made a 2D swarm demo and when my "birds" change direction, if I have filled them with a gradient, the gradient stays at the same angle. Thanks,
Walt
PS - Actually, a better question relates not just to gradients, but to all object visual parameters, like height and width - can any be made "Local" to the object rather than "Global" to the screen? In SecondLife programming for example, objects and their relevant parameters can be selected to be global or local in terms of their cartesian axes.
Re: Gradient Rotation
Posted: Sat May 08, 2010 11:28 am
by bn
Walt,
check out this post from Scott Rossi with a link to a wonderful tool to better understand gradients.
http://www.mail-archive.com/use-revolut ... 16548.html
and you might want to check out this revOnline stack I made that shows a lot of fillgradient manipulations, among others how to change the angle/direction of a fillgradient.
http://revonline2.runrev.com/stack/322/Beachballs
regards
Bernd
Re: Gradient Rotation
Posted: Sun May 09, 2010 8:25 pm
by bn
Walt,
if all that gradient stuff is too much and you only want 1 graphic that turns you could upload a stack with that graphic to the forum (upload attachment). It has to be zipped for upload. And tell us what exactly the graphic is supposed to do. (e.g. do you want to turn it by degree?) and I see what I can do.
regards
Bernd
Re: Gradient Rotation
Posted: Sun May 09, 2010 11:28 pm
by WaltBrown
Thanks Bernd. Here's the example stack:
http://idlab.on-rev.com/stacks.html This stack shows the distortion. Note that I am going to use an externally created image instead that fits into a square to avoid this.
It brought up a few thoughts:
1. Graphic objects should fill their rects - this example shows the Bird in it's rect - note the top, left, and bottom margins.
2. It would be nice to have "Align center" in the IDE for aligning objects.
3. Objects should be able to be rotated - ie their entire rect, not just rect contents.
4. Another nice RevTalk feature would be a function like:
the overlap [rect|visual] of object id "xxx" and object id "yyy" is true|false
the adjacent [rect|visual] of object....
and including the alpha channel for the overlap (the "visual" parameter).
Oh, on the idlab.on-rev.com link - I'm just re-starting as I didn't have time before to finish creating the site, so please be gentle with me on all the missing "stuff" there...
Walt
Re: Gradient Rotation
Posted: Mon May 10, 2010 3:56 am
by WaltBrown
Another note - when setting the angle of a "graphic" versus an "image". The "graphic" object angles go clockwise when increasing, the "image" object angles go counterclockwise. I'll add that to my example stack. It is also interesting in that the "graphic" stays constrained to it's assigned rect, while the "image" rect varies as it's angle is changed.
OK, added rotationtest2 to the previous link.
Walt
Re: Gradient Rotation
Posted: Mon May 10, 2010 10:53 pm
by bn
Hi Walt,
I misunderstood your first posting because I thought you wanted to work on the fillgradient of a graphic. So all the links I posted were not up to what you wanted. (fillgradient is the gradient of a graphic, your graphic has a background color or fillcolor) As it turns out you want to rotate the graphic. That is doable but unfortunately not really nice in Rev.
Rev has a command: revRotatePoly that can rotate polygons (the ones Rev calls freehand polygons in the palette). But this function creates rounding errors for the polygons if called repeatedly on a polygon. If you do it often enough the polygon gets smaller and smaller. One workaround this is to let revRotatePolygons operate on the original set of points, which I assign as a custom property of the graphic itself. Than you always start from non-rounded points and only have one rounding error in the operation. I attach a stack that show this for a triangle similar to the one of your stack. The result is not perfectly smooth but might be sufficient, depending of what you want. Alternatively you could set the points of a graphic on the fly to change its shape, that of course means you have to calculate these points.
Regarding rotating pictures: if you rotate images by small increments you will get a lot of distortion in the image. If you rotate by 90/180/270 degrees it works quite well. I attach another stack that shows the distortion of an image if you repeatedly rotate it. The resulting distortion should be promoted as a feature, worthy of a Photoshop plug-in
This all has to do with the fact that Rev uses the pixel as smallest unit, so distortions are unavoidable on rotation until Rev changes its image/graphic model.
Unfortunately the image in your second stack did not show up since it was reference to your local drive. If you want to include it you have to import the image or issue from the message box
Code: Select all
set the imagedata of image "myImage" to the imagedata of image "myImage"
this unties the external reference and the image is now local in your stack.
WaltBrown wrote:2. It would be nice to have "Align center" in the IDE for aligning objects
you can do this in the properties inspector if you have selected more then one object in the align objects pane under align: at the right the two options lets you align all objects to the location of the first object you selected vertically and horizontally.
regards
Bernd
Re: Gradient Rotation
Posted: Tue May 11, 2010 2:37 am
by WaltBrown
Thanks Bernd. Great image on the expanding, distorting sphere! That was actually a wonderful picture! An exploding universe!
I have added some stuff to your stack, at
http://idlab.on-rev.com/RotatePolygon2.rev.
It's not polished, but if you hit the "flybird" button you'll see what I am doing. At the moment collision is only detected by calculating the cartesian distance between the two "birds" (the dashed line circles) at each moveStopped event, which is 1/40 of the distance between the pink "bird" and the target.
I added a bounding rect to your yellow "bird" to show the issue with using rect as the collision detector.
Sorry about the missing graphic, I forgot about the linked versus embedded issue with images. Thanks for your help.
Walt
Re: Gradient Rotation
Posted: Tue May 11, 2010 11:36 am
by bn
Hi Walt,
here is another way to make a pointer. It uses the startangle of a graphic.
regards
Bernd