How to make circles: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>Mindraker
m Reverted edits by Riking27 (Talk) to last version by Mindraker
>Camoy
okay redir
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
__TOC__
#REDIRECT [[Circle]]
 
== Introduction ==
 
This tutorial will show you how to make semicircles and circles.  It would be helpful if you knew some basic trigonometry, but it is not necessary.
 
== What are we trying to do? ==
 
This is not a [[Part]] with the shape of a [[Shape|Ball]].  This is instead a rather hollow outline pixelated with many small bricks.  In fact, you won't be touching bricks at all -- you will only be scripting.
 
== Steps ==
 
* Create a new, blank, map in [[Roblox Studio]].
* Insert > Object > Script
* Insert the following into that script (the explanation is below):
 
<pre>
local i = 0
for i = 1, 360, 1 do
 
local p = Instance.new("Part")
p.Parent = game.Workspace
p.Name = "Brick"
p.Size = Vector3.new(1,1,1)
p.Anchored = true
p.Position=Vector3.new(100*math.cos(math.rad(i)), 100*math.sin(math.rad(i))+120,0)
wait()
end
 
</pre>
 
== Explanation ==
 
A circle has 360 degrees.  You are going to create 360 little bricks for your circle.  The "for" loop runs 360 times. The "math.rad(i)" converts the angle i, which is in degrees, into [[radians]]<br>
Each time the "for" loop runs, it:<br>
* Creates a new 'part', of which the parent is "game.Workspace".
* The part's name is "Brick"
* The Brick's size is (1,1,1) -- remember, we wanted little bricks.
* All the bricks are anchored, so that they don't fall down.<br>
 
Now comes the tricky part: we want to position the bricks as a circle.  If you've taken trigonometry, the next line should make sense.  If not, all this is saying that the X value should be 100 times a mathematical function named "cosine" of the value of "i", and the Y value should be 100 times a mathematical function named "sine" of the value of "i".  Sine and cosine are functions to study angles and circles.  The value of "Y" is bumped up 120 squares, otherwise it is mashed against the ground, which makes your circle look like a semicircle.
 
Run this, and you should get a nice little circle.
 
== Advanced ==
 
The above example is a rather large circle.  Let's say you want a smaller one.  You'll have to do two things:<br>
* Reduce the factor that you are multiplying the cos and sin by.
* Reduce the number of iterations (which reduces the number of bricks).  If you don't do this, you will have double-layered bricks, which isn't as pretty.  Example:
 
<pre>
local i = 0
for i = 1, 360, 3 do
 
local p = Instance.new("Part")
p.Parent = game.Workspace
p.Name = "Brick"
p.Size = Vector3.new(1,1,1)
p.Anchored = true
p.Position=Vector3.new(50*math.cos(math.rad(i)), 50*math.sin(math.rad(i))+75,0)
wait()
end
</pre>
 
Or maybe you want to rotate the bricks so that the faces face inwards for a smoother circle. This circle will be horizontal. To make it horizontal, you need to keep the y value constant and change the z value instead.
 
<pre>
local i = 0
for i = 1, 360, 3 do
 
local p = Instance.new("Part")
p.Parent = game.Workspace
p.Name = "Brick"
p.Size = Vector3.new(1,1,1)
p.CFrame = CFrame.fromEulerAnglesXYZ(0,-math.rad(i),0) --rotates the brick
p.Anchored = true
p.Position=Vector3.new(50*math.cos(math.rad(i)),10,50*math.sin(math.rad(i)))
wait()
end
</pre>
 
== Ellipse ==
 
Ellipses are quite similar geometrically to circles.  You just need to make one dimension (x or y) longer than the other:
 
<pre>
local i = 0
for i = 1, 360, 2 do
 
local p = Instance.new("Part")
p.Parent = game.Workspace
p.Name = "Brick"
p.Size = Vector3.new(1,1,1)
p.Anchored = true
p.Position=Vector3.new(100*math.cos(math.rad(i)), 50*math.sin(math.rad(i))+120)
wait()
end
</pre>
 
Notice here that the x dimension is <b>100</b>*math.cos(i), and the y dimension is now only <b>50</b>*math.sin(i).  You can swap these numbers to change whether the ellipse is longer horizontally or vertically.  These numbers can also be changed to alter the length and width of your ellipse.
 
[[Category:Scripting Tutorials]]

Latest revision as of 21:34, 23 January 2011

Redirect to: