Counter in AS3 "without dynamic text field" - c++

What is the best way to program an LED number tick. I need to have a number display that goes up to 1,000,000.00. Dynamic text fields are not an option because of symbol instances. How would I make a counter?
ANIMATION
The numbers move in increments like an LED display. This
NUMBERS
The numbers multiple by ten each space over
decimal point numbers are not whole, so they go really fast
There's a 16,000 frame limit in flash
SYMBOLS
column of numbers that moves in increments, for each number place
WHAT WOULD IT REQUIRE?
numbers move at a rate in multiples of 10
decimal points times one hundred
FRAME BASED OR TIME BASED?
There's a 16,000 frame limit in Flash
Time based method would require a lot of code
the add and remove child issue
alt text http://www.ashcraftband.com/myspace/videodnd/number_example.jpg
TRANSITION EFFECT
A "tick"
move 10 pixels each time etc.
9 and 0 roll over smoothly

In Flash, and to achieve the result in your picture there, I would create 2 MovieClips:
A black bar with a decimal point
The grey digits in a column, 0 -> 0, as suggested by your pic
Then, combine the black bar and 9 of the digit columns into a single MovieClip to represent your counter, along with a custom base class for it. This allows you fine-grained control over the entire counter.
Provide a CounterClip::Step() or ::Tick() method (or whatever you want to call it) that can move the individual columns. You can use the flash.transitions.Tween class to create smooth animations (I think thats what it's called... I'm a bit rusty.)
If you find you need more than the 9 columns, you can change your Counter MovieClip class to support dynamically adding more digits.

i think it totally depends on the transition effect you are using while switching the numbers.

Related

QT infinite view on model

I am looking for a way to create an infinite view on a model that is not initialized completely. I would like to create something similar to an Excel spreadsheet, and all I came in was to start with an initialized model (e.g. 100x100 empty cells, maybe working on a database that has empty values), and then just dynamically add next rows/columns (and update view) once we are close to the end of a scrollbar.
But I am wondering if it is the best solution - I think I would definitively benefit from a model that's filled in only partially - by that, I mean store information in the model only about filled cells, and let view handle showing 'empty cells' (which would have been created once we - for example - click them).
I know it would be necessary to store XY positions and cell data (instead of only a 2D container with data), but I would like to try different solutions:
a) have a pointer-like container which would contain a list of filled cells with their positions on a 2D plane
b) have a 2D container with size (x,y), where x and y would mean the 'last filled cell' in a given dimension
And for both solutions, I would like to dynamically allocate more place once data is written.
So there is my question - how can it be achieved with QT model/view programming, if it is even possible to show 'ghost cells' without a model filled with empty data? It would be also nice if I could get a brief explanation of how it is done in apps like excel etc.
Well, your table will never be truly infinite unless you implement some indexing with numbers with infinite digit count and in that case, you will probably not be able to use Qt classes.
But I think you should choose some big enough number to define the maximum. It can be a really large number... if you are on a 64-bit machine, then your 'infinite' table can have 9,223,372,036,854,775,807 rows and the same number of columns. This big number happens to be the maximum of signed 64-bit int. And int is used for indexing with QModelIndex in QAbstractItemModel. So you can have a total of 8.5070592e+37 cells in your two-dimensional 'Excel' table. If this table size is not big enough for you then I do not know what is. Just for comparison, there are approximately 7e+27 atoms in the average human body, maybe a bit more after the covid lockdowns because people were eating instead of practicing sports. :) So you can count all atoms of all people on this planet (say there are a bit less than 10e+10 people altogether). But you will need to buy a bit bigger computer for this task.
So if you decide to go this way, then you can easily override QAbstractTableModel and display it in QTableView. Of course, you cannot save the underlying data in a two-dimensional array because you do not have enough memory. But you have to choose some other method. For example a QHash<QPoint, QString> where QPoint will represent the coordinates and QString the value (you can choose any other type instead of a string of course). Then when you will want to get the value for the given coordinates, you just look up the value in the hash table. The number of data points you will be able to hold depends only on your memory size. This solution is very simple, I guess it will be some 30 rows of code, not more.

Multidimensional array v. Sorting multiple arrays

I've hit a snag in continuing my work in a C++ program, I'm not sure what the best way to approach my problem is. Here is the situation in non-programming terms: I have a list of children and each child has a specific weight, age, and happiness. I have a way that people can visually view the bones of the child that is specific to these characteristics. (Think of an MMO character customization where there are sliders for each characteristic and when you slide the weight slider to heavy, the walk cycle looks like the character is heavier).
Before, my system had a set walk cycle for each end of the spectrum for each characteristic. For example, there is one specific walk cycle for the heaviest walk, one for the lightest walk, one for youngest walk, etc. There was not middle input, the output was the position of the slider on the scale and the heaviest walk cycle and the lightest walk cycle were averaged by a specific percentage, the position of the slider.
Now to the problem, I have a large library of preset walk cycles and each walk cycle has a specific weight, age, and happiness. So, Joe has a weight of 4, an age of 7, and happiness level of 8 and Sally 2, 3, 5. When the sliders move to a the specific value (weight 5, age 8, happiness 7). However, only one slider can be moved at one time and the slider that was moved last is the most important characteristic to find the closest match to. I want to find in my library the child that has the closest to all three of these values and Joe will be the closest.
I was told to check out using a 3 dimensional array but I would rather use an array of child objects and do multiple searches on that array which, I am a rookie and I know the search will take a bit of computing time but I keep leaning towards using the single array. I could also use a two dimensional array but I'm not sure. What data structure would be the best to search for three values in?
Thank you for any help!
How many different values can each slider take? If there are say ten values for each slider this would mean there are 10*10*10=1000 different possible character classes. If your library has less than 1000 walk cycles just reading through them all looking for the nearest match is probably gonna be fast enough.
Of course if there are 100 values for each slider then you may want something more clever. My point is there are some thing that don't have to be optimized.
Also is your library of walk cycles fixed once and for all? If so perhaps you could pre compute the walk cycle for each setting of the sliders and write that to a static array.
I agree with Wilf that the number of walk cycles is critical, as even if there are say 100,000 cycles you could easily use a brute-force find-the-maximum over...
weight_factor * diff(candidate.weight, target.weight) +
age_factor * diff(candidate.age, target.age) +
happiness_factor * diff(candidate.happiness, target.happiness)
...where the factor for the last-moved slider was higher than the others.
For more cycles than that you'd want to limit the search space somewhat, and some indices would be useful, e.g.:
map<int, map< int, map<int, vector<Cycle*>> cycles_by_weight_age_happiness;
You'd populate that adding a pointer to each walk cycle - characterised by { weight, age, happiness } - to cycles[rw(weight)][ra(age)][rh(happiness)], where each of rw, ra and rh rounded the parameters by whatever granularity you liked (e.g. round weight down to nearest 5kgs, group ages by integer part of log base 1.5 of age, leave happiness alone). Then to search you evaluate the entries "around" your target { rw(weight), ra(age), rh(happiness) } indices... the further from there you deviate (especially on the last-slider-moved parameter, the less likely you are to find a better fit than you've already seen, so tune to taste.
The above indexing is a refinement of what I think Wilf intended - just using functions to decouple the mapping from value space into vectors in the index.

Counting different ways to create QR code

I am working on an app that needs to create QR-code through a code, essentialy as for now
I thought on generating something similar to a sudoku board (9X9 squares of 3X3 sections) s.t. every odd number is beeing painted black and every double number is being painted in white.
I am stuck not on a code but rather on trying to figure out how many DIFFERENT options do I have to create images in that manner as for now -
For every 3X3 section I have (9 choose 5) options to place black "tiles" and I have 9 of those
which makes it (9 choose 5)^9 = 126^9 = 8.00451285e18 which is a really big number..
For some reason that seems wrong...any help?
I am using choose since the arrangment of the odd number is irrelvant because the two placments on the attached image gives the same result

make mandelbrot heightmap stay in one place

i have a small problem where my mandelbrot set is represented as a heightmap matrix, when every cell contains the number of iterations it took a single point to reach infinity or less.
in the end a 3d model is printed. my problem appears when i zoom rapidly and i begin to see that the entire set floats(because the number of iterations gets higher for each pixel).
is there a way to force the model to stay on 0 (y axis) but still let it grow as each point gets different number of iterations?
i've tried to find the point which requires the smallest amount of iterations(and basically the lowest point in the set) and subtracts it from all points but that didn't work.(since num of iterations changes every zoom process it made the set jump from value 5 to 100 for example).
This problem happens to 2D fractal maps as well, the escape value's color representation "shifts". If you zoom with a factor of 10, every 10th point should be a point from a non-zoomed version, but as iterations grow along with zoom these points will not be the same.
The solution (for me it was) is to find the largest zoom which you want to achieve, find the appropriate iteration factor for that zoom level (for precise calculations), and apply this iteration factor every time even for zoom level 0.
This will make the calculation slow, in my case I had to iterate every point 5000 times regardless of zoom level.

design exercise preferably using mfc

i was told to design a paintbrush program in 2 variation , one that uses lots of space and little cpu and the other vice versa.
the idea (as i was told- so not sure) is somehow to save the screen snapshots versus saving XOR maps (which i have no idea what it means) who represent the delta between the painting.
can someone suggest a way or add links to related material ?
The obvious place to put the screen shots to use would be to implement an "undo" command. The simple, memory-hog method is to take a snapshot of the screen before each action. If the user hits "undo", you can restore the old screen.
To save on memory space, you save only the difference between the two screens, by XORing them together. By itself, this doesn't actually save any space, but it sets all the unchanged pixels to 0. To save space, you'll then need to apply some sort of compression. Given that you can typically expect fairly large areas that are all zero, a run-length encoding will probably be quick and effective. For a run-length encoding, you'll typically turn a string of identical bytes into two bytes, the first holding the length of the run, and the second holding the value. For example, 75 zeros in a row would be encoded as 75 0.
If you wanted to go a step further, instead of saving XORed bitmaps, you could look into using a metafile. A metafile records the actions taken at the level of Windows GDI calls, so (for example) if you drew a red 100x200 rectangle at 10, 100, it would record essentially that -- i.e. instead of the twenty thousand pixels, it would save an identifier saying what GDI function to execute, and the parameters to supply to that function. In a typical case, this might average around 15-20 bytes per "command" executed. At the same time, it does (often) involve more computation -- for example, if you draw a circle, re-running a metafile requires re-rastering the circle instead of just storing the bits it produced.