Rename example -> examples

This commit is contained in:
Hajime Hoshi 2016-02-11 03:07:14 +09:00
parent 10650d1c6e
commit 0f6c18fb1b
86 changed files with 563 additions and 34 deletions

View File

@ -29,6 +29,25 @@ import (
"strings" "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 = "" var license = ""
func init() { func init() {
@ -130,10 +149,10 @@ func (e *example) Height() int {
func (e *example) Source() string { func (e *example) Source() string {
if e.Name == "blocks" { 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) b, err := ioutil.ReadFile(path)
if err != nil { if err != nil {
panic(err) panic(err)
@ -175,7 +194,7 @@ func clear() error {
return os.Remove(path) return os.Remove(path)
} }
// Remove example resources that are copied. // 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 { if err != nil {
return err return err
} }
@ -223,11 +242,15 @@ func outputMain() error {
func outputExampleImages() error { func outputExampleImages() error {
// TODO: Using cp command might not be portable. // TODO: Using cp command might not be portable.
// Use io.Copy instead. // 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 { func outputExampleContent(e *example) error {
const dir = "public/example" const dir = "public/examples"
if err := os.MkdirAll(dir, 0755); err != nil { if err := os.MkdirAll(dir, 0755); err != nil {
return err return err
} }
@ -259,8 +282,8 @@ func outputExampleContent(e *example) error {
} }
out := filepath.Join(dir, e.Name+".js") out := filepath.Join(dir, e.Name+".js")
path := "github.com/hajimehoshi/ebiten/example/" + e.Name path := "github.com/hajimehoshi/ebiten/examples/" + e.Name
if err := exec.Command("gopherjs", "build", "-m", "-o", out, path).Run(); err != nil { if err := execute("gopherjs", "build", "-m", "-o", out, path); err != nil {
return err return err
} }
@ -268,7 +291,7 @@ func outputExampleContent(e *example) error {
} }
func outputExample(e *example) error { func outputExample(e *example) error {
const dir = "public/example" const dir = "public/examples"
if err := os.MkdirAll(dir, 0755); err != nil { if err := os.MkdirAll(dir, 0755); err != nil {
return err return err
} }

View File

@ -15,4 +15,4 @@
package docs package docs
//go:generate go run gen.go //go:generate go run gen.go
//go:generate cp -r ../example/images ./public/example/ //go:generate cp -r ../examples/images ./public/examples/

View File

@ -48,7 +48,7 @@ pre {
<h2>Example</h2> <h2>Example</h2>
<p> <p>
{{range .Examples}} {{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}} {{end}}
</p> </p>

View File

@ -36,7 +36,7 @@ pre {
<h1>Ebiten example - blocks</h1> <h1>Ebiten example - blocks</h1>
<iframe src="blocks.content.html" width="512" height="480"></iframe> <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> <footer>© 2014 Hajime Hoshi</footer>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

Before

Width:  |  Height:  |  Size: 1008 B

After

Width:  |  Height:  |  Size: 1008 B

View File

Before

Width:  |  Height:  |  Size: 138 B

After

Width:  |  Height:  |  Size: 138 B

View File

Before

Width:  |  Height:  |  Size: 165 B

After

Width:  |  Height:  |  Size: 165 B

View File

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -41,7 +41,7 @@ pre {
import ( import (
&#34;github.com/hajimehoshi/ebiten&#34; &#34;github.com/hajimehoshi/ebiten&#34;
&#34;github.com/hajimehoshi/ebiten/ebitenutil&#34; &#34;github.com/hajimehoshi/ebiten/ebitenutil&#34;
&#34;github.com/hajimehoshi/ebiten/example/keyboard/keyboard&#34; &#34;github.com/hajimehoshi/ebiten/examples/keyboard/keyboard&#34;
&#34;log&#34; &#34;log&#34;
&#34;strconv&#34; &#34;strconv&#34;
) )

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -39,6 +39,7 @@ pre {
<pre><code>package main <pre><code>package main
import ( import (
&#34;bytes&#34;
&#34;fmt&#34; &#34;fmt&#34;
&#34;image/color&#34; &#34;image/color&#34;
&#34;log&#34; &#34;log&#34;
@ -46,21 +47,22 @@ import (
&#34;github.com/hajimehoshi/ebiten&#34; &#34;github.com/hajimehoshi/ebiten&#34;
&#34;github.com/hajimehoshi/ebiten/ebitenutil&#34; &#34;github.com/hajimehoshi/ebiten/ebitenutil&#34;
&#34;github.com/hajimehoshi/ebiten/example/common&#34; &#34;github.com/hajimehoshi/ebiten/examples/common&#34;
&#34;github.com/hajimehoshi/ebiten/exp/audio&#34; &#34;github.com/hajimehoshi/ebiten/exp/audio&#34;
) )
const ( const (
screenWidth = 320 screenWidth = 320
screenHeight = 240 screenHeight = 240
sampleRate = 44100
) )
var pcm = make([]float64, 4*audio.SampleRate()) var pcm = make([]float64, 4*sampleRate)
const baseFreq = 220 const baseFreq = 220
func init() { func init() {
s := float64(audio.SampleRate()) s := float64(sampleRate)
amp := []float64{1.0, 0.8, 0.6, 0.4, 0.2} amp := []float64{1.0, 0.8, 0.6, 0.4, 0.2}
x := []float64{4.0, 2.0, 1.0, 0.5, 0.25} x := []float64{4.0, 2.0, 1.0, 0.5, 0.25}
for i := 0; i &lt; len(pcm); i&#43;&#43; { for i := 0; i &lt; len(pcm); i&#43;&#43; {
@ -92,10 +94,19 @@ func toBytes(l, r []int16) []byte {
return b return b
} }
type stream struct {
*bytes.Reader
}
func (s *stream) Close() error {
return nil
}
func addNote(freq float64, vol float64) { func addNote(freq float64, vol float64) {
f := int(freq) f := int(freq)
if n, ok := noteCache[f]; ok { if n, ok := noteCache[f]; ok {
audio.Play(-1, n) p := audio.NewPlayer(&amp;stream{bytes.NewReader(n)}, sampleRate)
p.Play()
return return
} }
length := len(pcm) * baseFreq / f length := len(pcm) * baseFreq / f
@ -112,7 +123,8 @@ func addNote(freq float64, vol float64) {
} }
n := toBytes(l, r) n := toBytes(l, r)
noteCache[f] = n noteCache[f] = n
audio.Play(-1, n) p := audio.NewPlayer(&amp;stream{bytes.NewReader(n)}, sampleRate)
p.Play()
} }
var keys = []ebiten.Key{ var keys = []ebiten.Key{

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

Before

Width:  |  Height:  |  Size: 76 KiB

After

Width:  |  Height:  |  Size: 76 KiB

View File

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

View File

Before

Width:  |  Height:  |  Size: 87 KiB

After

Width:  |  Height:  |  Size: 87 KiB

View File

Before

Width:  |  Height:  |  Size: 87 KiB

After

Width:  |  Height:  |  Size: 87 KiB

View File

@ -62,21 +62,21 @@ pre {
<h2>Example</h2> <h2>Example</h2>
<p> <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> </p>

View File

@ -62,7 +62,7 @@ func createJSIfNeeded(name string) (string, error) {
return "", err return "", err
} }
if (err != nil && os.IsNotExist(err)) || time.Now().Sub(stat.ModTime()) > 5*time.Second { 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() out, err := exec.Command("gopherjs", "build", "-o", out, target).CombinedOutput()
if err != nil { if err != nil {
log.Print(string(out)) log.Print(string(out))

View File

@ -16,7 +16,7 @@ package blocks
import ( import (
"github.com/hajimehoshi/ebiten" "github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/example/common" "github.com/hajimehoshi/ebiten/examples/common"
"image/color" "image/color"
) )

View File

@ -17,7 +17,7 @@ package blocks
import ( import (
"fmt" "fmt"
"github.com/hajimehoshi/ebiten" "github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/example/common" "github.com/hajimehoshi/ebiten/examples/common"
"image/color" "image/color"
"strings" "strings"
) )

View File

@ -17,7 +17,7 @@ package blocks
import ( import (
"github.com/hajimehoshi/ebiten" "github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/ebitenutil" "github.com/hajimehoshi/ebiten/ebitenutil"
"github.com/hajimehoshi/ebiten/example/common" "github.com/hajimehoshi/ebiten/examples/common"
"image/color" "image/color"
_ "image/jpeg" _ "image/jpeg"
"math/rand" "math/rand"

View File

@ -17,7 +17,7 @@ package blocks
import ( import (
"github.com/hajimehoshi/ebiten" "github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/ebitenutil" "github.com/hajimehoshi/ebiten/ebitenutil"
"github.com/hajimehoshi/ebiten/example/common" "github.com/hajimehoshi/ebiten/examples/common"
"image/color" "image/color"
) )

View File

@ -17,7 +17,7 @@ package main
import ( import (
"flag" "flag"
"github.com/hajimehoshi/ebiten" "github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/example/blocks/blocks" "github.com/hajimehoshi/ebiten/examples/blocks/blocks"
"log" "log"
"os" "os"
"runtime/pprof" "runtime/pprof"

View File

Before

Width:  |  Height:  |  Size: 1008 B

After

Width:  |  Height:  |  Size: 1008 B

View File

Before

Width:  |  Height:  |  Size: 138 B

After

Width:  |  Height:  |  Size: 138 B

View File

Before

Width:  |  Height:  |  Size: 165 B

After

Width:  |  Height:  |  Size: 165 B

View File

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -18,7 +18,7 @@ package main
import ( import (
"github.com/hajimehoshi/ebiten" "github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/example/common" "github.com/hajimehoshi/ebiten/examples/common"
"image" "image"
"image/color" "image/color"
"image/draw" "image/draw"

View File

@ -17,7 +17,7 @@ package main
import ( import (
"github.com/hajimehoshi/ebiten" "github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/ebitenutil" "github.com/hajimehoshi/ebiten/ebitenutil"
"github.com/hajimehoshi/ebiten/example/keyboard/keyboard" "github.com/hajimehoshi/ebiten/examples/keyboard/keyboard"
"log" "log"
"strconv" "strconv"
) )

View File

@ -23,7 +23,7 @@ import (
"github.com/hajimehoshi/ebiten" "github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/ebitenutil" "github.com/hajimehoshi/ebiten/ebitenutil"
"github.com/hajimehoshi/ebiten/example/common" "github.com/hajimehoshi/ebiten/examples/common"
"github.com/hajimehoshi/ebiten/exp/audio" "github.com/hajimehoshi/ebiten/exp/audio"
) )