Exemple #1
0
func main() {
	flag.Parse()
	ZellijTilings, reset = zellij.TileSkeleton(skeleton, tileSymmetry, false)
	Frame := zellij.SkeletonFrame(skeleton)
	symmetryCounts := make(map[string]int)
	for T := range ZellijTilings {
		symmetryGroup := zellij.DetectSymmetryGroup(T)
		filename := fmt.Sprintf("%v-%v-%d", skeleton, symmetryGroup, symmetryCounts[symmetryGroup]+1)
		symmetryCounts[symmetryGroup]++
		save, err := os.Create(path.Join(dir, filename+".zellij"))
		if err != nil {
			panic("file error")
		}
		enc := json.NewEncoder(save)
		enc.Encode([]*quadratic.Map{Frame, T})
		save.Close()
		image := cairo.NewSurface(path.Join(dir, "svg", filename+".svg"), 72*5, 72*5)
		image.SetSourceRGB(0., 0., 0.)
		image.SetLineWidth(.1)
		image.Translate(72*2.5, 72*2.5)
		image.Scale(4., 4.)
		T.ColourFaces(image, zellij.PlainBrush)
		image.Finish()
	}
}
Exemple #2
0
func RenderTiles(w http.ResponseWriter, req *http.Request) {
	e := os.Remove("svg/test-surface.svg")
	if e != nil {
		os.Stderr.WriteString(e.String() + "\n")
	}

	if CurrentTiling == nil {
		EmptySvg(w, req)
		return
	}

	style := req.FormValue("style")

	image := cairo.NewSurface("svg/test-surface.svg", 72*4, 72*4)
	image.SetSourceRGB(0., 0., 0.)
	image.SetLineWidth(.1)
	image.Translate(72*2., 72*2.)
	image.Scale(4., 4.)
	if style == "edges" {
		image.SetSourceRGBA(0., 0., 0., 1.)
		CurrentTiling.DrawEdges(image)
	} else if style == "plain" {
		CurrentTiling.ColourFaces(image, zellij.OrangeBlueBrush)
	} else {
		CurrentTiling.ColourDebugFaces(image)
		CurrentTiling.DrawDebugEdges(image)
	}

	image.Finish()
	http.ServeFile(w, req, "svg/test-surface.svg")
}
Exemple #3
0
func main() {
	surface := cairo.NewSurface(cairo.FormatArgB32, 240, 80)
	surface.SelectFontFace("serif", cairo.FontSlantNormal, cairo.FontWeightBold)
	surface.SetFontSize(32.0)
	surface.SetSourceRGB(0.0, 0.0, 1.0)
	surface.MoveTo(10.0, 50.0)
	surface.ShowText("Hello World")
	surface.Finish()
	surface.WriteToPNG("hello.png")
}
Exemple #4
0
func EmbellishFrame(w http.ResponseWriter, req *http.Request) {
	e := os.Remove("svg/embellishment.svg")
	if e != nil {
		os.Stderr.WriteString(e.String() + "\n")
	}
	frame := quadratic.NewMap()
	jsonErr := json.NewDecoder(strings.NewReader(req.FormValue("frame"))).Decode(frame)
	if jsonErr != nil {
		os.Stderr.WriteString("json error: " + jsonErr.String() + "\n")
		return
	}
	zig, err := zellij.Embellish(frame, MotifDatabase)
	if err != nil {
		os.Stderr.WriteString(err.String() + "\n")
		return
	}
	fmt.Fprintf(os.Stderr, "embellishment has %v faces\n", zig.Faces.Len())
	bx := zig.Verticies.At(0).(*quadratic.Vertex).Point
	tx := zig.Verticies.At(0).(*quadratic.Vertex).Point
	by := zig.Verticies.At(0).(*quadratic.Vertex).Point
	ty := zig.Verticies.At(0).(*quadratic.Vertex).Point
	for i := 1; i < zig.Verticies.Len(); i++ {
		v := zig.Verticies.At(i).(*quadratic.Vertex).Point
		if v.Y().Float64() < by.Y().Float64() {
			by = v
		} else if v.Y().Float64() > ty.Y().Float64() {
			ty = v
		}
		if v.X().Float64() < bx.X().Float64() {
			bx = v
		} else if v.X().Float64() > tx.X().Float64() {
			tx = v
		}
	}
	xwidth := math.Floor(tx.X().Float64() - bx.X().Float64() + 20.0)
	ywidth := math.Floor(ty.Y().Float64() - by.Y().Float64() + 20.0)

	image := cairo.NewSurface("svg/embellishment.svg", xwidth*4, ywidth*4)
	image.SetSourceRGB(0., 0., 0.)
	image.SetLineWidth(.1)
	image.Translate(-bx.X().Float64()*4.+40, -by.Y().Float64()*4.+40)
	image.Scale(4., 4.)
	zig.ColourFaces(image, zellij.OrangeBlueBrush)
	image.Finish()
	http.ServeFile(w, req, "svg/embellishment.svg")
}
Exemple #5
0
func DrawSkel(w http.ResponseWriter, req *http.Request) {
	e := os.Remove("svg/test-surface.svg")
	if e != nil {
		os.Stderr.WriteString(e.String() + "\n")
	}
	skeleton := req.FormValue("skeleton")
	image := cairo.NewSurface("svg/test-surface.svg", 72*4, 72*4)
	image.SetSourceRGB(0., 0., 0.)
	image.SetLineWidth(.1)
	image.Translate(72*2., 72*2.)
	image.Scale(4., 4.)
	skel, ok := zellij.SkeletonMap(skeleton)
	if ok != nil {
		os.Stderr.WriteString(ok.String() + "\n")
	}
	skel.DrawEdges(image)
	image.Finish()
	http.ServeFile(w, req, "svg/test-surface.svg")
}