I am attempting to build a simulated sonar waterfall display by deleting the bottom line of pixels of an image and appending a new line at the top to simulate the sonar display. This causes the LC memory to expand 3meg a second. Routine waterfall in card is:
on waterfall
set lockScreen to true
put "plot" into pImage
put 400 into pWidth
put 200 into pHeight
set the height of image pImage to pHeight
set the width of image pImage to pWidth
put the imageData of image pImage into iData
delete char -1600 to -1 of iData
put 1 into y
put "" into nData
repeat with x = 1 to pWidth
put random (10) into gry
put gry into r
put random (255) into g
put gry into b
put numToChar(255) into char ((y - 1) * pWidth * 4) + ((x - 1) * 4) + 1 of nData
put numToChar(r) into char ((y - 1) * pWidth * 4) + ((x - 1) * 4) + 2 of nData
put numToChar(g) into char ((y - 1) * pWidth * 4) + ((x - 1) * 4) + 3 of nData
put numToChar(b) into char ((y - 1) * pWidth * 4) + ((x - 1) * 4) + 4 of nData
end repeat
put nData before iData
set the imageData of image pImage to iData
set the rect of image pImage to the rect of graphic "BlackBack"
put "" into iData
put "" into nData
if the hilited of button "WaterFallon" is true then send waterFall to this card in .05 seconds
end waterFall
######## a checkbox button starts the display with this code:
on mouseUp
if the hilited of me is true then
put "BlackBack" into pGraphic
if there is a graphic pGraphic then delete graphic pGraphic
create graphic pGraphic
set the height of graphic pGraphic to 200
set the width of graphic pGraphic to 400
set the opaque of graphic pGraphic to true
set the backgroundColor of graphic pGraphic to black
set the topLeft of graphic pGraphic to 0,0
put "plot" into pImage
if there is an image pImage then delete image pImage
create image pImage
send waterFall to this card
end if
end mouseUp
Add the following line at the end of the repeat loop, right before end repeat:
wait 0 millisecs with messages
This gives LiveCode a little time to update the GUI and discard old versions of the screen.
Related
I just wrote this code to perform an iterative calculation. It finds the X,Y coordinates where an unknown parabola is tangent to a known circle. It is based on other iterative functions I've written that have worked flawlessly. I'm stumped as to what the issue is. Here is the code:
Public Function Jext(PA As Double, Xcl As Double, Ycl As Double, Ctr As Double, Rnl As Double, Finl As Double) As Double
Pi = 3.14159265358979
tol = 0.00000001
Dim x(20) As Double
Dim Yc(20) As Double
Dim Yp(20) As Double
Dim A(20) As Double
Dim Diff(20) As Double
Dim It As Integer
Dim hF As Double
Dim Sf As Double
'Xcl is the horizontal position of the root radius center line
'Ycl is the vertical position of the root radius center line
'Ctr is root radius. It's an approximation of the trochoid and is typically the cutter tip radius
'Rnl is the radius to the point where the load line intersects the tooth centerline. It is the apex of the parabola
'x is the horizontal position that is common to the parabola and circle. It is the independent variable
'Yc is the vertical position on the circle at point x
'Yp is the vertical position on the parabola at point x
'A is the leading term of the parabolic equation
'Diff is the calculated difference in vertical positions of circle and parabola
'Set initial guess values. x(0) is 5% of the radius (left edge of circle) and x(1) is 95% of the radius(bottom of the circle)
x(0) = (Xcl - Ctr) + 0.05 * Ctr
x(1) = (Xcl - Ctr) + 0.95 * Ctr
Yc(0) = Ycl - (Ctr ^ 2 - (x(0) - Xcl) ^ 2) ^ 0.5
Yc(1) = Ycl - (Ctr ^ 2 - (x(1) - Xcl) ^ 2) ^ 0.5
A(0) = Tan(WorksheetFunction.Acos((Xcl - x(0)) / Ctr) + Pi / 2) / (2 * x(0))
A(1) = Tan(WorksheetFunction.Acos((Xcl - x(1)) / Ctr) + Pi / 2) / (2 * x(1))
Yp(0) = A(0) * x(0) ^ 2 + Rnl
Yp(1) = A(1) * x(1) ^ 2 + Rnl
Diff(0) = Yp(0) - Yc(0)
Diff(1) = Yp(1) - Yc(1)
For It = 1 To 19 Step 1
x(It + 1) = x(It) - (Diff(It) - 0) * (x(It - 1) - x(It)) / (Diff(It - 1) - Diff(It))
Yc(It + 1) = Ycl - (Ctr ^ 2 - (x(It + 1) - Xcl) ^ 2) ^ 0.5
A(It + 1) = Tan(WorksheetFunction.Acos((Xcl - x(It + 1)) / Ctr) + Pi / 2) / (2 * x(It + 1))
Yp(It + 1) = A(It + 1) * x(It + 1) ^ 2 + Rnl
Diff(It + 1) = Yp(It + 1) - Yc(It + 1)
If Abs(Diff(It + 1)) < tol Then Exit For
Debug.Print Diff(It + 1)
Next It
hF = Rnl - Yp(t + 1)
Sf = 2 * x(t + 1)
Jext = 1 / (Cos(Finl) / Cos(PA) * (6 * hF / Sf ^ 2 - Tan(Finl) / Sf))
End Function
I put a stop at the "Next It" line to check the values as it went through the iterative loops. When I execute the code, all of the values are as expected and the value of Abs(Diff(It+1)) is not small enough to exit the for loop in the IF statement. I put the Debug.Print statement in there to make sure it was getting that far in the code and it did print Diff(It+1). So it executes everything to that point. Then when I continue the function it just stops and returns a #VALUE error in the spreadsheet. I've no idea why it won't continue the for loop. Anyone see something I've missed?
I'm trying to make a label move from one cell to another. I figured out the position offsets and created 3 "tweens" as animators call them. But when I run the code, the Label doesn't display until the sub has ended. If I comment out the last position the label is in the right spot. How do I make Excel update the screen to show the label before I move it again?
xo and yo are integers either -1, 0, or 1. playerLocation is a range, might as well be ActiveCell.
Sub moveAnimation()
Dim moveAnim As OLEObject
Set moveAnim = Worksheets(currentSheet).OLEObjects(currentSheet & "player")
moveAnim.Left = playerLocation.Left - 0.5 + yo * (playerLocation.Width / 4)
moveAnim.Top = playerLocation.Top + 0.25 + xo * (playerLocation.Width / 4)
Sleep (25)
moveAnim.Left = playerLocation.Left - 0.5 + yo * (playerLocation.Width / 2)
moveAnim.Top = playerLocation.Top + 0.25 + xo * (playerLocation.Width / 2)
Sleep (25)
moveAnim.Left = playerLocation.Left - 0.5 + yo * 3 * (playerLocation.Width / 4)
moveAnim.Top = playerLocation.Top + 0.25 + xo * 3 * (playerLocation.Width / 4)
Sleep (25)
moveAnim.Left = 0
moveAnim.Top = 0
I've figured it out. ActiveSheet.Calculate will force an update so i put it between each position
I have a list of lat long coordinates each with corresponding azimuths (directions) such as:
Site | Cell | Lat | Long | Azimuth (degrees) | Beamwidth
CE0001 | CE0001U09A1 | X | Y | 0 | 65
CE0001 | CE0001U09B1 | X | Y | 120 | 65
CE0001 | CE0001U09C1 | X | Y | 240 | 65
For each unique cell, I would like to create a triangular polygon that is oriented in the direction of the azimuth for the corresponding cell with a width of 65degs and a radius of say 2km. I would like to generate shapes similar to what is shown below.
Can anyone point me in the direction as to how I could begin coding this up to loop through each entry in my file and how to generate a single google earth file that contains a polygon for each one? There are approx 9000 or so cells that require a polygon but if I can get this working for a small sample I would be very happy.
Here is and old post I made to a forum of a script to build hexagon tiles. Some of the calls are to the GIS API but I think you can probably extracted the needed VBA code:
.. VB script to create some hexagon tiles.
It creates tiles of a given radius (circle around a tile), not side length. If you want side length you will need to do the math and updte the code.
Here is the Comments from the .map file:
Creating a drawing of hexagon tiles:
R - radius
Radius of circumscribed circle around tile
a - Apothem:
Distance from centroid perpendicular to a side
a = R * cos(1/2 * 360/n) (n=6 for a hexagon
A set of hexagon tiles would be a series of six sided
"circles" centered on two point grids (1 & 2). Both grids
would have the spacing of:
in X --- 3R
in Y --- 2a
Grid 2 would be offset from grid 1 by:
in X ---- 3R/2
in Y ---- 2a/2
To test script delete all objects in A then
run the script.
This sample was only tested with a lat/long drawing. I'm not
sure of all the ramifications of using a projected drawing.
To use with your data set the start point (upper left) in the script and desired radius.
Set precision and run Normailize Topology when done to join
the tiles.
Code was based on the FreeStuff sample scripts ScriptRandomPoints
and ScriptSpatialOperations.
Please post any problems you find with this code.
Hmmm.. the attachments option is gone? :-?
Send me your address via email and send the .map file if you'd like.
Here's the code:
Sub Main
' test lat/long drawing
' ** ** delete all objects in A to test
set drawing = Application.ActiveDocument.ComponentSet("A")
set objects = drawing.ObjectSet
sides = 6
pi = 3.14159
R = 2.5 ' radius in degrees
interiorAngle = (360/6) * (pi / 180) ' in radians
a = abs(R * cos(0.5 * interiorAngle)) ' apothem
' pick/make a start point - upper left
Set startPoint = Application.NewPoint
startPoint.X = -25
startPoint.Y = 73.6602540378444
' grid (4x3x2)
for i = 0 to 3
for j = 0 to 2
' -- create point grid 1
Set point = Application.NewPoint
point.X = startPoint.X + (i * 3 * R)
point.Y = startPoint.Y - (j * 2 * a)
' objects.Add Application.NewGeom(GeomPoint, point) ' centroid
Set pointSet = Application.NewPointSet
For k = 0 To sides -1
Set pt = Application.NewPoint
' calculate angle
angle = (k*2*Pi/sides)' - (360/sides)/2
' obtain point on circle
pt.X = point.X + R*Cos(angle)
pt.Y = point.Y + R*Sin(angle)
pointSet.Add(pt)
Next
objects.Add Application.NewGeom(GeomArea, pointSet)
' -- create point grid 2
Set point = Application.NewPoint
point.X = startPoint.X + (i * 3 * R) + ((3 * R)/2)
point.Y = startPoint.Y - (j * 2 * a) - a
' objects.Add Application.NewGeom(GeomPoint, point) ' centroid
Set pointSet = Application.NewPointSet
For k = 0 To sides -1
Set pt = Application.NewPoint
' calculate angle
angle = (k*2*Pi/sides)' - (360/sides)/2
' obtain point on circle
pt.X = point.X + R*Cos(angle)
pt.Y = point.Y + R*Sin(angle)
pointSet.Add(pt)
Next
objects.Add Application.NewGeom(GeomArea, pointSet)
next
next
msgbox "Done!"
End Sub
Here's a cleaned up version that just developes one hex tile. You should be able to modify it to do what you want.
Sub xx()
Dim startPoint As clsPoint
Dim Point As clsPoint
Dim pt As clsPoint
Dim pts As Collection
Dim s As String
' lat/long (western hemisphere?)
Dim sides, i, j, k As Integer
Dim Pi, R, interiorAngle, A, Angle As Double
sides = 6
Pi = 3.14159
R = 0.25 ' radius in degrees
interiorAngle = (360 / 6) * (Pi / 180) ' in radians
A = Abs(R * Cos(0.5 * interiorAngle)) ' apothem
' pick/make a start point - upper left
Set startPoint = New clsPoint
startPoint.X = -121.5
startPoint.Y = 35.5
s = "Longitude" & vbTab & "Latitude" & vbCrLf
s = s & startPoint.X & vbTab & startPoint.Y & vbCrLf
Set Point = New clsPoint
Point.X = startPoint.X '+ (i * 3 * R)
Point.Y = startPoint.Y '- (j * 2 * A)
Set pts = New Collection
For k = 0 To sides - 1
Set pt = New clsPoint
' calculate angle
Angle = (k * 2 * Pi / sides) ' - (360/sides)/2
' Debug.Print Angle
' obtain point on circle
pt.X = Point.X + R * Cos(Angle)
pt.Y = Point.Y + R * Sin(Angle)
pts.Add pt
Next
For Each pt In pts
s = s & pt.X & vbTab & pt.Y & vbCrLf
Next
Debug.Print s
Stop
End Sub
clsPoint just contains:
Public X As Double
Public Y As Double
I'm new to graphics and was wondering how I would go about creating an object boundary for my game.
Right now I have an object following my mouse. This works fine for my boundary when my ship has a rotation.z of 0. However, when I rotate the ship, the boundary has odd behavior.
I tried getting the world position of the ship and simply checking the x and y boundaries. However, the world position seems to give me a different x and y when I rotate. How can I
go about creating a boundary that works for all the rotations of my ship.
Here's my game(collisions turned off for purpose of help): http://www.cis.gvsu.edu/~chaua/CS371/WebGLProject/home.html
The behavior I'd like occurs when you don't rotate the ship.
Rotate the ship with left/right mouse.
Relevant code snippets(in render loop):
if(mouseLeftDown)
ship.rotation.z += leanSpeed;
if(mouseRightDown)
ship.rotation.z += -leanSpeed;
....
....
targetX = ((lastMouseX / window.innerWidth) * 2 - 1) * 90;
targetY = -((lastMouseY / window.innerHeight) * 2 - 1) * 60;
var worldPosition = (new THREE.Vector3()).getPositionFromMatrix(ship.matrixWorld);
if(worldPosition.x + targetX <= (randSpawnWidth/2)-500 && worldPosition.x + targetX >= -(randSpawnWidth/2)+500)
ship.translateX(targetX);
if(worldPosition.y + targetY <= (randSpawnHeight/2)-500 && worldPosition.y + targetY >= -(randSpawnHeight/2)+500)
ship.translateY(targetY);
I would appreciate any help. Thanks!
Is there any problem in this code where I am just trying to subtract the pixel values of images through direct access of pixels ..... Am assuming that the images are of same height and width ... Whenever I run the program I am getting completely black picture.....
IplImage * img3 = cvCreateImage(cvSize(img1->height,img1->width),IPL_DEPTH_32F,3);
// img2 and img1 both are IplImage pointers
cvZero(img3);
long value;
for ( int row = 0 ; row < img2->height * img2->width ; row ++ ){
value = &((uchar*)(img1->imageData))[row] - &((uchar*)(img2->imageData))[row] ;
img3->imageData[row] = value;
1) img2->height * img2->width calculate as constant before loop
2)
I dont understand this line
&((uchar*)(img1->imageData))[row] - &((uchar*)(img2->imageData))[row] - are you subtracting pointer from another pointer? Why?
value = img1->imageData[row] - img2->imageData[row]; should do the trick
3) you can not subtract RGB values by subtracting pixel values (if that is your goal)
4) if img3->imageData is *char, then you should multiply row * 4.