Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. Domains: forum.doom9.org / forum.doom9.net / forum.doom9.se |
|
|
#1 | Link |
|
Registered User
Join Date: Mar 2005
Posts: 366
|
Drawing lines with Gscript
Here's a function for drawing lines with Gscript:
Code:
Loadplugin("GScript.dll")
blankclip(1,500,500,"RGB32", color=$FF0000FF)
# Example a line:
#DrawLine(canvas, 1,1,500,500, $FFFFFFFF)
#Example a red box:
#DrawLine(last, 100,100,400,100,5, $FFFF0000)
#DrawLine(last, 100,100,100,400,5, $FFFF0000)
#DrawLine(last, 100,400,400,400,5, $FFFF0000)
#DrawLine(last, 400,100,400,400,5, $FFFF0000)
# Example a lot of lines:
GScript("""
for (i=0, 500,10){
DrawLine(last, 0,i,500,500-i,1, $FFFFFFFF)
DrawLine(last, i,0,500-i,500,1, $FFFFFFFF)
}
""")
function DrawLine(clip canvas, val x0, val y0,val x1,val y1, val dsize, val dcolor)
{
dtotal=canvas.framecount()
OptCanvas=blankclip(1,canvas.width(),canvas.height(),"RGB32", color=$00000000)
pen=blankclip(1,dsize,dsize,"RGB32", color=dcolor)
dx = float(x1 - x0)
dy = float(y1 - y0)
sx = dx > 0 ? 1 : -1
sy = dy > 0 ? 1 : -1
dx = float(dx*sx)
dy = float(dy*sy)
dxdy= float(dx/dy)
dydx = float(dy/dx)
dxdy = dxdy *sx
dydx = dydx *sy
py = float(y0)
px = float(x0)
GScript("""
if( dx > dy )
{
for(x=0, int(dx))
{
OptCanvas=Layer(OptCanvas,pen,"add",257,int(px),int(py))
px=px+sx
py=py+dydx
}
}
else
{
for(y=0, int(dy))
{
OptCanvas=Layer(OptCanvas,pen,"add",257,int(px),int(py))
py=py+sy
px=px+dxdy
}
}
""")
return Layer(Canvas,OptCanvas.loop(dtotal),"add",257,0,0)
}
__________________
DVD slideshow GUI(Freeware). Last edited by tin3tin; 28th November 2010 at 22:10. |
|
|
|
|
|
#2 | Link |
|
Registered User
Join Date: Mar 2005
Posts: 366
|
Tried to make a DrawCircle too, from this example: http://www.cs.unc.edu/~mcmillan/comp...e7/circle.html
However there is an error... ![]() [Edit: Thanks Gavino! here's the working script:] Code:
Loadplugin("GScript.dll")
blankclip(1,500,500,"RGB32", color=$FF0000FF)
DrawCircle(last, 250,250,100, 2, $FFFFFFFF)
function DrawCircle(clip canvas, val CenterX, val CenterY,val radius, val pensize, val pencolor)
{
dtotal=canvas.framecount()
OptCanvas=blankclip(1,canvas.width(),canvas.height(),"RGB32", color=$00000000)
pen=blankclip(1,pensize,pensize,"RGB32", color=pencolor)
GScript("""
x = 0
y = radius
p = (5 - radius*4)/4
while (x < y)
{
x=x+1
if (p < 0) {
p = p+2*x+1
} else {
y=y-1
p =p+ 2*(x-y+1)
}
OptCanvas=circlePoints(CenterX, CenterY, x, y, OptCanvas, pen)
OptCanvas=Layer(OptCanvas,pen,"add",257,CenterX+int(x),CenterY+int(y))
}
""")
return Layer(Canvas,OptCanvas.loop(dtotal),"add",257,0,0)
}
function circlePoints(int cx, int cy, int x, int y, clip optCanvas, clip pen)
{
GScript("""
if (x == 0) {
OptCanvas=Layer(OptCanvas,pen,"add",257, cx, cy + y)
OptCanvas=Layer(OptCanvas,pen,"add",257, cx, cy - y)
OptCanvas=Layer(OptCanvas,pen,"add",257, cx + y, cy)
OptCanvas=Layer(OptCanvas,pen,"add",257, cx - y, cy)
} else if (x == y) {
OptCanvas=Layer(OptCanvas,pen,"add",257,cx + x, cy + y)
OptCanvas=Layer(OptCanvas,pen,"add",257, cx - x, cy + y)
OptCanvas=Layer(OptCanvas,pen,"add",257, cx + x, cy - y)
OptCanvas=Layer(OptCanvas,pen,"add",257, cx - x, cy - y)
} else if (x < y) {
OptCanvas=Layer(OptCanvas,pen,"add",257, cx + x, cy + y)
OptCanvas=Layer(OptCanvas,pen,"add",257, cx - x, cy + y)
OptCanvas=Layer(OptCanvas,pen,"add",257, cx + x, cy - y)
OptCanvas=Layer(OptCanvas,pen,"add",257, cx - x, cy - y)
OptCanvas=Layer(OptCanvas,pen,"add",257, cx + y, cy + x)
OptCanvas=Layer(OptCanvas,pen,"add",257, cx - y, cy + x)
OptCanvas=Layer(OptCanvas,pen,"add",257, cx + y, cy - x)
OptCanvas=Layer(OptCanvas,pen,"add",257, cx - y, cy - x)
}
""")
return OptCanvas
}
__________________
DVD slideshow GUI(Freeware). Last edited by tin3tin; 28th November 2010 at 22:08. Reason: Corrected the code |
|
|
|
|
|
#4 | Link |
|
Registered User
Join Date: Mar 2005
Posts: 366
|
Thanks Gavino!
![]() I was so close... and so blind...
__________________
DVD slideshow GUI(Freeware). |
|
|
|
|
|
#5 | Link |
|
Warm and fuzzy
Join Date: Apr 2010
Location: Moscow, Russia
Posts: 206
|
tin3tin
. Exuse me, mate. . How to draw ARC ? How to draw ELLIPSE ? . Gavino . Can you help, mate ? .
__________________
Warm and fuzzy (white and fluffy) Last edited by Jenyok; 17th March 2013 at 06:03. |
|
|
|
|
|
#6 | Link |
|
Registered User
Join Date: Mar 2005
Posts: 366
|
What I did was to google up some code handling the math and then changed it to Avisynth script.
__________________
DVD slideshow GUI(Freeware). |
|
|
|
|
|
#7 | Link |
|
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,406
|
Maybe of interest:
http://en.wikipedia.org/wiki/Midpoint_circle_algorithm http://en.wikipedia.org/wiki/Ellipse http://en.wikipedia.org/wiki/Bresenh...line_algorithm http://en.wikipedia.org/wiki/Digital...s_algorithm%29
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? |
|
|
|
|
|
#8 | Link |
|
Warm and fuzzy
Join Date: Apr 2010
Location: Moscow, Russia
Posts: 206
|
StainlessS
Thanks, mate. . . I do not understand, why line of code does not works, see code below ? . Code:
LoadPlugin("C:\PROGRAM FILES\AVISYNTH 2.5\PLUGINS\GSCRIPT_11\gscript.dll")
function DrawCircle(clip canvas, val CenterX, val CenterY, val radius, val pensize, val pencolor)
{
dtotal = canvas.framecount()
OptCanvas = blankclip(1, canvas.width(), canvas.height(), "RGB32", color=$00000000)
pen = blankclip(1, pensize, pensize, "RGB32", color=pencolor)
GScript("""
x = 0
y = radius
p = (5 - radius * 4) / 4
dt = 0
while (x < y) {
x = x + 1
if (p < 0) {
p = p + 2 * x + 1
}
else {
y = y - 1
p = p + 2 * (x - y + 1)
}
OptCanvas = circlePoints(CenterX, CenterY, x, y, OptCanvas, pen)
OptCanvas = Layer(OptCanvas, pen, "add", 257, CenterX+int(x), CenterY+int(y))
OptCanvas = SubTitle(OptCanvas, "p = "+string(p), x=5, y=5+dt, size=10, align=1, text_color=$FFFFFF, halo_color=$000000, font="Arial Cyr") # Why does this line not works ?
dt=dt+10
}
""")
return (Layer(canvas, OptCanvas.loop(dtotal), "add", 257, 0, 0))
}
function circlePoints(int cx, int cy, int x, int y, clip optCanvas, clip pen)
{
GScript("""
if (x == 0) {
OptCanvas = Layer(OptCanvas, pen, "add", 257, cx, cy + y)
OptCanvas = Layer(OptCanvas, pen, "add", 257, cx, cy - y)
OptCanvas = Layer(OptCanvas, pen, "add", 257, cx + y, cy)
OptCanvas = Layer(OptCanvas, pen, "add", 257, cx - y, cy)
}
else if (x == y) {
OptCanvas = Layer(OptCanvas, pen, "add", 257, cx + x, cy + y)
OptCanvas = Layer(OptCanvas, pen, "add", 257, cx - x, cy + y)
OptCanvas = Layer(OptCanvas, pen, "add", 257, cx + x, cy - y)
OptCanvas = Layer(OptCanvas, pen, "add", 257, cx - x, cy - y)
}
else if (x < y) {
OptCanvas = Layer(OptCanvas, pen, "add", 257, cx + x, cy + y)
OptCanvas = Layer(OptCanvas, pen, "add", 257, cx - x, cy + y)
OptCanvas = Layer(OptCanvas, pen, "add", 257, cx + x, cy - y)
OptCanvas = Layer(OptCanvas, pen, "add", 257, cx - x, cy - y)
OptCanvas = Layer(OptCanvas, pen, "add", 257, cx + y, cy + x)
OptCanvas = Layer(OptCanvas, pen, "add", 257, cx - y, cy + x)
OptCanvas = Layer(OptCanvas, pen, "add", 257, cx + y, cy - x)
OptCanvas = Layer(OptCanvas, pen, "add", 257, cx - y, cy - x)
}
""")
return (OptCanvas)
}
BlankClip(length=50, width=768, height=576, fps=25.0, channels=2, color=$000000)
x2 = Width() / 2
y2 = Height() / 2
DrawCircle(last, x2+200, y2, 100, 2, $FFFFFFFF)
ConvertToYUY2()
__________________
Warm and fuzzy (white and fluffy) Last edited by Jenyok; 17th March 2013 at 15:09. |
|
|
|
|
|
#9 | Link | |
|
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,442
|
Quote:
You need to add this line after the Subtitle call: Code:
OptCanvas = OptCanvas.Mask(OptCanvas.ShowAlpha().SubTitle("p = "+string(p), x=5, y=5+dt, size=10, align=1, text_color=$FFFFFF, halo_color=$FFFFFF, font="Arial Cyr"))
|
|
|
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|