| Author | Message |
|---|---|
| iris87 |
Post Posted: Thu Jun 01, 2023 2:04 pm Post subject: Dot Animation Issue
|
| What is it you are trying to achieve?
A simple moving dots animation What is the problem you are having? Sometimes the dots sort of "stick" to a wall, because I'm just reversing the direction of the dots on collision it will always stick to walls. Describe what you have tried to solve this problem I attempted to add a randomness to the reversed angle, this works but not great, it still takes quite a few collisions while stuck on a wall to bounce away. Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) (ignore the repel from mouse related things, not implemented yet) Turing: setscreen ("graphics:max;max;nobuttonbar;offscreenonly;title:Connecting Dots") colorback (black ) const AmountOfDots := 100 const RepelFromMouse := true var DebugChar : string (1) var ColourArray : array 1 .. 100 of int for Colour : 1 .. 100 ColourArray (Colour) := RGB.AddColour (Colour / 100, Colour / 100, Colour / 100) end for type Dot : record X : int Y : int Speed : real Direction : int end record var DotArray : array 1 .. AmountOfDots of Dot for DotIndex : 1 .. AmountOfDots DotArray (DotIndex).X := Rand.Int (1, maxx - 1) DotArray (DotIndex).Y := Rand.Int (1, maxy - 1) DotArray (DotIndex).Speed := Rand.Int (20, 40) / 10 DotArray (DotIndex).Direction := Rand.Int (1, 360) end for function DegreeToRadian (degree : int) : real result degree * (Math.PI / 180) end DegreeToRadian % Render loop var lastFrameTime : int := Time.Elapsed var MouseX : int var MouseY : int var MouseDown : int var DistanceBetweenPoints : real var LineColour : int color (brightgreen ) loop cls Mouse.Where (MouseX, MouseY, MouseDown) put "FPS: ", round (1000 / (Time.Elapsed - lastFrameTime)) put "X:Y ", MouseX, ":", MouseY lastFrameTime := Time.Elapsed Time.DelaySinceLast (17) for DotIndex : 1 .. AmountOfDots if DotArray (DotIndex).X >= maxx then DotArray (DotIndex).X := maxx - 1 DotArray (DotIndex).Speed := Rand.Int (20, 40) / 10 DotArray (DotIndex).Direction := 180 - DotArray (DotIndex).Direction + Rand.Int(-20, 20) end if if DotArray (DotIndex).Y >= maxy then DotArray (DotIndex).Y := maxy - 1 DotArray (DotIndex).Speed := Rand.Int (20, 40) / 10 DotArray (DotIndex).Direction := -1 * DotArray (DotIndex).Direction + Rand.Int(-20, 20) end if if DotArray (DotIndex).X < 0 then DotArray (DotIndex).X := 1 DotArray (DotIndex).Speed := Rand.Int (20, 40) / 10 DotArray (DotIndex).Direction := 180 - DotArray (DotIndex).Direction + Rand.Int(-20, 20) end if if DotArray (DotIndex).Y < 0 then DotArray (DotIndex).Y := 1 DotArray (DotIndex).Speed := Rand.Int (20, 40) / 10 DotArray (DotIndex).Direction := -1 * DotArray (DotIndex).Direction + Rand.Int(-20, 20) end if DotArray (DotIndex).X += round (Math.cos (DegreeToRadian (DotArray (DotIndex).Direction)) * DotArray (DotIndex).Speed) DotArray (DotIndex).Y += round (Math.sin (DegreeToRadian (DotArray (DotIndex).Direction)) * DotArray (DotIndex).Speed) end for for DotIndex : 1 .. AmountOfDots for OtherDot : 1 .. AmountOfDots if OtherDot = DotIndex then exit end if DistanceBetweenPoints := sqrt ((DotArray (OtherDot).X - DotArray (DotIndex).X) ** 2 + (DotArray (OtherDot).Y - DotArray (DotIndex).Y) ** 2) if DistanceBetweenPoints < 150 then LineColour := ColourArray (100 - floor (DistanceBetweenPoints / 1.5)) drawline (DotArray (DotIndex).X, DotArray (DotIndex).Y, DotArray (OtherDot).X, DotArray (OtherDot).Y, LineColour) end if end for end for for DotIndex : 1 .. AmountOfDots drawfilloval (DotArray (DotIndex).X, DotArray (DotIndex).Y, 4, 4, white ) end for View.Update end loop Please specify what version of Turing you are using 4.1 |
|