Author Topic: Questions about [drawing]  (Read 15275 times)

Breakord

  • Sapling
  • **
  • Thank You
  • -Given: 14
  • -Receive: 7
  • Posts: 57
  • Eufloria: Yes
Questions about [drawing]
« on: February 10, 2013, 01:48:20 PM »
:)
Still, many questions!
I'd like to say thank you first~
Q1:Can I set the cascading order of the graphes drawed by DrawSprite(), DrawLine(), DrawTexLine() and DrawBox()?
How?
I've noticed that lines drawed by DrawLine()  is always on the top of other graphes, is there a way to explicitly set the cascading index?
Q2:How to draw a polygon or polyline?Or how to call function "DrawPolygon()/DrawPolyline()"?
Q3:Can I draw a sector or arch?How?
Q4:Besides DrawTexLine(),is there a way to draw an ellipse?How?
Q5:Can I use the "TextureLoader" to draw text?Though Aino's function DrawText() is very useful, it will be great to use the build-in functions~

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 24
  • Posts: 932
  • Eufloria: Yes
Re: Questions about [drawing]
« Reply #1 on: February 10, 2013, 06:00:49 PM »
1) It depends on the order you draw them. They will always be on top of the asteroids.

2) I made a polygon drawing function, it's around somewhere (I'll look for it)

3) Not easily

4) I don't think so

5) Don't know

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 24
  • Posts: 932
  • Eufloria: Yes
Re: Questions about [drawing]
« Reply #2 on: February 10, 2013, 06:31:54 PM »

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Questions about [drawing]
« Reply #3 on: February 10, 2013, 08:23:40 PM »
3:
Using math.sin and math.cos you can find the angles on screen, now you just got to do a for loop and draw hundreds of lines.

Code: [Select]
function DrawArc(x,y, width, height, startAngle, arcAngle, r1, g1, b1,a1, r2,g2,b2,a2, lineWidth)
local numLines = 32
for i = 0,numLines-1 do
DrawLine(x+math.cos(startAngle/180*math.pi+arcAngle/180*math.pi*i/numLines)*width, y+math.sin(startAngle/180*math.pi+arcAngle/180*math.pi*i/numLines)*height,
x+math.cos(startAngle/180*math.pi+arcAngle/180*math.pi*(i+1)/numLines)*width, y+math.sin(startAngle/180*math.pi+arcAngle/180*math.pi*(i+1)/numLines)*height,
r1,b1,g1,a1, r1+(r2-r1)*i/numLines, b1+(b2-b1)*i/numLines, g1+(g2-g1)*i/numLines, a1+(a2-a1)*i/numLines, lineWidth);
end
end
function DrawArc(x,y, radius, startAngle, arcAngle, r1, g1, b1,a1, r2,g2,b2,a2, lineWidth)
local numLines = 32
for i = 0,numLines-1 do
DrawLine(x+math.cos(startAngle/180*math.pi+arcAngle/180*math.pi*i/numLines)*radius, y+math.sin(startAngle/180*math.pi+arcAngle/180*math.pi*i/numLines)*radius,
x+math.cos(startAngle/180*math.pi+arcAngle/180*math.pi*(i+1)/numLines)*radius, y+math.sin(startAngle/180*math.pi+arcAngle/180*math.pi*(i+1)/numLines)*radius,
r1,b1,g1,a1, r1+(r2-r1)*i/numLines, b1+(b2-b1)*i/numLines, g1+(g2-g1)*i/numLines, a1+(a2-a1)*i/numLines, lineWidth);
end
end
function DrawArc(x,y, radius, startAngle, arcAngle, r, g, b,a, lineWidth)
local numLines = 32
for i = 0,numLines-1 do
DrawLine(x+math.cos(startAngle/180*math.pi+arcAngle/180*math.pi*i/numLines)*radius, y+math.sin(startAngle/180*math.pi+arcAngle/180*math.pi*i/numLines)*radius,
x+math.cos(startAngle/180*math.pi+arcAngle/180*math.pi*(i+1)/numLines)*radius, y+math.sin(startAngle/180*math.pi+arcAngle/180*math.pi*(i+1)/numLines)*radius,
r,b,g,a, r,b,g,a, lineWidth);
end
end
function DrawArc(x,y, radius, startAngle, arcAngle, r, g, b,a, lineWidth, numLines)
if (numLines > 0) then
for i = 0,numLines-1 do
DrawLine(x+math.cos(startAngle/180*math.pi+arcAngle/180*math.pi*i/numLines)*radius, y+math.sin(startAngle/180*math.pi+arcAngle/180*math.pi*i/numLines)*radius,
x+math.cos(startAngle/180*math.pi+arcAngle/180*math.pi*(i+1)/numLines)*radius, y+math.sin(startAngle/180*math.pi+arcAngle/180*math.pi*(i+1)/numLines)*radius,
r,b,g,a, r,b,g,a, lineWidth);
end
end
end
function DrawArc(x,y, width, height, startAngle, arcAngle, r1, g1, b1,a1, r2,g2,b2,a2, lineWidth, numLines)
if (numLines > 0) then
for i = 0,numLines-1 do
DrawLine(x+math.cos(startAngle/180*math.pi+arcAngle/180*math.pi*i/numLines)*width, y+math.sin(startAngle/180*math.pi+arcAngle/180*math.pi*i/numLines)*height,
x+math.cos(startAngle/180*math.pi+arcAngle/180*math.pi*(i+1)/numLines)*width, y+math.sin(startAngle/180*math.pi+arcAngle/180*math.pi*(i+1)/numLines)*height,
r1,b1,g1,a1, r1+(r2-r1)*i/numLines, b1+(b2-b1)*i/numLines, g1+(g2-g1)*i/numLines, a1+(a2-a1)*i/numLines, lineWidth);
end
end
end

It's a little math heavy, but this functions means you won't need to write it. You can(and should IMO) check out the maths, and please don't ask for a fill function.
I don't know if you can take all of them and copy them into your code though, so pick a favorite and print it in (I recommend the last one!) :)
And one more note: THEY US DEGREES, NOT RADIANS.

5:
Using the inbuilt DrawText function from the game: DrawText(text,x,y,alpha,size) the size is a tricky one, it's not normal font size, I think it's sizemultiplication of the image size, which means it would be easy to find where the next line should be :)
« Last Edit: February 10, 2013, 08:34:28 PM by Aino »

Breakord

  • Sapling
  • **
  • Thank You
  • -Given: 14
  • -Receive: 7
  • Posts: 57
  • Eufloria: Yes
Re: Questions about [drawing]
« Reply #4 on: February 18, 2013, 10:40:28 AM »
1) It depends on the order you draw them. They will always be on top of the asteroids.

2) I made a polygon drawing function, it's around somewhere (I'll look for it)

3) Not easily

4) I don't think so

5) Don't know
Sorry to reply so late,New Year's day is a bit busy ~
1)Not so simple, for example,  box drawn by DrawBox(5,...)is always on the top of sprite drawn by DrawSprite(1,...)
2)Nice dude!
Thank you !

Breakord

  • Sapling
  • **
  • Thank You
  • -Given: 14
  • -Receive: 7
  • Posts: 57
  • Eufloria: Yes
Re: Questions about [drawing]
« Reply #5 on: February 18, 2013, 11:00:07 AM »
3:
Using math.sin and math.cos you can find the angles on screen, now you just got to do a for loop and draw hundreds of lines.

Code: [Select]
function DrawArc(x,y, width, height, startAngle, arcAngle, r1, g1, b1,a1, r2,g2,b2,a2, lineWidth)
local numLines = 32
for i = 0,numLines-1 do
DrawLine(x+math.cos(startAngle/180*math.pi+arcAngle/180*math.pi*i/numLines)*width, y+math.sin(startAngle/180*math.pi+arcAngle/180*math.pi*i/numLines)*height,
x+math.cos(startAngle/180*math.pi+arcAngle/180*math.pi*(i+1)/numLines)*width, y+math.sin(startAngle/180*math.pi+arcAngle/180*math.pi*(i+1)/numLines)*height,
r1,b1,g1,a1, r1+(r2-r1)*i/numLines, b1+(b2-b1)*i/numLines, g1+(g2-g1)*i/numLines, a1+(a2-a1)*i/numLines, lineWidth);
end
end
function DrawArc(x,y, radius, startAngle, arcAngle, r1, g1, b1,a1, r2,g2,b2,a2, lineWidth)
local numLines = 32
for i = 0,numLines-1 do
DrawLine(x+math.cos(startAngle/180*math.pi+arcAngle/180*math.pi*i/numLines)*radius, y+math.sin(startAngle/180*math.pi+arcAngle/180*math.pi*i/numLines)*radius,
x+math.cos(startAngle/180*math.pi+arcAngle/180*math.pi*(i+1)/numLines)*radius, y+math.sin(startAngle/180*math.pi+arcAngle/180*math.pi*(i+1)/numLines)*radius,
r1,b1,g1,a1, r1+(r2-r1)*i/numLines, b1+(b2-b1)*i/numLines, g1+(g2-g1)*i/numLines, a1+(a2-a1)*i/numLines, lineWidth);
end
end
function DrawArc(x,y, radius, startAngle, arcAngle, r, g, b,a, lineWidth)
local numLines = 32
for i = 0,numLines-1 do
DrawLine(x+math.cos(startAngle/180*math.pi+arcAngle/180*math.pi*i/numLines)*radius, y+math.sin(startAngle/180*math.pi+arcAngle/180*math.pi*i/numLines)*radius,
x+math.cos(startAngle/180*math.pi+arcAngle/180*math.pi*(i+1)/numLines)*radius, y+math.sin(startAngle/180*math.pi+arcAngle/180*math.pi*(i+1)/numLines)*radius,
r,b,g,a, r,b,g,a, lineWidth);
end
end
function DrawArc(x,y, radius, startAngle, arcAngle, r, g, b,a, lineWidth, numLines)
if (numLines > 0) then
for i = 0,numLines-1 do
DrawLine(x+math.cos(startAngle/180*math.pi+arcAngle/180*math.pi*i/numLines)*radius, y+math.sin(startAngle/180*math.pi+arcAngle/180*math.pi*i/numLines)*radius,
x+math.cos(startAngle/180*math.pi+arcAngle/180*math.pi*(i+1)/numLines)*radius, y+math.sin(startAngle/180*math.pi+arcAngle/180*math.pi*(i+1)/numLines)*radius,
r,b,g,a, r,b,g,a, lineWidth);
end
end
end
function DrawArc(x,y, width, height, startAngle, arcAngle, r1, g1, b1,a1, r2,g2,b2,a2, lineWidth, numLines)
if (numLines > 0) then
for i = 0,numLines-1 do
DrawLine(x+math.cos(startAngle/180*math.pi+arcAngle/180*math.pi*i/numLines)*width, y+math.sin(startAngle/180*math.pi+arcAngle/180*math.pi*i/numLines)*height,
x+math.cos(startAngle/180*math.pi+arcAngle/180*math.pi*(i+1)/numLines)*width, y+math.sin(startAngle/180*math.pi+arcAngle/180*math.pi*(i+1)/numLines)*height,
r1,b1,g1,a1, r1+(r2-r1)*i/numLines, b1+(b2-b1)*i/numLines, g1+(g2-g1)*i/numLines, a1+(a2-a1)*i/numLines, lineWidth);
end
end
end

It's a little math heavy, but this functions means you won't need to write it. You can(and should IMO) check out the maths, and please don't ask for a fill function.
I don't know if you can take all of them and copy them into your code though, so pick a favorite and print it in (I recommend the last one!) :)
And one more note: THEY US DEGREES, NOT RADIANS.

5:
Using the inbuilt DrawText function from the game: DrawText(text,x,y,alpha,size) the size is a tricky one, it's not normal font size, I think it's sizemultiplication of the image size, which means it would be easy to find where the next line should be :)

3.Awesome!Though, it is a pity that there are no build-in functions...
5.I think now I understand what makes you want to write a new DrawText()...=_=
Thank you!
Sorry to reply so late, New Year's day is a bit busy...

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Questions about [drawing]
« Reply #6 on: February 18, 2013, 11:33:23 AM »
3.Awesome!Though, it is a pity that there are no build-in functions...
5.I think now I understand what makes you want to write a new DrawText()...=_=
Thank you!
Sorry to reply so late, New Year's day is a bit busy...

The real reason why I wrote the DrawText function was basically because nobody really knew that there were any built-in DrawText function back then, unless people have been lying to me all along... :o

However, now it's optional to use my function or the built-in one. The built-in one provides better performance, but mine provides more customization. I'm actually using the built-in one most because I like it best...