Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local swait=function(num)if tonumber(num)then for i=1,tonumber(num)do game:service'RunService'.RenderStepped:wait()end else game:service'RunService'.RenderStepped:wait()end return true end
- local hwait=function(num)if tonumber(num)then for i=1,tonumber(num)do game:service'RunService'.Heartbeat:wait()end else game:service'RunService'.Heartbeat:wait()end return true end
- if script:IsA"Script"then
- swait=hwait
- end
- if"SimplexNoise"then
- --[[ Example implementation of tileable fractional brownian motion (not needed for pure simplex noise)
- x and z are the input coordinates.
- octs is the number of octaves of noise you would like.
- decay is how quickly the amplitude of the noise decays with each octave.
- ridged returns ridged fractal noise instead of regular simplex noise.
- function fbm(x,z,octs,decay,ridged)
- local X=x
- local Z=z
- -- results seem to be the best when x and z are small (why i devide them by 300) - scale them how you please.
- x=x/300
- z=z/300
- local val=0;
- for o=0,octs-1 do
- if (ridged) then
- val=val + math.abs(-(decay^o) * shared.noise(x * 2^o,z * 2^o));
- else
- val=val + (-(decay^o) * shared.noise(x * 2^o,z * 2^o))
- end
- end
- --return val
- end
- ]]
- grad3={{1,1,0},{-1,1,0},{1,-1,0},{-1,-1,0},{1,0,1},{-1,0,1},{1,0,-1},{-1,0,-1},{0,1,1},{0,-1,1},{0,1,-1},{0,-1,-1}}
- p={}
- function setnoise(seed)
- p={}
- math.randomseed(seed or 1)
- for i=0,255 do p[i]=math.random(0,255)end
- -- To remove the need for index wrapping, double the permutation table length
- perm={}for i=0, 511 do perm[i]=p[i%256]end
- end
- setnoise()
- function fastfloor(x)if x>0 then return math.floor(x)else return math.floor(x-1)end end
- function dot(g,x,y)return g[1]*x + g[1]*y end
- -- 2D simplex noise
- SimplexNoise=function(xin,yin,seed)
- if seed then setnoise(seed)end
- local i1,j1,n0,n2=nil
- xin=xin / 16
- yin=yin / 16
- local F2=0.5*(math.sqrt(3.0)-1.0);
- local s=(xin+yin)*F2; --// Hairy factor for 2D
- local i=fastfloor(xin+s);
- local j=fastfloor(yin+s);
- local G2=(3.0-math.sqrt(3.0))/6.0;
- local t=(i+j)*G2;
- local X0=i-t; --// Unskew the cell origin back to (x,y) space
- local Y0=j-t;
- local x0=xin-X0; --// The x,y distances from the cell origin
- local y0=yin-Y0;
- if x0>y0 then
- i1=1
- j1=0 --// lower triangle, XY order: (0,0)->(1,0)->(1,1)
- else
- i1=0
- j1=1
- end --// upper triangle, YX order: (0,0)->(0,1)->(1,1)
- local x1=x0 - i1 + G2; --// Offsets for middle corner in (x,y) unskewed coords
- local y1=y0 - j1 + G2;
- local x2=x0 - 1.0 + 2.0 * G2 --// Offsets for last corner in (x,y) unskewed coords
- local y2=y0 - 1.0 + 2.0 * G2
- --// Work out the hashed gradient indices of the three simplex corners
- local ii=i % 256
- local jj=j % 256
- local gi0=perm[ii+perm[jj]] % 12;
- local gi1=perm[ii+i1+perm[jj+j1]] % 12;
- local gi2=perm[ii+1+perm[jj+1]] % 12;
- --// Calculate the contribution from the three corners
- local t0=0.5 - x0*x0-y0*y0;
- if t0<0 then
- n0=0.0
- else
- t0=t0 * t0;
- n0=t0 * t0 * dot(grad3[gi0+1], x0, y0); --// (x,y) of grad3 used for 2D gradient
- end
- local t1=0.5 - x1*x1-y1*y1;
- local n1=nil
- if t1<0 then
- n1=0.0;
- else
- t1=t1 * t1;
- n1=t1 * t1 * dot(grad3[gi1+1], x1, y1);
- end
- local t2=0.5 - x2*x2-y2*y2;
- if (t2<0) then
- n2=0.0;
- else
- t2=t2 * t2;
- n2=t2 * t2 * dot(grad3[gi2+1], x2, y2);
- end
- -- Add contributions from each corner to get the final noise value.
- -- The result is scaled to return values in the interval [-1,1].
- return 70.0 * (n0 + n1 + n2);
- end
- end
- if"Triangle Function"then
- local wedge=Instance.new"WedgePart"wedge.TopSurface=Enum.SurfaceType.Smooth wedge.BottomSurface=Enum.SurfaceType.Smooth wedge.CanCollide=false
- Instance.new("SpecialMesh",wedge).MeshType="Wedge"wedge.Size=Vector3.new()
- function DrawTriangle(a,b,c,parent,PartStat,Collide,FadeOpt)
- a=typeof(a)=="CFrame"and a.p or a b=typeof(b)=="CFrame"and b.p or b c=typeof(c)=="CFrame"and c.p or c
- if not a or not b or not c then error'Attempt to use NIL value'end
- local TriangleModel=Instance.new("Model",parent)
- local siz=0 local edges={{longest=(c-b),other=(a-b),position=b},{longest=(a-c),other=(b-c),position=c},{longest=(b-a),other=(c-a),position=a}}
- table.sort(edges,function(a,b) return a.longest.magnitude > b.longest.magnitude end)local edge=edges[1]
- local theta=math.acos(edge.longest.unit:Dot(edge.other.unit))local s1=Vector2.new(edge.other.magnitude * math.cos(theta),edge.other.magnitude * math.sin(theta))
- local s2=Vector2.new(edge.longest.magnitude-s1.x,s1.y)local p1=edge.position + edge.other * 0.5 local p2=edge.position + edge.longest + (edge.other-edge.longest) * 0.5
- local right=edge.longest:Cross(edge.other).unit local up=right:Cross(edge.longest).unit local back=edge.longest.unit
- local cf1=CFrame.new(p1.x,p1.y,p1.z,-right.x,up.x,back.x,-right.y,up.y,back.y,-right.z,up.z,back.z)local cf2=CFrame.new(p2.x,p2.y,p2.z,right.x,up.x,-back.x,right.y,up.y,-back.y,right.z,up.z,-back.z)
- local w1=wedge:Clone()local w2=wedge:Clone()if not Collide then w1.Mesh.Scale=Vector3.new(siz,s1.y,s1.x)*20 w2.Mesh.Scale=Vector3.new(siz,s2.y,s2.x)*20 else w1.Size=Vector3.new(siz,s1.y,s1.x)w2.Size=Vector3.new(siz,s2.y,s2.x)end
- w1.CFrame=cf1 w2.CFrame=cf2 w1.Parent=TriangleModel w2.Parent=TriangleModel
- for Index, Value in pairs(PartStat or{})do w1[Index]=Value end for Index, Value in pairs(PartStat or{})do w2[Index]=Value end
- w1.Name="Wedge1"w2.Name="Wedge2"
- if FadeOpt then local FadingRange=FadeOpt.Range or 10 local FadeSpeed=FadeOpt.Speed or 1
- local scr=(s1.x+s2.x)*s1.x/2 local fadval=scr-FadingRange if fadval<0 then fadval=0 end fadval=fadval*FadeSpeed
- if w1.Transparency+fadval>=1 then w1.Transparency=1 w2.Transparency=1 else
- w1.Transparency=w1.Transparency+fadval w2.Transparency=w1.Transparency end
- end
- TriangleModel.Parent=parent or workspace
- return TriangleModel
- end
- function ReDrawTri(TriangleModel,a,b,c,PartStat,Collide,FadeOpt)
- a=typeof(a)=="CFrame"and a.p or a b=typeof(b)=="CFrame"and b.p or b c=typeof(c)=="CFrame"and c.p or c
- local siz=0 local edges={{longest=(c-b),other=(a-b),position=b},{longest=(a-c),other=(b-c),position=c},{longest=(b-a),other=(c-a),position=a}}
- table.sort(edges,function(a,b) return a.longest.magnitude > b.longest.magnitude end)local edge=edges[1]
- local theta=math.acos(edge.longest.unit:Dot(edge.other.unit))local s1=Vector2.new(edge.other.magnitude * math.cos(theta),edge.other.magnitude * math.sin(theta))
- local s2=Vector2.new(edge.longest.magnitude-s1.x,s1.y)local p1=edge.position + edge.other * 0.5 local p2=edge.position + edge.longest + (edge.other-edge.longest) * 0.5
- local right=edge.longest:Cross(edge.other).unit local up=right:Cross(edge.longest).unit local back=edge.longest.unit
- local cf1=CFrame.new(p1.x,p1.y,p1.z,-right.x,up.x,back.x,-right.y,up.y,back.y,-right.z,up.z,back.z)local cf2=CFrame.new(p2.x,p2.y,p2.z,right.x,up.x,-back.x,right.y,up.y,-back.y,right.z,up.z,-back.z)
- local w1=TriangleModel.Wedge1 local w2=TriangleModel.Wedge2 if not Collide then w1.Mesh.Scale=Vector3.new(siz,s1.y,s1.x)*20 w2.Mesh.Scale=Vector3.new(siz,s2.y,s2.x)*20 else w1.Size=Vector3.new(siz,s1.y,s1.x)w2.Size=Vector3.new(siz,s2.y,s2.x)end
- w1.CFrame=cf1 w2.CFrame=cf2 w1.Parent=TriangleModel w2.Parent=TriangleModel
- for Index, Value in pairs(PartStat or{})do w1[Index]=Value end for Index, Value in pairs(PartStat or{})do w2[Index]=Value end
- if FadeOpt then local FadingRange=FadeOpt.Range or 10 local FadeSpeed=FadeOpt.Speed or 1
- local scr=(s1.x+s2.x)*s1.x/2 local fadval=scr-FadingRange if fadval<0 then fadval=0 end fadval=fadval*FadeSpeed
- if w1.Transparency+fadval>=1 then w1.Transparency=1 w2.Transparency=1 else
- w1.Transparency=w1.Transparency+fadval w2.Transparency=w1.Transparency end
- end
- end
- function DrawSqu(A,B,C,D,parent,PartStat,Collide,FadeOpt)
- local SquareModel=Instance.new("Model",parent or workspace)
- local mA=DrawTriangle(A,B,C,SquareModel,PartStat,Collide,FadeOpt)local mB=DrawTriangle(C,D,A,SquareModel,PartStat,Collide,FadeOpt)mA.Name="A"mB.Name="B"return SquareModel end
- function ReDrawSqu(m,A,B,C,D,PartStat,Collide,FadeOpt)ReDrawTri(m.A,A,B,C,PartStat,Collide,FadeOpt)ReDrawTri(m.B,C,D,A,PartStat,Collide,FadeOpt)end
- end
- if"Audio things"then
- end
- if"Misc"then
- RandomAngleCF=function()return CFrame.Angles(math.rad(math.random(360)),math.rad(math.random(360)))end
- end
- shared.AdvFunc={SimplexNoise=SimplexNoise,DrawTri=DrawTriangle,ReDrawTri=ReDrawTri,
- DrawSqu=DrawSqu,ReDrawSqu=ReDrawSqu,swait=swait,hwait=hwait,RandomAngleCF=RandomAngleCF,
- DataStorage={}}
- --[[
- Packed Functions
- Noise
- >SimplexNoise(x , y , seed) ,
- Triangle Function
- >DrawTri( p1 , p2 , p3 , Parent , {Part State} , isNOTmesh , Fade Option) -draw freedom triangle , except actually broke or not even.
- >ReDrawTri(TriangleModel ,p1 ,p2 ,p3 , isNOTmesh , {Part State} , Fade Option) -anti lag, this uses model that gets returned from DrawTri.
- >DrawSqu -just extended.
- >ReDrawSqu -too.
- Variable
- >DataStorage (it is able to use as a temporary data storage if you want to use. or else create your own , this is easier way.)
- --]]
- print("Including function finished.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement