|
Post by Tag365 on Sept 28, 2014 20:45:04 GMT
How do I make it draw a rotated line?
-- For Custom Objects function ObjRes.Custom(CorTab, X, Y, Size, RotRad, Mat, k) if not Size then Size = 32 end local Line, filltriangle = draw.line, draw.filltriangle local Col if type(Mat) == "table" then Col = Mat else Col = ObjMaterials[Mat] or draw.brown end --setmetatable(Col, Col255MT) -- use local Col2 = ObjMaterialsBorders[Mat] or draw.black --print("Size: "..tostring(Size), "k: "..tostring(k)) for k, v in ipairs(CorTab) do local FCor = CorTab[k-1] or CorTab[#CorTab] local SCor = CorTab[k] local TCor = CorTab[k+1] or CorTab[1] filltriangle((FCor[1]*Size)+X, (FCor[2]*Size)+Y, (SCor[1]*Size)+X, (SCor[2]*Size)+Y, (TCor[1]*Size)+X, (TCor[2]*Size)+Y, Col) Line((FCor[1]*Size)+X, (FCor[2]*Size)+Y, (SCor[1]*Size)+X, (SCor[2]*Size)+Y, angle, Col2) -- this is the line i need to be drawn rotated end end
|
|
Dark Vortex
New Member
Just typing those words in
Posts: 8
|
Post by Dark Vortex on Sept 29, 2014 22:24:04 GMT
This rotates squares so I'm guess you can take code from this and rotate a line
draw.setscreen(1) draw.settitle("Rotating square")
function DS(x,y,a,b,d,C,g,m) --rotate 90*d clockwise D = a-x D = math.floor(D*d) -- if in group move together if g == 1 then y = y + (D*m) b = b + (D*m) elseif g == 2 then x = x - (D*m) a = a - (D*m) elseif g == 3 then x = x + (D*m) a = a + D*m elseif g == 4 then y = y - (D*m) b = b - (D*m) elseif g == 5 then x = x - D a = a - D y = y + D b = b + D elseif g == 6 then x = x - D a = a - D y = y - D b = b - D elseif g == 7 then x = x + D a = a + D y = y + D b = b + D elseif g == 8 then x = x + D a = a + D y = y - D b = b - D end --draw draw.line(a-D,y,x,y+D,C) draw.line(x,y+D,x+D,b,C) draw.line(x+D,b,a,b-D,C) draw.line(a,b-D,a-D,y,C) end
function rotate( x,y,e,f,r,C,g,m) ga,gb,gc,gd,ge,gf,gg,gh,gi = 0 for i = 0, 400 do r = r + .01 if r > .99 then r = 0 end if g == 1 then ga,gb,gc,gd = 1,2,3,4 elseif g == 2 then ga,gb,gc = 1,7,2 gd,ge,gf = 5,0,8 gg,gh,gi = 3,6,4 end draw.beginframe() if m == 1 then l = 0 DS(x,y,e,f,r,C,g,l) elseif m == 2 then l = 1 g = e-x g = g/2 h = f-y h = h/2 a = x + g b = y + h DS(x,y,a,b,r,C,ga,l) DS(x,b,a,f,r,C,gc,l) DS(a,y,e,b,r,C,gb,l) DS(a,b,e,f,r,C,gd,l) elseif m == 3 then l = 2 g = e-x g = g/3 h = f-y h = h/3 a = x + g b = y + h c = x + g + g d = y + h + h DS(x,y,a,b,r,C,ga,l) DS(x,b,a,d,r,C,gb,l) DS(x,d,a,f,r,C,gg,l) DS(a,y,c,b,r,C,gd,l) DS(a,b,c,d,r,C,ge,l) DS(a,d,c,f,r,C,gf,l) DS(c,y,e,b,r,C,gc,l) DS(c,b,e,d,r,C,gh,l) DS(c,d,e,f,r,C,gi,l) end draw.endframe() sleep(10) draw.clear() end end
-- examples
function set() draw.stringsize(40) --draw.setfont() a,b,c,d = 75,150,225,300 r = 0 m = 175 C = draw.red B = draw.black S = draw.lightgray end set() q = .36 draw.beginframe() DS(b,b,c,c,q,C,1,1) DS(b,b,c,c,q,C,2,1) DS(b,b,c,c,q,C,3,1) DS(b,b,c,c,q,C,4,1) DS(b,b,c,c,q,C,5,1) DS(b,b,c,c,q,C,6,1) DS(b,b,c,c,q,C,7,1) DS(b,b,c,c,q,C,8,1) draw.endframe() sleep(50000)
Or you could take a line and insert the line's x, y and length Into a function then it would move the line based on a circle around half the length to rotate the circle
|
|
Atom
Junior Member
Posts: 81
|
Post by Atom on Sept 30, 2014 11:49:16 GMT
I didn't use your code but I created a function that draws a rotated line based on center coordinates, radius, angle and color.
-- Center coordinates, radius, angle (radians), color function rotatedLine(cx, cy, radius, angle, color) local x = cx + math.cos(angle)*radius local y = cy + math.sin(angle)*radius draw.line(cx, cy, x, y, color) end
-- EXAMPLE draw.setscreen(1) draw.setlinestyle(4, 'round') a, sw, sh = 0, draw.getport() -- Get screen size while true do sleep(20) draw.clear() rotatedLine(sw/2, sh/2, 120, a, draw.black) a = a + 0.01 -- Increase line angle end
|
|