Rename example -> examples
39
_docs/gen.go
@ -29,6 +29,25 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func execute(command string, args ...string) error {
|
||||
cmd := exec.Command(command, args...)
|
||||
stderr, err := cmd.StderrPipe()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := cmd.Start(); err != nil {
|
||||
return err
|
||||
}
|
||||
msg, err := ioutil.ReadAll(stderr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := cmd.Wait(); err != nil {
|
||||
return fmt.Errorf("%v: %s", err, string(msg))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var license = ""
|
||||
|
||||
func init() {
|
||||
@ -130,10 +149,10 @@ func (e *example) Height() int {
|
||||
|
||||
func (e *example) Source() string {
|
||||
if e.Name == "blocks" {
|
||||
return "// Please read example/blocks/main.go and example/blocks/blocks/*.go"
|
||||
return "// Please read examples/blocks/main.go and examples/blocks/blocks/*.go"
|
||||
}
|
||||
|
||||
path := filepath.Join(os.Getenv("GOPATH"), "src", "github.com", "hajimehoshi", "ebiten", "example", e.Name, "main.go")
|
||||
path := filepath.Join(os.Getenv("GOPATH"), "src", "github.com", "hajimehoshi", "ebiten", "examples", e.Name, "main.go")
|
||||
b, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@ -175,7 +194,7 @@ func clear() error {
|
||||
return os.Remove(path)
|
||||
}
|
||||
// Remove example resources that are copied.
|
||||
m, err = regexp.MatchString("^public/example/images$", path)
|
||||
m, err = regexp.MatchString("^public/examples/images$", path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -223,11 +242,15 @@ func outputMain() error {
|
||||
func outputExampleImages() error {
|
||||
// TODO: Using cp command might not be portable.
|
||||
// Use io.Copy instead.
|
||||
return exec.Command("cp", "-R", "../example/images", "public/example/images").Run()
|
||||
const dir = "public/examples"
|
||||
if err := os.MkdirAll(dir, 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
return execute("cp", "-R", "../examples/images", "public/examples/images")
|
||||
}
|
||||
|
||||
func outputExampleContent(e *example) error {
|
||||
const dir = "public/example"
|
||||
const dir = "public/examples"
|
||||
if err := os.MkdirAll(dir, 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -259,8 +282,8 @@ func outputExampleContent(e *example) error {
|
||||
}
|
||||
|
||||
out := filepath.Join(dir, e.Name+".js")
|
||||
path := "github.com/hajimehoshi/ebiten/example/" + e.Name
|
||||
if err := exec.Command("gopherjs", "build", "-m", "-o", out, path).Run(); err != nil {
|
||||
path := "github.com/hajimehoshi/ebiten/examples/" + e.Name
|
||||
if err := execute("gopherjs", "build", "-m", "-o", out, path); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -268,7 +291,7 @@ func outputExampleContent(e *example) error {
|
||||
}
|
||||
|
||||
func outputExample(e *example) error {
|
||||
const dir = "public/example"
|
||||
const dir = "public/examples"
|
||||
if err := os.MkdirAll(dir, 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -15,4 +15,4 @@
|
||||
package docs
|
||||
|
||||
//go:generate go run gen.go
|
||||
//go:generate cp -r ../example/images ./public/example/
|
||||
//go:generate cp -r ../examples/images ./public/examples/
|
||||
|
@ -48,7 +48,7 @@ pre {
|
||||
<h2>Example</h2>
|
||||
<p>
|
||||
{{range .Examples}}
|
||||
<a href="example/{{.Name}}.html"><img src="images/example/{{.Name}}.png" width="{{.ThumbWidth}}" height="{{.ThumbHeight}}" alt="Ebiten example: {{.Name}}" class="example"></a>
|
||||
<a href="examples/{{.Name}}.html"><img src="images/examples/{{.Name}}.png" width="{{.ThumbWidth}}" height="{{.ThumbHeight}}" alt="Ebiten example: {{.Name}}" class="example"></a>
|
||||
{{end}}
|
||||
</p>
|
||||
|
||||
|
@ -36,7 +36,7 @@ pre {
|
||||
|
||||
<h1>Ebiten example - blocks</h1>
|
||||
<iframe src="blocks.content.html" width="512" height="480"></iframe>
|
||||
<pre><code>// Please read example/blocks/main.go and example/blocks/blocks/*.go</code></pre>
|
||||
<pre><code>// Please read examples/blocks/main.go and examples/blocks/blocks/*.go</code></pre>
|
||||
|
||||
|
||||
<footer>© 2014 Hajime Hoshi</footer>
|
66
_docs/public/examples/blocks.js
Normal file
1
_docs/public/examples/blocks.js.map
Normal file
60
_docs/public/examples/hue.js
Normal file
1
_docs/public/examples/hue.js.map
Normal file
Before Width: | Height: | Size: 1008 B After Width: | Height: | Size: 1008 B |
Before Width: | Height: | Size: 138 B After Width: | Height: | Size: 138 B |
Before Width: | Height: | Size: 165 B After Width: | Height: | Size: 165 B |
Before Width: | Height: | Size: 3.3 KiB After Width: | Height: | Size: 3.3 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
@ -41,7 +41,7 @@ pre {
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/ebitenutil"
|
||||
"github.com/hajimehoshi/ebiten/example/keyboard/keyboard"
|
||||
"github.com/hajimehoshi/ebiten/examples/keyboard/keyboard"
|
||||
"log"
|
||||
"strconv"
|
||||
)
|
60
_docs/public/examples/keyboard.js
Normal file
1
_docs/public/examples/keyboard.js.map
Normal file
60
_docs/public/examples/mosaic.js
Normal file
1
_docs/public/examples/mosaic.js.map
Normal file
59
_docs/public/examples/paint.js
Normal file
1
_docs/public/examples/paint.js.map
Normal file
60
_docs/public/examples/perspective.js
Normal file
1
_docs/public/examples/perspective.js.map
Normal file
@ -39,6 +39,7 @@ pre {
|
||||
<pre><code>package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"image/color"
|
||||
"log"
|
||||
@ -46,21 +47,22 @@ import (
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/ebitenutil"
|
||||
"github.com/hajimehoshi/ebiten/example/common"
|
||||
"github.com/hajimehoshi/ebiten/examples/common"
|
||||
"github.com/hajimehoshi/ebiten/exp/audio"
|
||||
)
|
||||
|
||||
const (
|
||||
screenWidth = 320
|
||||
screenHeight = 240
|
||||
sampleRate = 44100
|
||||
)
|
||||
|
||||
var pcm = make([]float64, 4*audio.SampleRate())
|
||||
var pcm = make([]float64, 4*sampleRate)
|
||||
|
||||
const baseFreq = 220
|
||||
|
||||
func init() {
|
||||
s := float64(audio.SampleRate())
|
||||
s := float64(sampleRate)
|
||||
amp := []float64{1.0, 0.8, 0.6, 0.4, 0.2}
|
||||
x := []float64{4.0, 2.0, 1.0, 0.5, 0.25}
|
||||
for i := 0; i < len(pcm); i++ {
|
||||
@ -92,10 +94,19 @@ func toBytes(l, r []int16) []byte {
|
||||
return b
|
||||
}
|
||||
|
||||
type stream struct {
|
||||
*bytes.Reader
|
||||
}
|
||||
|
||||
func (s *stream) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func addNote(freq float64, vol float64) {
|
||||
f := int(freq)
|
||||
if n, ok := noteCache[f]; ok {
|
||||
audio.Play(-1, n)
|
||||
p := audio.NewPlayer(&stream{bytes.NewReader(n)}, sampleRate)
|
||||
p.Play()
|
||||
return
|
||||
}
|
||||
length := len(pcm) * baseFreq / f
|
||||
@ -112,7 +123,8 @@ func addNote(freq float64, vol float64) {
|
||||
}
|
||||
n := toBytes(l, r)
|
||||
noteCache[f] = n
|
||||
audio.Play(-1, n)
|
||||
p := audio.NewPlayer(&stream{bytes.NewReader(n)}, sampleRate)
|
||||
p.Play()
|
||||
}
|
||||
|
||||
var keys = []ebiten.Key{
|
61
_docs/public/examples/piano.js
Normal file
1
_docs/public/examples/piano.js.map
Normal file
60
_docs/public/examples/rotate.js
Normal file
1
_docs/public/examples/rotate.js.map
Normal file
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.0 KiB |
Before Width: | Height: | Size: 76 KiB After Width: | Height: | Size: 76 KiB |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 87 KiB After Width: | Height: | Size: 87 KiB |
Before Width: | Height: | Size: 87 KiB After Width: | Height: | Size: 87 KiB |
@ -62,21 +62,21 @@ pre {
|
||||
<h2>Example</h2>
|
||||
<p>
|
||||
|
||||
<a href="example/hue.html"><img src="images/example/hue.png" width="320" height="240" alt="Ebiten example: hue" class="example"></a>
|
||||
<a href="examples/hue.html"><img src="images/examples/hue.png" width="320" height="240" alt="Ebiten example: hue" class="example"></a>
|
||||
|
||||
<a href="example/keyboard.html"><img src="images/example/keyboard.png" width="320" height="240" alt="Ebiten example: keyboard" class="example"></a>
|
||||
<a href="examples/keyboard.html"><img src="images/examples/keyboard.png" width="320" height="240" alt="Ebiten example: keyboard" class="example"></a>
|
||||
|
||||
<a href="example/mosaic.html"><img src="images/example/mosaic.png" width="320" height="240" alt="Ebiten example: mosaic" class="example"></a>
|
||||
<a href="examples/mosaic.html"><img src="images/examples/mosaic.png" width="320" height="240" alt="Ebiten example: mosaic" class="example"></a>
|
||||
|
||||
<a href="example/paint.html"><img src="images/example/paint.png" width="320" height="240" alt="Ebiten example: paint" class="example"></a>
|
||||
<a href="examples/paint.html"><img src="images/examples/paint.png" width="320" height="240" alt="Ebiten example: paint" class="example"></a>
|
||||
|
||||
<a href="example/perspective.html"><img src="images/example/perspective.png" width="320" height="240" alt="Ebiten example: perspective" class="example"></a>
|
||||
<a href="examples/perspective.html"><img src="images/examples/perspective.png" width="320" height="240" alt="Ebiten example: perspective" class="example"></a>
|
||||
|
||||
<a href="example/piano.html"><img src="images/example/piano.png" width="320" height="240" alt="Ebiten example: piano" class="example"></a>
|
||||
<a href="examples/piano.html"><img src="images/examples/piano.png" width="320" height="240" alt="Ebiten example: piano" class="example"></a>
|
||||
|
||||
<a href="example/rotate.html"><img src="images/example/rotate.png" width="320" height="240" alt="Ebiten example: rotate" class="example"></a>
|
||||
<a href="examples/rotate.html"><img src="images/examples/rotate.png" width="320" height="240" alt="Ebiten example: rotate" class="example"></a>
|
||||
|
||||
<a href="example/blocks.html"><img src="images/example/blocks.png" width="256" height="240" alt="Ebiten example: blocks" class="example"></a>
|
||||
<a href="examples/blocks.html"><img src="images/examples/blocks.png" width="256" height="240" alt="Ebiten example: blocks" class="example"></a>
|
||||
|
||||
</p>
|
||||
|
||||
|
@ -62,7 +62,7 @@ func createJSIfNeeded(name string) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
if (err != nil && os.IsNotExist(err)) || time.Now().Sub(stat.ModTime()) > 5*time.Second {
|
||||
target := "github.com/hajimehoshi/ebiten/example/" + name
|
||||
target := "github.com/hajimehoshi/ebiten/examples/" + name
|
||||
out, err := exec.Command("gopherjs", "build", "-o", out, target).CombinedOutput()
|
||||
if err != nil {
|
||||
log.Print(string(out))
|
@ -16,7 +16,7 @@ package blocks
|
||||
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/example/common"
|
||||
"github.com/hajimehoshi/ebiten/examples/common"
|
||||
"image/color"
|
||||
)
|
||||
|
@ -17,7 +17,7 @@ package blocks
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/example/common"
|
||||
"github.com/hajimehoshi/ebiten/examples/common"
|
||||
"image/color"
|
||||
"strings"
|
||||
)
|
@ -17,7 +17,7 @@ package blocks
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/ebitenutil"
|
||||
"github.com/hajimehoshi/ebiten/example/common"
|
||||
"github.com/hajimehoshi/ebiten/examples/common"
|
||||
"image/color"
|
||||
_ "image/jpeg"
|
||||
"math/rand"
|
@ -17,7 +17,7 @@ package blocks
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/ebitenutil"
|
||||
"github.com/hajimehoshi/ebiten/example/common"
|
||||
"github.com/hajimehoshi/ebiten/examples/common"
|
||||
"image/color"
|
||||
)
|
||||
|
@ -17,7 +17,7 @@ package main
|
||||
import (
|
||||
"flag"
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/example/blocks/blocks"
|
||||
"github.com/hajimehoshi/ebiten/examples/blocks/blocks"
|
||||
"log"
|
||||
"os"
|
||||
"runtime/pprof"
|
Before Width: | Height: | Size: 1008 B After Width: | Height: | Size: 1008 B |
Before Width: | Height: | Size: 138 B After Width: | Height: | Size: 138 B |
Before Width: | Height: | Size: 165 B After Width: | Height: | Size: 165 B |
Before Width: | Height: | Size: 3.3 KiB After Width: | Height: | Size: 3.3 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
@ -18,7 +18,7 @@ package main
|
||||
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/example/common"
|
||||
"github.com/hajimehoshi/ebiten/examples/common"
|
||||
"image"
|
||||
"image/color"
|
||||
"image/draw"
|
@ -17,7 +17,7 @@ package main
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/ebitenutil"
|
||||
"github.com/hajimehoshi/ebiten/example/keyboard/keyboard"
|
||||
"github.com/hajimehoshi/ebiten/examples/keyboard/keyboard"
|
||||
"log"
|
||||
"strconv"
|
||||
)
|
@ -23,7 +23,7 @@ import (
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/ebitenutil"
|
||||
"github.com/hajimehoshi/ebiten/example/common"
|
||||
"github.com/hajimehoshi/ebiten/examples/common"
|
||||
"github.com/hajimehoshi/ebiten/exp/audio"
|
||||
)
|
||||
|