Way to handle colors visually/manually AND with code, in Flash/Animate? - actionscript-3

I used to use a lot of Filters in Animate, and it was glorious because I could make a color filter by hand, see what it looks like, and then integrate code into that too, eg:
object.filters = e.currentTarget.filters;
But I'm trying to be good and stay away from filters to reduce processing power etc. Plus, filters don't take in hex codes. So I'm trying to use colorTransforms. But now things get really unwieldly because I figure out which colors I want, write down all the hex codes in Notepad, then write code to transform things to that color. And I still can't SEE the colours interacting until I publish the file. Isn't there SOME way to manually fiddle with colorTransforms? Maybe the Advanced section under Color Effect -> Style?
How I imagine this happening in my fantasy is:
I have a few movieclips which interact to create a fabric swatch. I fiddle with the colorTransform or SOMEhow apply a hex code to them manually (not dynamically in code), and then I can use those swatches to dynamically color other things, something like:
newFabric.topPattern.colorTransform.color = fabricSwatch.topPattern.colorTransform.color;
I know I can do this if I added the colour using code first.. but is there any way to add the colour on the stage/visually/manually and then have the code roll it forward? I know I can draw a bitmap and sample a pixel's color, but the patterns all have very fine, different & complex shapes and transparencies so that won't work here :/

Ok! I have found a workaround! \o/
I can edit the Tint manually, and even input a hex code or eye-drop a colour from my pre-made palette. I just have to make sure to set the "Tint" setting on the Tint to 100%. (Color Effect -> Style:Tint)
Now I simply use the colorTransform code and it can pull my manually placed Tint, and transfer it to other items:
grl.overlay.shapes.transform.colorTransform = e.currentTarget.shapes.transform.colorTransform;
I didn't even have to change my code AND this is better than filters since I can input hex codes. I don't know how this will be on performance relative to filters, but someone just told me that it shouldn't be too bad since nothing is animating. I'm so happy :)

There are LOTS of tutorials out there for using colortransforms – like this one.
As for using hex colors, you can convert back and forth between the various color representations very easily. A simple Google search turned up this snippet:
var brightPinkHex:uint = 0xFF32CC;
var brightPinkRGB:Object = HexToRGB(brightPinkHex);
trace(brightPinkRGB.r+ ", " + brightPinkRGB.g + ", " + brightPinkRGB.b);
function HexToRGB(value:uint):Object {
var rgb:Object = new Object();
rgb.r = (value >> 16) & 0xFF
rgb.g = (value >> 8) & 0xFF
rgb.b = value & 0xFF
return rgb;
}
// OUTPUT
// 255, 50, 204

Related

How to change the field background color in Crystal Reports using HTML?

I have a cross-tab in the report. I need to change background color of the summary field based on the database field HEX value. For this I'm interpreting field as HTML. So I created the formula fields and trying to use HTML tags to format it. I can change the font color OK, like this:
But I cannot figure out how to change the background color. I have a database field for this - {Report_SELECT_TagLayouts.BackgroundColorHex}, but even if I just use regular HEX values it doesn't work. I've tried different tags - div, span etc. - no luck.
I understand that Crystal reports support only limited number of HTML tags, but whatever I try is not working. Font color is fine.
I would appreciate your suggestions.
Unfortunately, you will need to convert your hex to rgb.
I would then go to then go to the border tab, click on the background X-2 in the Color box.
You would then place the your criteria (if x then color(r,g,b) else crNoColor
You will probably need to create a variable formula for the rgb conversion
i.g.
local numberVar R;
local numberVar B;
local numberVar G;
local stringVar convert;
convert =: R & "," & "," & B & "," & G;
if x then color(convert) else crNoColor
good news though is that someone has already done conversion math.
http://www.rapidtables.com/convert/color/hex-to-rgb.htm

libgdx/box2d lights: change blur of lights

I was wondering whether it is possible to change the rate at which a lights intensity decareases over distance.
something like this:
So I finally figuered it out.
You have to write a custom shader that is essetially the same as the default one, but change the line that takes care of the interpolation:
"v_color = s*quad_colors;\n"
for example:
"v_color = s*2*quad_colors;\n"
halves the dropoff rate, while:
"v_color = (s*0)+quad_colors;\n"
gets rid of any blur (leaving out the "s" completely out won't work)
I have the "v_color = squad_colors;\n" its in the vertex shader of the light source. See https://github.com/libgdx/box2dlights/blob/master/src/shaders/LightShader.java. However the above didn't work for me, the number you use must be a float. E.g."v_color = (s0.0)+quad_colors;\n"

Is there any easy way to add color to single words in VB2010?

I been trying to research it a bit and this may be frowned upon, but I don't want to learn how to do everything in VB since I'm just doing what should be a 5-10 minute program to make something a little easier for myself. So sorry for that in advance.
Anyways, I just want to add colors or any formatting really to make stuff easier to read or the like. I originally was doing textboxes with the read only attribute and found you couldn't add good formatting with it. Label was similar in terms you could add one color a label. RichTextBox was the next idea and while it works, it seems like quite a bit of work for what I'm needing.
I just want an idea on how to make a single form have a font like "these three words"
It's super easy with bbcone and html, and I can't imagine the best way in VB is something that takes around 10 lines for one string of text.
Thanks.
Like you don't want to learn how to, but have notions of Html, then I think that the best solution for your needs is to use this 3rd party user-control, Html Renderer, which can render html/css code.
Another approach is to use a WebBrowser as mentioned in the comments, however, it will be (very)slower, or also you can use the MSHTML ocx which Microsoft specified that is more focused to document renderization tasks, but is harder to use than the specified user-control because you will need to investigate for the online documentation and usage of the MSHTML members, and seems that you don't want to do, since you specified that a RichTextBox has too much effort for your needs.
I have a richtextbox1 which has some text in it - I use the code below to search through the text and change specific words to a different font/style and color :-
DIM TZZ as String
TZZ = RichTextBox1.Text
TZZ = UCase(TZZ)
Dim x As Single
For X = 1 To Len(TZZ)
Dim y As Single = InStr(TZZ, "CHANGES MADE")
If y > 0 Then
Dim intLength As Integer = 12
'select the text
RichTextBox1.Select(y - 1, intLength)
RichTextBox1.SelectionFont = New System.Drawing.Font("Tahoma", 10, FontStyle.Bold Or FontStyle.Italic)
RichTextBox1.SelectionColor = Color.Red
Mid(TZZ, y, 12) = "123456789012"
X = y
End If
Next X
RichTextBox1.Select(0, 0)

Best and most performant implementation of dynamic shapes in cesium

I am currently working an application that is using a Cesium Viewer. I need to be able to display a collection of shapes that will be updated dynamically. I am having trouble understanding the best way to do this.
I currently am using Entities and using CallbackProperties to allow for the updating of shapes.
You can through this into a sandcastle to get an idea of how I am doing this. There is a polygon object that is being used as the basis for the cesiumCallback, and it is getting edited by another piece of code. (simulated with the setTimeout)
var viewer = new Cesium.Viewer('cesiumContainer', {});
var polygon = {};
polygon.coordinates = [
{longitude: 0, latitude: 0, altitude: 0},
{longitude: 10, latitude: 10, altitude: 0},
{longitude: 10, latitude: 0, altitude: 0}
];
// converts generic style options to cesium one (aka color -> material)
var polOpts = {};
// function for getting location
polOpts.hierarchy = new Cesium.CallbackProperty(function() {
var hierarchy = [];
for (var i = 0; i < polygon.coordinates.length; i++) {
var coordinate = polygon.coordinates[i];
hierarchy.push(Cesium.Cartesian3.fromDegrees(coordinate.longitude, coordinate.latitude, coordinate.altitude));
}
return hierarchy;
}, false);
viewer.entities.add({polygon: polOpts});
setInterval(function(polygon){
polygon.coordinates[0].longitude--;
}.bind(this, polygon), 1000);
The polygon being passed in is a class that generically describes a polygon, so it has an array of coordinates and style options, as well as a render method that calls this method renderPolygon passing in itself.
This method of rendering shapes works for everything I need it to, but it is not very performant. There are two cases for shapes updating, one type of shape will be updated over a long period of time, as a slow rate like once every few seconds. The other is shapes that will will get updated many times, like thousands, in a few seconds, then not change again for a long time, if ever.
I had two ideas for how to fix this.
Idea 1:
Have two methods, a renderDynamicPolygon and a renderStaticPolygon.
The renderDynamicPolygon method would do the above functionality, using the cesiumCallbackProperties. This would be used for shapes that are getting updated many times during the short time they are being updated.
The renderStaticPolygon method would replace the entities properties that are using callbackProperties with constant values, once the updating is done.
This creates a lot of other work to make sure shapes are in the right state, and doesn't help the shapes that are being updated slowly over a long period of time.
Idea 2:
Similarly to how the primitives work, I tried removing the old entity and adding it again with its updated properties each time its need to be updated, but this resulted in flickering, and unlike primitives, i could not find a async property for entities.
I also tried using primitives. It worked great for polylines, I would simply remove the old one and add a new one with the updated properties. I was also using the async = false to ensure there was no flickering. This issue I ran into here was not all shapes can be created using primitives. (Is this true?)
The other thing I tried was using the geometry instance using the geometry and appearance. After going through the tutorial on the cesium website I was able to render a few shapes, and could update the appearance, but found it close to impossible to figure out how to update the shapes correctly, and also have a very hard time getting them to look correct. Shapes need to have the right shape, a fill color and opacity and a stroke color, opacity and weight. I tried to use the polygonOutlineGeometry, but had not luck.
What would be the best way to implement this? Are one of these options headed the right way or is there some other method of doing this I have not uncovered yet?
[Edit] I added an answer of where I have gotten, but still not complete and looking for answers.
I have came up with a pretty good solution to this, but it still has one small issue.
I made too ways of showing entities. I am calling one render and one paint. Render uses the the Cesium.CallbackProperty with the isConstant property true, and paint with the isConstantProperty false.
Then I created a function to change the an entity from render to paint and vice vera. It goes through the entities callback properties an uses the setCallback property to overwrite the property with a the correct function and isConstant value.
Example:
I create a ellipse based on a circle object I have defined.
// isConst is True if it is being "painted" and false if it is being "rendered"
ellipse: lenz.util.extend(this._getStyleOptions(circle), {
semiMinorAxis: new Cesium.CallbackProperty(
this._getRadius.bind(this, circle),
isConst
),
semiMajorAxis: new Cesium.CallbackProperty(
this._getRadius.bind(this, circle),
isConst
),
})
So when the shape is being updated (while the user is drawing a shape) the shape is rendered with the isConstant being false.
Then when the drawing is complete it is converted to the painted version using some code like this:
existingEntity.ellipse.semiMinorAxis.setCallback(
this._getRadius.bind(this, circle),
isConst
);
existingEntity.ellipse.semiMajorAxis.setCallback(
this._getRadius.bind(this, circle, 1),
isConst
);
This works great performance wise. I am able to draw hundreds of shapes without the frame dropping much at all. I have attached a screen shot of the cesium map with 612 entities before and after my changes, the frame rate is in the upper right using the chrome render tool.
Before: Locked up at fps 0.9
Note: I redacted the rest of the ui, witch makes the globe look cut off, sorry
And after the changes: The fps remains at 59.9, almost perfect!
Whenever the entity is 'converted' from using constant to not constant callback properties, it and all other entities of the same type flash off then on again. I cannot find a better way to do this conversion. I feel as thought there must still be some thing I am missing.
You could try using a PositionPropertyArray as the polygon's hierarchy with SampledPositionProperty for any dynamic positions and ConstantPositionProperty for any static positions. I'm not sure if it would perform any better than your solution, but it might be worth testing. Here is an example of how it might work that you can paste into the Cesium Sandcastle:
var viewer = new Cesium.Viewer('cesiumContainer', {});
// required if you want no interpolation of position between times
var noInterpolation = {
type: 'No Interpolation',
getRequiredDataPoints: function (degree) {
return 2;
},
interpolateOrderZero: function (x, xTable, yTable, yStride, result) {
if (!Cesium.defined(result)) {
result = new Array(yStride);
}
for (var i = 0; i < yStride; i++) {
result[i] = yTable[i];
}
return result;
}
};
var start = viewer.clock.currentTime;
// set up the sampled position property
var sampledPositionProperty = new Cesium.SampledPositionProperty();
sampledPositionProperty.forwardExtrapolationType = Cesium.ExtrapolationType.HOLD;
sampledPositionProperty.addSample(start, new Cesium.Cartesian3.fromDegrees(0, 0)); // initial position
sampledPositionProperty.setInterpolationOptions({
interpolationAlgorithm: noInterpolation
});
// set up the sampled position property array
var positions = [
sampledPositionProperty,
new Cesium.ConstantPositionProperty(new Cesium.Cartesian3.fromDegrees(10, 10)),
new Cesium.ConstantPositionProperty(new Cesium.Cartesian3.fromDegrees(10, 0))
];
// add the polygon to Cesium viewer
var polygonEntity = new Cesium.Entity({
polygon: {
hierarchy: new Cesium.PositionPropertyArray(positions)
}
});
viewer.zoomTo(viewer.entities.add(polygonEntity));
// add a sample every second
var counter = 1;
setInterval(function(positionArray) {
var time = new Cesium.JulianDate.addSeconds(start, counter, new Cesium.JulianDate());
var position = new Cesium.Cartesian3.fromDegrees(-counter, 0);
positionArray[0].addSample(time, position);
counter++;
}.bind(this, positions), 1000);
One nice thing about this is you can set the timeline start/end time to a reasonable range and use it to see your polygon at any time within the sample range so you can see the history of your polygons through time (See here for how to change the timeline start/end time). Additionally, you don't need to use timers to set the positions, the time is built in to the SampledPositionProperty (although you can still add samples asynchronously).
However, this also means that the position depends on the current time in the timeline instead of a real-time array value. And you might need to keep track of a time somewhere if you aren't adding all the samples at once.
I've also never done this using ellipses before, but the semiMinorAxis and semiMajorAxis are properties, so you might still be able to use a SampledProperty.
Of course, this doesn't really matter if there are still performance issues. Hopefully it will improve as you don't need to recreate the array from scratch each callback and, depending on how you're getting the data to update the polygons, you might be able to add multiple samples at once. This is just speculation, but it's something to consider.
EDIT
Cesium can handle quite a bit of samples added to a sampled position, for example in the above code if you add a million samples to the position it takes a few seconds to load them all, but renders the polygon at any time without any performance issues. To test this, instead of adding samples using a timer, just add them all directly to the property.
for (var i = 0; i < 1000000; i++) {
var time = new Cesium.JulianDate.addSeconds(start, i, new Cesium.JulianDate());
var position = new Cesium.Cartesian3.fromDegrees(-(i % 2), 0);
positions[0].addSample(time, position);
}
However, if you run into memory problems currently there is no way to remove samples from a position property without accessing private variables. A work around would be to periodically create a new array containing new position properties and use the previous position property array's setValue() method to clear previous values or perhaps to use a TimeIntervalCollectionProperty as in this answer and remove time intervals with the removeInterval method.

Keeping the current CCSprite to another scenes

I'm a beginner of using cocos2d-x.
My problem is I dun know how to keep the CCSprite to another scenes.
The details of my case:
I've made a class"Scene01"includes 5 characters CCSprite with attributes, each of them class name like C1,C2...C5.
I've made a "Draw" button at class"Scene02"to draw out 1 of them randomly. I put this action at "CCTouchesBegan"...the character draw setting as below:
if (probability >0 && probability <=20) {result = C1::create();}
else if (probability >20 && probability <=40){result = C2::create();}
...until C5::create();
I use "this->addChild(result);" display on "Scene02" at "CCTouchesBegan".
But I don't know how to keep the generated "result(CCSprite)" to the new scene class"Scene03". Is there any better way(s) to simplify my case or any method(s) can help me to complete it?
You could try the following: retain the Sprite, remove it from Scene02 (keeping it on the heap) and then add it to the Scene03.
//(Scene02)
result->retain();
result->removeFromParent();
..
//(Scene03)
this->addChild(result);
result->release();