コード例 #1
0
ファイル: buddha.go プロジェクト: mewmew/playground
func main() {
	buddha.Grid = geometry.Rect(-2.5, -2.5, 2.5, 2.5)
	set := buddha.New(1024, 1024)
	filePath := "buddha.png"
	err := imgutil.WriteFile(filePath, set)
	if err != nil {
		log.Fatalln(err)
	}
	fmt.Println("Created:", filePath)
}
コード例 #2
0
ファイル: simple.go プロジェクト: mewmew/playground
func main() {
	mset.Grid = geometry.Rect(-2.5, -2.5, 2.5, 2.5)
	set := mset.New(1024, 1024)
	set.White = true
	filePath := "simple.png"
	err := imgutil.WriteFile(filePath, set)
	if err != nil {
		log.Fatalln(err)
	}
	fmt.Println("Created:", filePath)
}
コード例 #3
0
ファイル: min_dump.go プロジェクト: mewrnd/blizzconv
// dumpPillars stores each pillar as a new png image, using the frames from a
// CEL image level file.
func dumpPillars(pillars []min.Pillar, levelFrames []image.Image, dumpDir string) (err error) {
	for pillarNum, pillar := range pillars {
		pillarPath := dumpDir + fmt.Sprintf("pillar_%04d.png", pillarNum)
		bar.Inc()
		img := pillar.Image(levelFrames)
		err = imgutil.WriteFile(pillarPath, img)
		if err != nil {
			return err
		}
	}
	return nil
}
コード例 #4
0
ファイル: til_dump.go プロジェクト: mewrnd/blizzconv
// dumpPillars stores each pillar as a new png image, using the frames from a
// CEL image level file.
func dumpSquares(squares []til.Square, pillars []min.Pillar, levelFrames []image.Image, dumpDir string) (err error) {
	for squareNum, square := range squares {
		squarePath := dumpDir + fmt.Sprintf("square_%04d.png", squareNum)
		bar.Inc()
		img := square.Image(pillars, levelFrames)
		err = imgutil.WriteFile(squarePath, img)
		if err != nil {
			return err
		}
	}
	return nil
}
コード例 #5
0
ファイル: plot.go プロジェクト: mewmew/playground
func main() {
	for p0 := 0.0; p0 <= 1.0; p0 += 0.1 {
		for p1 := 0.0; p1 <= 1.0; p1 += 0.1 {
			for p2 := 0.0; p2 <= 1.0; p2 += 0.1 {
				for p3 := 0.0; p3 <= 1.0; p3 += 0.1 {
					p := [4]float64{p0, p1, p2, p3}
					img := bezier.Plot(p)
					path := fmt.Sprintf("plot_%.1f_%.1f_%.1f_%.1f.png", p0, p1, p2, p3)
					err := imgutil.WriteFile(path, img)
					if err != nil {
						log.Fatalln(err)
					}
				}
			}
		}
	}
}
コード例 #6
0
ファイル: pretty.go プロジェクト: mewmew/playground
func main() {
	colors := make([]color.Color, mset.Iterations)
	var c color.RGBA
	// Create a transition from black to blue to white.
	for i := range colors {
		x := uint8(float64(i) * 256 / float64(mset.Iterations/2))
		if i < mset.Iterations/2 {
			// Slow transition from black to blue.
			c = color.RGBA{0, 0, x, 255}
		} else {
			// Slow transition from blue to white.
			c = color.RGBA{x, x, 255, 255}
		}
		colors[i] = c
	}
	mset.Colors = colors
	set := mset.New(1280, 1024)
	filePath := "pretty.png"
	err := imgutil.WriteFile(filePath, set)
	if err != nil {
		log.Fatalln(err)
	}
	fmt.Println("Created:", filePath)
}
コード例 #7
0
ファイル: dun_dump.go プロジェクト: mewrnd/blizzconv
// dungeonDump creates a dump directory and stores the dungeon, which has been
// constructed based on the given DUN files, as a png image once for each image
// config (pal).
func dungeonDump(dungeonName string) (err error) {
	dunNames, err := dunconf.GetDunNames(dungeonName)
	if err != nil {
		return err
	}
	dungeon := dun.New()
	for _, dunName := range dunNames {
		err = dungeon.Parse(dunName)
		if err != nil {
			return fmt.Errorf("failed to parse %q: %s", dungeonName, err)
		}
	}
	colCount, err := dunconf.GetColCount(dungeonName)
	if err != nil {
		return err
	}
	rowCount, err := dunconf.GetRowCount(dungeonName)
	if err != nil {
		return err
	}
	nameWithoutExt, err := dun.GetLevelName(dunNames[0])
	if err != nil {
		return err
	}
	minName := nameWithoutExt + ".min"
	pillars, err := min.Parse(minName)
	if err != nil {
		return err
	}
	imgName := nameWithoutExt + ".cel"
	relPalPaths := imgconf.GetRelPalPaths(imgName)
	for _, relPalPath := range relPalPaths {
		conf, err := cel.GetConf(imgName, relPalPath)
		if err != nil {
			return err
		}
		var palDir string
		if len(relPalPaths) > 1 {
			dbg.Println("using pal:", relPalPath)
			palDir = dungeonName + "/"
		}
		levelFrames, err := cel.DecodeAll(imgName, conf)
		if err != nil {
			return err
		}
		dumpDir := path.Clean(dumpPrefix+"_dungeons_/") + "/" + palDir
		// prevent directory traversal
		if !strings.HasPrefix(dumpDir, dumpPrefix) {
			return fmt.Errorf("path (%s) contains no dump prefix (%s).", dumpDir, dumpPrefix)
		}
		err = os.MkdirAll(dumpDir, 0755)
		if err != nil {
			return err
		}
		dungeonPath := dumpDir + dungeonName + ".png"
		if len(relPalPaths) > 1 {
			palName := path.Base(relPalPath)
			palNameWithoutExt := palName[:len(palName)-len(path.Ext(palName))]
			dungeonPath = dumpDir + dungeonName + "_" + palNameWithoutExt + ".png"
		}
		dbg.Println("Creating image:", path.Base(dungeonPath))
		img := dungeon.Image(colCount, rowCount, pillars, levelFrames)
		err = imgutil.WriteFile(dungeonPath, img)
		if err != nil {
			return err
		}
	}
	return nil
}