Skip to content

Commit

Permalink
Use a coil image for visual distinction between springs and ropes/rod…
Browse files Browse the repository at this point in the history
…s. (#20)
  • Loading branch information
jaipack17 authored Dec 31, 2021
1 parent 17b4a67 commit cbfe7ac
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 16 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div align="center">
<img src="https://doy2mn9upadnk.cloudfront.net/uploads/default/original/4X/e/7/0/e709b34f89add2336a7d74faee3b2a839a9391b0.png" width="480" /><br/><br/>
<a href="https://devforum.roblox.com/t/physics-library-nature2d-bring-ui-elements-to-life/1510935/75"><img alt="version" src="https://img.shields.io/badge/v0.5.4--beta-version-%231FD67F"></img></a>
<a href="https://devforum.roblox.com/t/physics-library-nature2d-bring-ui-elements-to-life/1510935/75"><img alt="version" src="https://img.shields.io/badge/v0.5.5--beta-version-%231FD67F"></img></a>
<br/>
<a href="https://devforum.roblox.com/t/physics-library-nature2d-bring-ui-elements-to-life/1510935/"><img alt="devforum" src="https://img.shields.io/badge/topic-devforum-white"></img></a>
<a href="https://www.roblox.com/library/7625799164/Nature2D"><img alt="model" src="https://img.shields.io/badge/asset-roblox-white"></img></a>
Expand Down Expand Up @@ -34,7 +34,7 @@ https://www.roblox.com/library/7625799164/Nature2D
**Using wally** - Use [wally](https://github.com/UpliftGames/wally), a package manager for roblox to install Nature2D in your external code editor. This requires wally to be installed on your device. Then, add Nature2D to the dependencies listed in your `wally.toml` file.<br/>
```toml
[dependencies]
Nature2D = "jaipack17/[email protected].4"
Nature2D = "jaipack17/[email protected].5"
```
After that, Run `wally install` in the cli. Nature2D should be installed in your root directory. If you encounter any errors or problems installing Nature2D using wally, [open an issue!](https://github.com/jaipack17/Nature2D/issues)

Expand Down
4 changes: 2 additions & 2 deletions src/Engine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ function Engine:Create(object: string, properties: Types.Properties)
restLength = properties.RestLength or dist,
render = properties.Visible,
thickness = properties.Thickness,
support = true,
support = false,
TYPE = string.upper(properties.Type)
}, self)

Expand Down Expand Up @@ -535,4 +535,4 @@ function Engine:FrameRateIndependent(independent: boolean)
self.independent = independent
end

return Engine
return Engine
7 changes: 4 additions & 3 deletions src/Physics/Constraint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,14 @@ function Constraint:Render()

local thickness = self.thickness or Globals.constraint.thickness
local color = self.color or Globals.constraint.color

local image = self._TYPE == "SPRING" and "rbxassetid://8404350124" or nil

if not self.frame then
self.frame = line(self.point1.pos, self.point2.pos, self.canvas.frame, thickness, color)
self.frame = line(self.point1.pos, self.point2.pos, self.canvas.frame, thickness, color, nil, image)
end

-- Draw constraint on screen
line(self.point1.pos, self.point2.pos, self.canvas.frame, thickness, color, self.frame)
line(self.point1.pos, self.point2.pos, self.canvas.frame, thickness, color, self.frame, image)
end
end

Expand Down
24 changes: 16 additions & 8 deletions src/Utilities/Line.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,34 @@
local Globals = require(script.Parent.Parent.Constants.Globals)

-- Create the constraint's instance and apply properties
local function draw(hyp: number, origin: Vector2, thickness: number, parent: Instance, color: Color3, l: Frame?) : Frame
local line = l or Instance.new("Frame")
local function draw(hyp: number, origin: Vector2, thickness: number, parent: Instance, color: Color3, l: Frame?, image: string?) : Frame
local line = l or (image and Instance.new("ImageLabel") or Instance.new("Frame"))
line.Name = "Constraint"
line.AnchorPoint = Vector2.new(.5, .5)
line.Size = UDim2.new(0, hyp, 0, thickness or Globals.constraint.thickness)
line.BackgroundColor3 = color or Globals.constraint.color
line.Size = UDim2.new(0, hyp, 0, (thickness or Globals.constraint.thickness) + (image and 15 or 0))
line.BackgroundTransparency = image and 1 or 0
line.BorderSizePixel = 0
line.Position = UDim2.fromOffset(origin.X, origin.Y)
line.ZIndex = 1
line.Parent = parent

if image then
line.Image = image
line.ImageColor3 = color or Globals.constraint.color
else
line.BackgroundColor3 = color or Globals.constraint.color
end

line.Parent = parent

return line
end

return function (origin: Vector2, endpoint: Vector2, parent: Instance, thickness: number, color: Color3, l: Frame?) : Frame
return function (origin: Vector2, endpoint: Vector2, parent: Instance, thickness: number, color: Color3, l: Frame?, image: string?) : Frame
-- Calculate magnitude between the constraint's points
-- Draw the constraint
-- Calculate rotation
local hyp = (endpoint - origin).Magnitude
local line = draw(hyp, origin, thickness, parent, color, l)
local line = draw(hyp, origin, thickness, parent, color, l, image)
local mid = (origin + endpoint)/2
local theta = math.atan2((origin - endpoint).Y, (origin - endpoint).X)

Expand All @@ -32,4 +40,4 @@ return function (origin: Vector2, endpoint: Vector2, parent: Instance, thickness
line.Rotation = math.deg(theta)

return line
end
end
2 changes: 1 addition & 1 deletion wally.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "jaipack17/nature2d"
description = "Create versatile physics simulations and mechanics with Guis on Roblox!"
authors = ["jaipack17"]
version = "0.5.4"
version = "0.5.5"
license = "MIT"
registry = "https://github.com/UpliftGames/wally-index"
realm = "shared"
Expand Down

0 comments on commit cbfe7ac

Please sign in to comment.