How can i create a trail of a moving displayObject? [closed] - actionscript-3

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
some elegant way to create a shadow trail of a object ,e.g a plane?
this answer i can't understand this ,im a starter for as3 .
so , some directly code should be very good for me .

var dis : DisplayObject;
var prevDis : DisplayObject;
for ( var i:int = _displayList. length -1; i >= 1; i-- ) //reverse recursive
{
dis = _displayList[ i ];
prevDis = _displayList[ i -1 ] ;
dis . x = prevDis .x;
dis . y = prevDis .y; //create ghost shadow effect
}
// need to locate the first displayObject's position by tween .
prevDis . x = int (_tween . target. x );
prevDis . y = int (_tween . target. y );
_tween . tick( delta );

Related

how to get azimuth and elevation from enu vectors [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 3 years ago.
Improve this question
How do you get the azimuth and elevation from one enu vector to another enu vector?
A link to a formula or piece of code would be helpful. I'm not getting much information at all when searching.
You can calculate the azimuth and elevation angles between East-North-Up vectors (x,y,z) and (u,v,w) using the following:
Subtract the vectors: (x,y,z) - (u,v,w) = (x-u,y-v,z-w) = (x',y',z')
Compute the azimuth angle: a = arctan(x'/y') = arctan((x-u)/(y-v))
Compute the elevation angle: e = arctan(z'/y') = arctan((z-w)/(y-v))
In Python:
v1 = np.array([3,4,4])
v2 = np.array([1,2,6])
v = v1 - v2
a = np.degrees(np.arctan(v[0]/v[1]))
e = np.degrees(np.arctan(v[2]/v[1]))
print('azimuth = '+str(a)+', elevation = '+str(e))
Output:
azimuth = 45.0, elevation = -45.0
(Image Source)

How to draw a line using X, Y, Z coordinates from a csv or txt file? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
and I'm having difficulty to drawing a line on the screen using the X, Y, Z coordinates of a CSV or TXT file. I tried with the line render and also with swipe trail, but I could not. Thanks for your help
Read a file e.g using StreamReader.ReadToEnd
var fileContent = "";
(using var reader = new StreamReader(path))
{
fileContent = reader.ReadToEnd();
}
Assuming a CSV/txt content like
23.46, 1.0, 2.4
0.003, 7.038, 3
...
Parse the content e.g. using SplitCSVLine from CSVReader
private static string[] SplitCsvLine(string line)
{
return (from System.Text.RegularExpressions.Match m in System.Text.RegularExpressions.Regex.Matches(line,
#"(((?<x>(?=[,\r\n]+))|""(?<x>([^""]|"""")+)""|(?<x>[^,\r\n]+)),?)",
System.Text.RegularExpressions.RegexOptions.ExplicitCapture)
select m.Groups[1].Value).ToArray();
}
use it together with float.TryParse(string, out float) like
var lines = fileContent.Split('/n');
var points = new List<Vector3>();
foreach(var line in lines)
{
var parts = SplitCsvLine(line);
float x = float.TryParse(parts[0], out x) ? x : 0;
float y = float.TryParse(parts[1], out y) ? y : 0;
float z = float.TryParse(parts[2], out z) ? z : 0;
points.Add(new Vector3(x, y, z));
}
where
float x = float.TryParse(parts[0], out x) ? x : 0;
is a short form of writing
float x;
if(!float.TryParse(parts[0], out x))
{
x = 0;
// Alternatively you could also declare this point as invalid
// and not add this point at all
continue;
}
or, if you know the content will only exactly contain those numeric symbols and commas, no special characters, you could also simply use
var parts = line.Split(',');
And finally apply those points e.g. to a LineRenderer using SetPositions
GetComponent<LineRenderer>().SetPositions(points);
There might be more efficient options though.

Can a sound be re-created from FFT? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I'm studying some FFT code's and I'm looking for the possibility to recreate a (cycling) sound that as been decomposed with a fast fourrier transform.
I tried by adding several sinuzoidal curves but it doesn't work at all.
I'm working with C++ but any help will be welcomed.
Thanks
It seems that have to answer my question alone... also I understood that the IFFT was what I looked for,I found a slower function but perfect for me:
void inverseDFT(const double *a, const double *b, const int &N, double *&s)
{
// note: this code is not optimised at all, written for clarity not speed.
for (int x = 0; x < N; ++x)
{
s[x] = a[0];
for (int k = 1; k <= N / 2; ++k)
{
s[x] += a[k] * cos(2 * M_PI / N * k * x) + b[k] * sin(2 * M_PI / N * k * x);
}
}
}
It works perfectly, maybe it will help someone else.

Tricky Triangle Design implementation [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am working on a website at the moment and have run into a problem with a triangle pattern.
The designer mocked the site up with triangular tiles and patterns :
Please note that I had to remove most of the content to post it here, but there is content on top of the triangular pattern.
I have done some research on how to implement the triangles in HTML,CSS and possibly JS(?) and came up with three possible options:
background-image
clipping divs and positioning them
using svg and positioning this
The problem with a background-image is that some of these tiles will later change on click and show things etc. So they really shouldn't be on a picture
I have started clipping and positioning divs, but this is just taking forever and I am starting to feel like this cannot be the best solution. Loads of fiddling and I think I will later have problems with inconsistencies
I don't have much experience working with svg, but I would have to draw them all one by one and position them as well (right? this is an assumption). Doesn't seem like the best practice approach.
Does anyone have any input on how I could solve this or do I just have to follow through with one of the solutions named above, as there is no quicker way.
I would really appreciate any ideas.
Thanks Anton
If you decide to go with the SVG route then the code to create the triangles can be relatively small. Store the colors in an array of arrays. Store the horizontal and vertical distance between triangles in two variables (e.g. dx and dy). Then loop through the colors array to draw the individual triangles.
JavaScript code...
var svgNS = "http://www.w3.org/2000/svg";
function drawTriangles() {
var svg = document.getElementById("mySvg");
var colors = [
["#0000FF", "#0044FF", "#0088FF", "#00CCFF"],
["#4400FF", "#4444FF", "#4488FF", "#44CCFF"],
["#8800FF", "#8844FF", "#8888FF", "#88CCFF"],
["#CC00FF", "#CC44FF", "#CC88FF", "#CCCCFF"],
];
var n = colors.length;
var m = colors[0].length;
var dx = 100;
var dy = 75;
for (var i = 0; i < n; i++) {
for (var j = 0; j < m; j++) {
var polygon = document.createElementNS(svgNS, "polygon");
var point0 = svg.createSVGPoint();
var point1 = svg.createSVGPoint();
var point2 = svg.createSVGPoint();
if ((i + j) % 2 === 0) {
point0.x = j * dx;
point0.y = i * dy;
point1.x = (j + 1) * dx;
point1.y = (i + 1) * dy;
point2.x = (j + 1) * dx;
point2.y = (i - 1) * dy;
} else {
point0.x = (j + 1) * dx;
point0.y = i * dy;
point1.x = j * dx;
point1.y = (i - 1) * dy;
point2.x = j * dx;
point2.y = (i + 1) * dy;
}
polygon.setAttribute("fill", colors[i][j]);
polygon.points.appendItem(point0);
polygon.points.appendItem(point1);
polygon.points.appendItem(point2);
svg.appendChild(polygon);
}
}
}
drawTriangles();
<svg id="mySvg" width="400" height="225"></svg>
If css shapes are an option, i would recommend to use them.
https://css-tricks.com/examples/ShapesOfCSS/
However you chose to create the boundaries of your containers, if you embed the svg directly into the html, you can access all the elements the same way you access html elements, and with them you can get their vertices. This way you could use that information to create the shapes.
The downside of that approach is that it is highly depending on javascript, if it is disabled or fails, the complete layout will fail, too. But you can react on layout changes at runtime.
To overcome this you might be able to process the svg on the server, but there you are missing out the final dimensions, what might not be problem if you use percentage values to position your content containers, but a huzzle to code.
All in all, if got this right, creating such a layout where content is arranged in triangles will need a lot of code in each case.
If the page will stay small and not much content be assigned, than doing everything by hand might be faster.

What should happen when a generator function is assigned? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
If I have a programming language with first class functions. What should the semantics be when a generator function is shared?
For example:
var f = function() {
foreach (i in 0..42)
yield i;
}
int a = f(); // 0
int b = f(); // 1
// Assigning the generator function
var g = f;
int c = g(); // ??
int d = f(); // ??
I can imagine three things:
c == 2, d == 3 meaning that the generator function is shared
c == 0, d == 2 meaning that a new generator function is created, with the values initialized
c == 2, d == 2 meaning that a new generator function is created by copying the current state of the generator
The best answer in my opinion, would provide the most compelling argument to do one mechanism or another. Often I find that prior art is the most persuasive argument.
If you have reference semantics in your language, and assignment is usually reference assignment, then you want option 1.
This is what happens in Python, where generates are objects, and assignment is reference assignment (even though you invoke .next() to retrieve the next value, rather than "calling" the generator).
Here is a brief demonstration how this behaves in Python:
>>> def gen():
... for i in range(42):
... yield i
...
>>> f = gen().next
>>> a = f()
>>> b = f()
>>> g = f
>>> c = g()
>>> d = f()
>>> a, b, c, d
(0, 1, 2, 3)