Begin to work on matrix transformation (does not yet really work)
This commit is contained in:
parent
10fb830ac9
commit
2d02464b73
3 changed files with 157 additions and 18 deletions
17
draw2d/src/cmd/ps_tests/TestStar.ps
Normal file
17
draw2d/src/cmd/ps_tests/TestStar.ps
Normal file
|
@ -0,0 +1,17 @@
|
|||
%!
|
||||
% Example of rotation... draws 36 lines in a circular pattern
|
||||
|
||||
0 10 360 { % Go from 0 to 360 degrees in 10 degree steps
|
||||
newpath % Start a new path
|
||||
|
||||
gsave % Keep rotations temporary
|
||||
144 144 moveto
|
||||
rotate % Rotate by degrees on stack from 'for'
|
||||
72 0 rlineto
|
||||
stroke
|
||||
grestore % Get back the unrotated state
|
||||
|
||||
} for % Iterate over angles
|
||||
|
||||
showpage
|
||||
|
50
draw2d/src/cmd/ps_tests/TestTransform.ps
Normal file
50
draw2d/src/cmd/ps_tests/TestTransform.ps
Normal file
|
@ -0,0 +1,50 @@
|
|||
%!
|
||||
% Example to demonstrate translate, rotate, and scale
|
||||
|
||||
% operator box: xcoord ycoord box -
|
||||
% Creates one inch box at xcoord, ycoord
|
||||
/box {
|
||||
newpath
|
||||
moveto
|
||||
72 0 rlineto
|
||||
0 72 rlineto
|
||||
-72 0 rlineto
|
||||
closepath
|
||||
} def
|
||||
|
||||
% Specify font for text labels
|
||||
/Helvetica findfont 40 scalefont setfont
|
||||
|
||||
gsave
|
||||
40 40 translate % Set origin to (40, 40)
|
||||
0 0 box stroke % Draw box at new origin...
|
||||
77 0 moveto
|
||||
(Translated) show % and label
|
||||
grestore
|
||||
|
||||
gsave
|
||||
100 150 translate % Translate origin to (100, 150)
|
||||
30 rotate % Rotate counter-clockwise by 30 degrees
|
||||
0 0 box stroke % Draw box...
|
||||
75 0 moveto
|
||||
(Translated & Rotated) show % and label
|
||||
grestore
|
||||
|
||||
gsave
|
||||
40 300 translate % Translate to (40, 300)
|
||||
0.5 1 scale % Reduce x coord by 1/2, y coord left alone
|
||||
0 0 box stroke % Draw box...
|
||||
75 0 moveto
|
||||
(Translated & Squished) show % and label
|
||||
grestore
|
||||
|
||||
gsave
|
||||
300 300 translate % Set origin to (300, 300)
|
||||
45 rotate % Rotate coordinates by 45 degrees
|
||||
0.5 1 scale % Scale coordinates
|
||||
0 0 box stroke % Draw box
|
||||
75 0 moveto
|
||||
(Everything) show
|
||||
grestore
|
||||
|
||||
showpage
|
|
@ -68,11 +68,12 @@ func saveToPngFile(TestName string, m image.Image) {
|
|||
*/
|
||||
func TestPath() {
|
||||
i, gc := initGc(w, h)
|
||||
gc.MoveTo(10.0, 10.0)
|
||||
gc.LineTo(100.0, 10.0)
|
||||
gc.Translate(10,10)
|
||||
gc.MoveTo(0.0, 0.0)
|
||||
gc.LineTo(100.0, 00.0)
|
||||
gc.LineTo(100.0, 100.0)
|
||||
gc.LineTo(10.0, 100.0)
|
||||
gc.LineTo(10.0, 10.0)
|
||||
gc.LineTo(0.0, 100.0)
|
||||
gc.LineTo(0.0, 0.0)
|
||||
gc.FillStroke()
|
||||
saveToPngFile("TestPath", i)
|
||||
}
|
||||
|
@ -127,13 +128,15 @@ func TestDrawArcNegative() {
|
|||
gc.SetLineWidth(10)
|
||||
gc.SetLineCap(draw2d.ButtCap)
|
||||
gc.SetStrokeColor(image.Black)
|
||||
|
||||
gc.ArcTo(xc, yc, radiusX, radiusY, startAngle, angle)
|
||||
gc.Stroke()
|
||||
// fill a circle
|
||||
gc.SetStrokeColor(image.RGBAColor{255, 0x33, 0x33, 0x80})
|
||||
gc.SetFillColor(image.RGBAColor{255, 0x33, 0x33, 0x80})
|
||||
gc.SetLineWidth(6)
|
||||
|
||||
|
||||
|
||||
gc.MoveTo(xc, yc)
|
||||
gc.LineTo(xc+cos(startAngle)*radiusX, yc+sin(startAngle)*radiusY)
|
||||
gc.MoveTo(xc, yc)
|
||||
|
@ -190,7 +193,7 @@ func TestCurveRectangle() {
|
|||
gc.CubicCurveTo(x0, y1, x0, y1, x0, y1-radius)
|
||||
}
|
||||
}
|
||||
gc.Close()
|
||||
gc.ClosePath()
|
||||
|
||||
gc.SetFillColor(image.RGBAColor{0x80, 0x80, 0xFF, 0xFF})
|
||||
gc.SetStrokeColor(image.RGBAColor{0x80, 0, 0, 0x80})
|
||||
|
@ -258,13 +261,13 @@ func TestFillStroke() {
|
|||
gc.LineTo(230.4, 230.4)
|
||||
gc.RLineTo(-102.4, 0.0)
|
||||
gc.CubicCurveTo(51.2, 230.4, 51.2, 128.0, 128.0, 128.0)
|
||||
gc.Close()
|
||||
gc.ClosePath()
|
||||
|
||||
gc.MoveTo(64.0, 25.6)
|
||||
gc.RLineTo(51.2, 51.2)
|
||||
gc.RLineTo(-51.2, 51.2)
|
||||
gc.RLineTo(-51.2, -51.2)
|
||||
gc.Close()
|
||||
gc.ClosePath()
|
||||
|
||||
gc.SetLineWidth(10.0)
|
||||
gc.SetFillColor(image.RGBAColor{0, 0, 0xFF, 0xFF})
|
||||
|
@ -338,7 +341,7 @@ func TestRoundRectangle() {
|
|||
gc.ArcTo(x+width-radius, y+height-radius, radius, radius, 0*degrees, 90*degrees)
|
||||
gc.ArcTo(x+radius, y+height-radius, radius, radius, 90*degrees, 90*degrees)
|
||||
gc.ArcTo(x+radius, y+radius, radius, radius, 180*degrees, 90*degrees)
|
||||
gc.Close()
|
||||
gc.ClosePath()
|
||||
|
||||
gc.SetFillColor(image.RGBAColor{0x80, 0x80, 0xFF, 0xFF})
|
||||
gc.SetStrokeColor(image.RGBAColor{0x80, 0, 0, 0x80})
|
||||
|
@ -401,18 +404,85 @@ func TestLineJoin() {
|
|||
|
||||
func TestBubble() {
|
||||
i, gc := initGc(w, h)
|
||||
gc.BeginPath();
|
||||
gc.MoveTo(75,25);
|
||||
gc.QuadCurveTo(25,25,25,62.5);
|
||||
gc.QuadCurveTo(25,100,50,100);
|
||||
gc.QuadCurveTo(50,120,30,125);
|
||||
gc.QuadCurveTo(60,120,65,100);
|
||||
gc.QuadCurveTo(125,100,125,62.5);
|
||||
gc.QuadCurveTo(125,25,75,25);
|
||||
gc.Stroke();
|
||||
gc.BeginPath()
|
||||
gc.MoveTo(75,25)
|
||||
gc.QuadCurveTo(25,25,25,62.5)
|
||||
gc.QuadCurveTo(25,100,50,100)
|
||||
gc.QuadCurveTo(50,120,30,125)
|
||||
gc.QuadCurveTo(60,120,65,100)
|
||||
gc.QuadCurveTo(125,100,125,62.5)
|
||||
gc.QuadCurveTo(125,25,75,25)
|
||||
gc.Stroke()
|
||||
saveToPngFile("TestBubble", i)
|
||||
}
|
||||
|
||||
func TestStar() {
|
||||
i, gc := initGc(w, h)
|
||||
for i := 0.0 ; i < 360; i = i + 10 {// Go from 0 to 360 degrees in 10 degree steps
|
||||
gc.BeginPath() // Start a new path
|
||||
gc.Save() // Keep rotations temporary
|
||||
gc.MoveTo(144, 144)
|
||||
gc.Rotate(i * (math.Pi / 180.0)) // Rotate by degrees on stack from 'for'
|
||||
gc.RLineTo(72, 0)
|
||||
gc.Stroke()
|
||||
gc.Restore() // Get back the unrotated state
|
||||
}
|
||||
saveToPngFile("TestStar", i)
|
||||
}
|
||||
|
||||
func TestTransform() {
|
||||
i, gc := initGc(800, 600)
|
||||
|
||||
gc.Save()
|
||||
gc.Translate(40, 40) // Set origin to (40, 40)
|
||||
gc.BeginPath()
|
||||
gc.MoveTo(0,0)
|
||||
gc.RLineTo(72,0)
|
||||
gc.RLineTo(0, 72)
|
||||
gc.RLineTo(-72,0)
|
||||
gc.ClosePath()
|
||||
gc.Stroke()
|
||||
gc.Restore()
|
||||
|
||||
gc.Save()
|
||||
gc.Translate(100, 150) // Translate origin to (100, 150)
|
||||
gc.Rotate(30* (math.Pi / 180.0)) // Rotate counter-clockwise by 30 degrees
|
||||
gc.BeginPath()
|
||||
gc.MoveTo(0,0)
|
||||
gc.RLineTo(72,0)
|
||||
gc.RLineTo(0, 72)
|
||||
gc.RLineTo(-72,0)
|
||||
gc.ClosePath() // Draw box...
|
||||
gc.Stroke()
|
||||
gc.Restore()
|
||||
|
||||
gc.Save()
|
||||
gc.Translate(40, 300) // Translate to (40, 300)
|
||||
gc.Scale(0.5, 1) // Reduce x coord by 1/2, y coord left alone
|
||||
gc.BeginPath()
|
||||
gc.MoveTo(0,0)
|
||||
gc.RLineTo(72,0)
|
||||
gc.RLineTo(0, 72)
|
||||
gc.RLineTo(-72,0)
|
||||
gc.ClosePath() // Draw box...
|
||||
gc.Stroke()
|
||||
gc.Restore()
|
||||
|
||||
gc.Save()
|
||||
gc.Translate(300, 300) // Set origin to (300, 300)
|
||||
gc.Rotate(45* (math.Pi / 180.0)) // Rotate coordinates by 45 degrees
|
||||
gc.Scale(0.5, 1) // Scale coordinates
|
||||
gc.BeginPath()
|
||||
gc.MoveTo(0,0)
|
||||
gc.RLineTo(72,0)
|
||||
gc.RLineTo(0, 72)
|
||||
gc.RLineTo(-72,0)
|
||||
gc.ClosePath() // Draw box
|
||||
gc.Stroke()
|
||||
gc.Restore()
|
||||
|
||||
saveToPngFile("TestTransform", i)
|
||||
}
|
||||
|
||||
func main() {
|
||||
TestPath()
|
||||
|
@ -428,4 +498,6 @@ func main() {
|
|||
TestLineCap()
|
||||
TestLineJoin()
|
||||
TestBubble()
|
||||
TestStar()
|
||||
TestTransform()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue