Update docs

This commit is contained in:
Hajime Hoshi 2015-01-08 23:45:30 +09:00
parent 5dade52621
commit eb325c9684
40 changed files with 775 additions and 360 deletions

View File

@ -1,3 +1,25 @@
<!DOCTYPE html>
{{comment .License}}
<script src="{{.Example.Name}}.js"></script>
<style>
body {
font-family: sans-serif;
}
iframe {
border-color: #999;
border-style: solid;
border-width: 1px;
overflow: hidden;
}
pre {
background: #eee;
padding: 1em;
}
</style>
<nav><a href="..">Ebiten</a></nav>
{{with .Example}}
<h1>{{.Name}}</h1>
<iframe src="{{.Name}}.content.html" width="{{.Width}}" height="{{.Height}}"></iframe>
<pre><code>{{.Source}}</code></pre>
{{end}}
<footer>{{.Copyright}}</footer>

View File

@ -0,0 +1,3 @@
<!DOCTYPE html>
{{comment .License}}
<script src="{{.Example.Name}}.js"></script>

View File

@ -4,7 +4,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
@ -26,6 +26,7 @@ import (
"path/filepath"
"regexp"
"strings"
"time"
)
var license = ""
@ -40,6 +41,12 @@ func init() {
// TODO: Year check
}
var copyright = ""
func init() {
copyright = fmt.Sprintf("© %d Hajime Hoshi", time.Now().Year())
}
var stableVersion = ""
var devVersion = ""
@ -73,20 +80,28 @@ type example struct {
Name string
}
func (e *example) Width() int {
func (e *example) ThumbWidth() int {
if e.Name == "blocks" {
return 256
}
return 320
}
func (e *example) Height() int {
func (e *example) ThumbHeight() int {
if e.Name == "blocks" {
return 240
}
return 240
}
func (e *example) Width() int {
return e.ThumbWidth() * 2
}
func (e *example) Height() int {
return e.ThumbHeight() * 2
}
func (e *example) Source() string {
if e.Name == "blocks" {
return "// Please read example/blocks/main.go and example/blocks/blocks/*.go"
@ -107,15 +122,39 @@ func versions() string {
}
var examples = []example{
{Name: "blocks"},
{Name: "hue"},
{Name: "keyboard"},
{Name: "mosaic"},
{Name: "perspective"},
{Name: "rotate"},
{Name: "blocks"},
}
func clear() error {
// TODO: favicon?
if err := filepath.Walk("public", func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
// Remove auto-generated html files.
m, err := regexp.MatchString(".html$", path)
if err != nil {
return err
}
if !m {
return nil
}
// Remove example resources that are copied.
m, err = regexp.MatchString("public/example/images", path)
if err != nil {
return err
}
if !m {
return nil
}
return os.Remove(path)
}); err != nil {
return err
}
return nil
}
@ -139,6 +178,7 @@ func outputMain() error {
data := map[string]interface{}{
"License": license,
"Copyright": copyright,
"StableVersion": stableVersion,
"DevVersion": devVersion,
"Examples": examples,
@ -146,6 +186,46 @@ func outputMain() error {
return t.Funcs(funcs).Execute(f, data)
}
func outputExampleContent(e *example) error {
const dir = "public/example"
if err := os.MkdirAll(dir, 0755); err != nil {
return err
}
f, err := os.Create(filepath.Join(dir, e.Name+".content.html"))
if err != nil {
return err
}
defer f.Close()
funcs := template.FuncMap{
"comment": comment,
"safeHTML": safeHTML,
}
const templatePath = "examplecontent.tmpl.html"
name := filepath.Base(templatePath)
t, err := template.New(name).Funcs(funcs).ParseFiles(templatePath)
if err != nil {
return err
}
data := map[string]interface{}{
"License": license,
"Copyright": copyright,
"Example": e,
}
if err := t.Funcs(funcs).Execute(f, data); err != nil {
return err
}
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 {
return err
}
return nil
}
func outputExample(e *example) error {
const dir = "public/example"
if err := os.MkdirAll(dir, 0755); err != nil {
@ -169,20 +249,11 @@ func outputExample(e *example) error {
}
data := map[string]interface{}{
"License": license,
"Example": e,
"License": license,
"Copyright": copyright,
"Example": e,
}
if err := t.Funcs(funcs).Execute(f, data); err != nil {
return err
}
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 {
return err
}
return nil
return t.Funcs(funcs).Execute(f, data)
}
func main() {
@ -193,6 +264,9 @@ func main() {
log.Fatal(err)
}
for _, e := range examples {
if err := outputExampleContent(&e); err != nil {
log.Fatal(err)
}
if err := outputExample(&e); err != nil {
log.Fatal(err)
}

View File

@ -7,27 +7,11 @@
body {
font-family: sans-serif;
}
table.examples {
border-collapse: separate;
border-spacing: 0 1em;
}
table.examples td {
padding: 0;
vertical-align: top;
}
table.examples td.code pre {
height: 240px;
margin: 0;
overflow: auto;
}
table.examples td.screen {
padding-left: 1em;
}
table.examples iframe, table.examples img {
img.example {
background-color: #000;
border-color: #999;
border-style: solid;
border-width: 1px;
overflow: hidden;
}
pre {
background: #eee;
@ -61,20 +45,11 @@ pre {
</ul>
<h2>Example</h2>
<table class="examples">
<p>
{{range .Examples}}
<tr>
<td class="code"><pre><code>// <b>{{.Name}}</b>
{{.Source}}</code></pre></td>
{{if eq .Name "blocks"}}
<td class="screen">Click to play!<br><a href="example/blocks.html"><img src="blocks.png" width="{{.Width}}" height="{{.Height}}"></a></td>
{{else}}
<td class="screen"><iframe src="example/{{.Name}}.html" width="{{.Width}}" height="{{.Height}}"></iframe></td>
{{end}}
</tr>
<a href="example/{{.Name}}.html"><img src="images/example/{{.Name}}.png" width="{{.ThumbWidth}}" height="{{.ThumbHeight}}" alt="Ebiten example: {{.Name}}" class="example"></a>
{{end}}
</table>
</p>
<h2>Install on Mac OS X</h2>
<pre><code>:; brew install glew
@ -88,19 +63,16 @@ pre {
<pre><code>:; cd $GOHOME/src/github.com/hajimehoshi/ebiten/example
:; go run rotate/main.go</code></pre>
<h2>Execute the example on a web browser</h2>
<p>If you can the example screens above, Ebiten is working on your browser! Each example above works as an independent html in an iframe. If you want to execute the examples apart from this site, execute this:</p>
<pre><code>:; go run $GOPATH/src/github.com/hajimehoshi/ebiten/example/server/main.go</code></pre>
<p>Then, open <code>localhost:8000</code> on your browser.</p>
<p><code>localhost:8000/?EXAMPLE_NAME</code> shows other examples (e.g. <code>localhost:8000/?rotate</code>).</p>
<p>Of cource, you can execute gopherjs yourself. Please see <a href="http://gopherjs.org/">GopherJS site</a> for more detail.</p>
<h2>Run your game on a desktop</h2>
<p>Just execute your Go program. That's it!</p>
<h2>Run your game on a web browser</h2>
<p>Compile your game with GopherJS:</p>
<p>Compile your game with <a href="http://gopherjs.org/">GopherJS</a>:</p>
<pre><code>:; gopherjs build -o yourgame.js path/to/yourgame</code></pre>
<p>Then, open the below HTML on your HTTP server:</p>
<pre><code>&lt;!DOCTYPE html&gt;
&lt;script src="yourgame.js"&gt;&lt;/script&gt;</code></pre>
<p>NOTE: <code>file://</code> URL may not work with Ebiten. Execute your game on a HTTP server.</p>
<h2>Change Log</h2>
<h3>2015-??-??</h3>
@ -137,3 +109,5 @@ pre {
<pre>{{.License}}</pre>
<h3>Go Gopher photograph</h3>
<p><a href="http://blog.golang.org/go-programming-language-turns-two">The original photograph of Go gophers by Chris Nokleberg</a> is licensed under the Creative Commons 3.0 Attributions license.</p>
<footer>{{.Copyright}}</footer>

View File

@ -0,0 +1,18 @@
<!DOCTYPE html>
<!--
Copyright 2015 Hajime Hoshi
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<script src="blocks.js"></script>

View File

@ -15,4 +15,26 @@ See the License for the specific language governing permissions and
limitations under the License.
-->
<script src="blocks.js"></script>
<style>
body {
font-family: sans-serif;
}
iframe {
border-color: #999;
border-style: solid;
border-width: 1px;
overflow: hidden;
}
pre {
background: #eee;
padding: 1em;
}
</style>
<nav><a href="..">Ebiten</a></nav>
<h1>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>
<footer>© 2015 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

View File

@ -0,0 +1,18 @@
<!DOCTYPE html>
<!--
Copyright 2015 Hajime Hoshi
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<script src="hue.js"></script>

View File

@ -15,4 +15,68 @@ See the License for the specific language governing permissions and
limitations under the License.
-->
<script src="hue.js"></script>
<style>
body {
font-family: sans-serif;
}
iframe {
border-color: #999;
border-style: solid;
border-width: 1px;
overflow: hidden;
}
pre {
background: #eee;
padding: 1em;
}
</style>
<nav><a href="..">Ebiten</a></nav>
<h1>hue</h1>
<iframe src="hue.content.html" width="640" height="480"></iframe>
<pre><code>package main
import (
&#34;github.com/hajimehoshi/ebiten&#34;
&#34;github.com/hajimehoshi/ebiten/ebitenutil&#34;
_ &#34;image/jpeg&#34;
&#34;log&#34;
&#34;math&#34;
)
const (
screenWidth = 320
screenHeight = 240
)
var (
count int
gophersImage *ebiten.Image
)
func update(screen *ebiten.Image) error {
count&#43;&#43;
w, h := gophersImage.Size()
op := &amp;ebiten.DrawImageOptions{}
op.GeoM.Translate(float64(screenWidth-w)/2, float64(screenHeight-h)/2)
op.ColorM.Concat(ebiten.RotateHue(float64(count%360) * 2 * math.Pi / 360))
if err := screen.DrawImage(gophersImage, op); err != nil {
return err
}
return nil
}
func main() {
var err error
gophersImage, _, err = ebitenutil.NewImageFromFile(&#34;images/gophers.jpg&#34;, ebiten.FilterNearest)
if err != nil {
log.Fatal(err)
}
if err := ebiten.Run(update, screenWidth, screenHeight, 2, &#34;Hue (Ebiten Demo)&#34;); err != nil {
log.Fatal(err)
}
}
</code></pre>
<footer>© 2015 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

View File

@ -0,0 +1,18 @@
<!DOCTYPE html>
<!--
Copyright 2015 Hajime Hoshi
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<script src="keyboard.js"></script>

View File

@ -0,0 +1,113 @@
<!DOCTYPE html>
<!--
Copyright 2015 Hajime Hoshi
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<style>
body {
font-family: sans-serif;
}
iframe {
border-color: #999;
border-style: solid;
border-width: 1px;
overflow: hidden;
}
pre {
background: #eee;
padding: 1em;
}
</style>
<nav><a href="..">Ebiten</a></nav>
<h1>keyboard</h1>
<iframe src="keyboard.content.html" width="640" height="480"></iframe>
<pre><code>package main
import (
&#34;github.com/hajimehoshi/ebiten&#34;
&#34;github.com/hajimehoshi/ebiten/ebitenutil&#34;
&#34;log&#34;
&#34;sort&#34;
&#34;strconv&#34;
&#34;strings&#34;
)
const (
screenWidth = 320
screenHeight = 240
)
// TODO: Add Key.String() by stringer
var keyNames = map[ebiten.Key]string{
ebiten.KeyBackspace: &#34;Backspace&#34;,
ebiten.KeyComma: &#34;&#39;,&#39;&#34;,
ebiten.KeyDelete: &#34;Delete&#34;,
ebiten.KeyEnter: &#34;Enter&#34;,
ebiten.KeyEscape: &#34;Esc&#34;,
ebiten.KeyPeriod: &#34;&#39;.&#39;&#34;,
ebiten.KeySpace: &#34;Space&#34;,
ebiten.KeyTab: &#34;Tab&#34;,
// Arrows
ebiten.KeyDown: &#34;Down&#34;,
ebiten.KeyLeft: &#34;Left&#34;,
ebiten.KeyRight: &#34;Right&#34;,
ebiten.KeyUp: &#34;Up&#34;,
// Mods
ebiten.KeyShift: &#34;Shift&#34;,
ebiten.KeyControl: &#34;Ctrl&#34;,
ebiten.KeyAlt: &#34;Alt&#34;,
}
func update(screen *ebiten.Image) error {
pressed := []string{}
for i := 0; i &lt;= 9; i&#43;&#43; {
if ebiten.IsKeyPressed(ebiten.Key(i) &#43; ebiten.Key0) {
pressed = append(pressed, string(i&#43;&#39;0&#39;))
}
}
for c := &#39;A&#39;; c &lt;= &#39;Z&#39;; c&#43;&#43; {
if ebiten.IsKeyPressed(ebiten.Key(c) - &#39;A&#39; &#43; ebiten.KeyA) {
pressed = append(pressed, string(c))
}
}
for i := 1; i &lt;= 12; i&#43;&#43; {
if ebiten.IsKeyPressed(ebiten.Key(i) &#43; ebiten.KeyF1 - 1) {
pressed = append(pressed, &#34;F&#34;&#43;strconv.Itoa(i))
}
}
for key, name := range keyNames {
if ebiten.IsKeyPressed(key) {
pressed = append(pressed, name)
}
}
sort.Strings(pressed)
str := &#34;Pressed Keys: &#34; &#43; strings.Join(pressed, &#34;, &#34;)
ebitenutil.DebugPrint(screen, str)
return nil
}
func main() {
if err := ebiten.Run(update, screenWidth, screenHeight, 2, &#34;Keyboard (Ebiten Demo)&#34;); err != nil {
log.Fatal(err)
}
}
</code></pre>
<footer>© 2015 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

View File

@ -0,0 +1,18 @@
<!DOCTYPE html>
<!--
Copyright 2015 Hajime Hoshi
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<script src="mosaic.js"></script>

View File

@ -15,4 +15,72 @@ See the License for the specific language governing permissions and
limitations under the License.
-->
<script src="mosaic.js"></script>
<style>
body {
font-family: sans-serif;
}
iframe {
border-color: #999;
border-style: solid;
border-width: 1px;
overflow: hidden;
}
pre {
background: #eee;
padding: 1em;
}
</style>
<nav><a href="..">Ebiten</a></nav>
<h1>mosaic</h1>
<iframe src="mosaic.content.html" width="640" height="480"></iframe>
<pre><code>package main
import (
&#34;github.com/hajimehoshi/ebiten&#34;
&#34;github.com/hajimehoshi/ebiten/ebitenutil&#34;
_ &#34;image/jpeg&#34;
&#34;log&#34;
)
const (
screenWidth = 320
screenHeight = 240
)
const mosaicRatio = 16
var (
gophersImage *ebiten.Image
gophersRenderTarget *ebiten.Image
)
func update(screen *ebiten.Image) error {
op := &amp;ebiten.DrawImageOptions{}
op.GeoM.Scale(1.0/mosaicRatio, 1.0/mosaicRatio)
gophersRenderTarget.DrawImage(gophersImage, op)
op = &amp;ebiten.DrawImageOptions{}
op.GeoM.Scale(mosaicRatio, mosaicRatio)
screen.DrawImage(gophersRenderTarget, op)
return nil
}
func main() {
var err error
gophersImage, _, err = ebitenutil.NewImageFromFile(&#34;images/gophers.jpg&#34;, ebiten.FilterNearest)
if err != nil {
log.Fatal(err)
}
w, h := gophersImage.Size()
gophersRenderTarget, err = ebiten.NewImage(w/mosaicRatio, h/mosaicRatio, ebiten.FilterNearest)
if err != nil {
log.Fatal(err)
}
if err := ebiten.Run(update, screenWidth, screenHeight, 2, &#34;Mosaic (Ebiten Demo)&#34;); err != nil {
log.Fatal(err)
}
}
</code></pre>
<footer>© 2015 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

View File

@ -0,0 +1,18 @@
<!DOCTYPE html>
<!--
Copyright 2015 Hajime Hoshi
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<script src="perspective.js"></script>

View File

@ -15,4 +15,87 @@ See the License for the specific language governing permissions and
limitations under the License.
-->
<script src="perspective.js"></script>
<style>
body {
font-family: sans-serif;
}
iframe {
border-color: #999;
border-style: solid;
border-width: 1px;
overflow: hidden;
}
pre {
background: #eee;
padding: 1em;
}
</style>
<nav><a href="..">Ebiten</a></nav>
<h1>perspective</h1>
<iframe src="perspective.content.html" width="640" height="480"></iframe>
<pre><code>package main
import (
&#34;github.com/hajimehoshi/ebiten&#34;
&#34;github.com/hajimehoshi/ebiten/ebitenutil&#34;
_ &#34;image/jpeg&#34;
&#34;log&#34;
)
const (
screenWidth = 320
screenHeight = 240
)
var (
gophersImage *ebiten.Image
)
type parts struct {
image *ebiten.Image
}
func (p parts) Len() int {
_, h := p.image.Size()
return h
}
func (p parts) Dst(i int) (x0, y0, x1, y1 int) {
w, h := p.image.Size()
width := w &#43; i*3/4
x := ((h - i) * 3 / 4) / 2
return x, i, x &#43; width, i &#43; 1
}
func (p parts) Src(i int) (x0, y0, x1, y1 int) {
w, _ := p.image.Size()
return 0, i, w, i &#43; 1
}
func update(screen *ebiten.Image) error {
op := &amp;ebiten.DrawImageOptions{
ImageParts: &amp;parts{gophersImage},
}
w, h := gophersImage.Size()
maxWidth := float64(w) &#43; float64(h)*0.75
op.GeoM.Translate(-maxWidth/2, -float64(h)/2)
op.GeoM.Translate(screenWidth/2, screenHeight/2)
screen.DrawImage(gophersImage, op)
return nil
}
func main() {
var err error
gophersImage, _, err = ebitenutil.NewImageFromFile(&#34;images/gophers.jpg&#34;, ebiten.FilterNearest)
if err != nil {
log.Fatal(err)
}
if err := ebiten.Run(update, screenWidth, screenHeight, 2, &#34;Perspective (Ebiten Demo)&#34;); err != nil {
log.Fatal(err)
}
}
</code></pre>
<footer>© 2015 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

View File

@ -0,0 +1,18 @@
<!DOCTYPE html>
<!--
Copyright 2015 Hajime Hoshi
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<script src="rotate.js"></script>

View File

@ -15,4 +15,69 @@ See the License for the specific language governing permissions and
limitations under the License.
-->
<script src="rotate.js"></script>
<style>
body {
font-family: sans-serif;
}
iframe {
border-color: #999;
border-style: solid;
border-width: 1px;
overflow: hidden;
}
pre {
background: #eee;
padding: 1em;
}
</style>
<nav><a href="..">Ebiten</a></nav>
<h1>rotate</h1>
<iframe src="rotate.content.html" width="640" height="480"></iframe>
<pre><code>package main
import (
&#34;github.com/hajimehoshi/ebiten&#34;
&#34;github.com/hajimehoshi/ebiten/ebitenutil&#34;
_ &#34;image/jpeg&#34;
&#34;log&#34;
&#34;math&#34;
)
const (
screenWidth = 320
screenHeight = 240
)
var (
count int
gophersImage *ebiten.Image
)
func update(screen *ebiten.Image) error {
count&#43;&#43;
w, h := gophersImage.Size()
op := &amp;ebiten.DrawImageOptions{}
op.GeoM.Translate(-float64(w)/2, -float64(h)/2)
op.GeoM.Rotate(float64(count%360) * 2 * math.Pi / 360)
op.GeoM.Translate(screenWidth/2, screenHeight/2)
if err := screen.DrawImage(gophersImage, op); err != nil {
return err
}
return nil
}
func main() {
var err error
gophersImage, _, err = ebitenutil.NewImageFromFile(&#34;images/gophers.jpg&#34;, ebiten.FilterNearest)
if err != nil {
log.Fatal(err)
}
if err := ebiten.Run(update, screenWidth, screenHeight, 2, &#34;Rotate (Ebiten Demo)&#34;); err != nil {
log.Fatal(err)
}
}
</code></pre>
<footer>© 2015 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

View File

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

View File

@ -22,27 +22,11 @@ limitations under the License.
body {
font-family: sans-serif;
}
table.examples {
border-collapse: separate;
border-spacing: 0 1em;
}
table.examples td {
padding: 0;
vertical-align: top;
}
table.examples td.code pre {
height: 240px;
margin: 0;
overflow: auto;
}
table.examples td.screen {
padding-left: 1em;
}
table.examples iframe, table.examples img {
img.example {
background-color: #000;
border-color: #999;
border-style: solid;
border-width: 1px;
overflow: hidden;
}
pre {
background: #eee;
@ -56,6 +40,10 @@ pre {
<li>Works on
<ul>
<li>Web browsers (powered by <a href="http://gopherjs.org/">GopherJS</a>)
<ul>
<li>Supported browsers: Chrome, Firefox, Safari on desktops</li>
</ul>
</li>
<li>Mac OS X</li>
<li>Linux (maybe)</li>
<li>Windows (possibly)</li>
@ -72,246 +60,21 @@ pre {
</ul>
<h2>Example</h2>
<table class="examples">
<p>
<tr>
<td class="code"><pre><code>// <b>blocks</b>
// Please read example/blocks/main.go and example/blocks/blocks/*.go</code></pre></td>
<td class="screen">Click to play!<br><a href="example/blocks.html"><img src="blocks.png" width="256" height="240"></a></td>
</tr>
<a href="example/hue.html"><img src="images/example/hue.png" width="320" height="240" alt="Ebiten example: hue" class="example"></a>
<tr>
<td class="code"><pre><code>// <b>hue</b>
package main
import (
&#34;github.com/hajimehoshi/ebiten&#34;
&#34;github.com/hajimehoshi/ebiten/ebitenutil&#34;
_ &#34;image/jpeg&#34;
&#34;log&#34;
&#34;math&#34;
)
const (
screenWidth = 320
screenHeight = 240
)
var (
count int
gophersImage *ebiten.Image
)
func update(screen *ebiten.Image) error {
count&#43;&#43;
w, h := gophersImage.Size()
op := &amp;ebiten.DrawImageOptions{}
op.GeoM.Translate(float64(screenWidth-w)/2, float64(screenHeight-h)/2)
op.ColorM.Concat(ebiten.RotateHue(float64(count%360) * 2 * math.Pi / 360))
if err := screen.DrawImage(gophersImage, op); err != nil {
return err
}
return nil
}
func main() {
var err error
gophersImage, _, err = ebitenutil.NewImageFromFile(&#34;images/gophers.jpg&#34;, ebiten.FilterNearest)
if err != nil {
log.Fatal(err)
}
if err := ebiten.Run(update, screenWidth, screenHeight, 1, &#34;Hue (Ebiten Demo)&#34;); err != nil {
log.Fatal(err)
}
}
</code></pre></td>
<td class="screen"><iframe src="example/hue.html" width="320" height="240"></iframe></td>
</tr>
<a href="example/keyboard.html"><img src="images/example/keyboard.png" width="320" height="240" alt="Ebiten example: keyboard" class="example"></a>
<tr>
<td class="code"><pre><code>// <b>mosaic</b>
package main
import (
&#34;github.com/hajimehoshi/ebiten&#34;
&#34;github.com/hajimehoshi/ebiten/ebitenutil&#34;
_ &#34;image/jpeg&#34;
&#34;log&#34;
)
const (
screenWidth = 320
screenHeight = 240
)
const mosaicRatio = 16
var (
gophersImage *ebiten.Image
gophersRenderTarget *ebiten.Image
)
func update(screen *ebiten.Image) error {
op := &amp;ebiten.DrawImageOptions{}
op.GeoM.Scale(1.0/mosaicRatio, 1.0/mosaicRatio)
gophersRenderTarget.DrawImage(gophersImage, op)
op = &amp;ebiten.DrawImageOptions{}
op.GeoM.Scale(mosaicRatio, mosaicRatio)
screen.DrawImage(gophersRenderTarget, op)
return nil
}
func main() {
var err error
gophersImage, _, err = ebitenutil.NewImageFromFile(&#34;images/gophers.jpg&#34;, ebiten.FilterNearest)
if err != nil {
log.Fatal(err)
}
w, h := gophersImage.Size()
gophersRenderTarget, err = ebiten.NewImage(w/mosaicRatio, h/mosaicRatio, ebiten.FilterNearest)
if err != nil {
log.Fatal(err)
}
if err := ebiten.Run(update, screenWidth, screenHeight, 1, &#34;Mosaic (Ebiten Demo)&#34;); err != nil {
log.Fatal(err)
}
}
</code></pre></td>
<td class="screen"><iframe src="example/mosaic.html" width="320" height="240"></iframe></td>
</tr>
<a href="example/mosaic.html"><img src="images/example/mosaic.png" width="320" height="240" alt="Ebiten example: mosaic" class="example"></a>
<tr>
<td class="code"><pre><code>// <b>perspective</b>
package main
import (
&#34;github.com/hajimehoshi/ebiten&#34;
&#34;github.com/hajimehoshi/ebiten/ebitenutil&#34;
_ &#34;image/jpeg&#34;
&#34;log&#34;
)
const (
screenWidth = 320
screenHeight = 240
)
var (
gophersImage *ebiten.Image
)
type parts struct {
image *ebiten.Image
}
func (p parts) Len() int {
_, h := p.image.Size()
return h
}
func (p parts) Dst(i int) (x0, y0, x1, y1 int) {
w, h := p.image.Size()
width := w &#43; i*3/4
x := ((h - i) * 3 / 4) / 2
return x, i, x &#43; width, i &#43; 1
}
func (p parts) Src(i int) (x0, y0, x1, y1 int) {
w, _ := p.image.Size()
return 0, i, w, i &#43; 1
}
func update(screen *ebiten.Image) error {
op := &amp;ebiten.DrawImageOptions{
ImageParts: &amp;parts{gophersImage},
}
w, h := gophersImage.Size()
maxWidth := float64(w) &#43; float64(h)*0.75
op.GeoM.Translate(-maxWidth/2, -float64(h)/2)
op.GeoM.Translate(screenWidth/2, screenHeight/2)
screen.DrawImage(gophersImage, op)
return nil
}
func main() {
var err error
gophersImage, _, err = ebitenutil.NewImageFromFile(&#34;images/gophers.jpg&#34;, ebiten.FilterNearest)
if err != nil {
log.Fatal(err)
}
if err := ebiten.Run(update, screenWidth, screenHeight, 1, &#34;Perspective (Ebiten Demo)&#34;); err != nil {
log.Fatal(err)
}
}
</code></pre></td>
<td class="screen"><iframe src="example/perspective.html" width="320" height="240"></iframe></td>
</tr>
<a href="example/perspective.html"><img src="images/example/perspective.png" width="320" height="240" alt="Ebiten example: perspective" class="example"></a>
<tr>
<td class="code"><pre><code>// <b>rotate</b>
package main
import (
&#34;github.com/hajimehoshi/ebiten&#34;
&#34;github.com/hajimehoshi/ebiten/ebitenutil&#34;
_ &#34;image/jpeg&#34;
&#34;log&#34;
&#34;math&#34;
)
const (
screenWidth = 320
screenHeight = 240
)
var (
count int
gophersImage *ebiten.Image
)
func update(screen *ebiten.Image) error {
count&#43;&#43;
w, h := gophersImage.Size()
op := &amp;ebiten.DrawImageOptions{}
op.GeoM.Translate(-float64(w)/2, -float64(h)/2)
op.GeoM.Rotate(float64(count%360) * 2 * math.Pi / 360)
op.GeoM.Translate(screenWidth/2, screenHeight/2)
if err := screen.DrawImage(gophersImage, op); err != nil {
return err
}
return nil
}
func main() {
var err error
gophersImage, _, err = ebitenutil.NewImageFromFile(&#34;images/gophers.jpg&#34;, ebiten.FilterNearest)
if err != nil {
log.Fatal(err)
}
if err := ebiten.Run(update, screenWidth, screenHeight, 1, &#34;Rotate (Ebiten Demo)&#34;); err != nil {
log.Fatal(err)
}
}
</code></pre></td>
<td class="screen"><iframe src="example/rotate.html" width="320" height="240"></iframe></td>
</tr>
<a href="example/rotate.html"><img src="images/example/rotate.png" width="320" height="240" alt="Ebiten example: rotate" class="example"></a>
</table>
<a href="example/blocks.html"><img src="images/example/blocks.png" width="256" height="240" alt="Ebiten example: blocks" class="example"></a>
</p>
<h2>Install on Mac OS X</h2>
<pre><code>:; brew install glew
@ -325,19 +88,16 @@ func main() {
<pre><code>:; cd $GOHOME/src/github.com/hajimehoshi/ebiten/example
:; go run rotate/main.go</code></pre>
<h2>Execute the example on a web browser</h2>
<p>If you can the example screens above, Ebiten is working on your browser! Each example above works as an independent html in an iframe. If you want to execute the examples apart from this site, execute this:</p>
<pre><code>:; go run $GOPATH/src/github.com/hajimehoshi/ebiten/example/server/main.go</code></pre>
<p>Then, open <code>localhost:8000</code> on your browser.</p>
<p><code>localhost:8000/?EXAMPLE_NAME</code> shows other examples (e.g. <code>localhost:8000/?rotate</code>).</p>
<p>Of cource, you can execute gopherjs yourself. Please see <a href="http://gopherjs.org/">GopherJS site</a> for more detail.</p>
<h2>Run your game on a desktop</h2>
<p>Just execute your Go program. That's it!</p>
<h2>Run your game on a web browser</h2>
<p>Compile your game with GopherJS:</p>
<p>Compile your game with <a href="http://gopherjs.org/">GopherJS</a>:</p>
<pre><code>:; gopherjs build -o yourgame.js path/to/yourgame</code></pre>
<p>Then, open the below HTML on your HTTP server:</p>
<pre><code>&lt;!DOCTYPE html&gt;
&lt;script src="yourgame.js"&gt;&lt;/script&gt;</code></pre>
<p>NOTE: <code>file://</code> URL may not work with Ebiten. Execute your game on a HTTP server.</p>
<h2>Change Log</h2>
<h3>2015-??-??</h3>
@ -352,6 +112,7 @@ func main() {
<li>A lot of keyboard keys have been added. KeyMax and MouseButtonMax were removed.</li>
</ul>
</li>
<li>The game is stopped when the window is not active.</li>
</ul>
</li>
</ul>
@ -386,3 +147,5 @@ limitations under the License.
</pre>
<h3>Go Gopher photograph</h3>
<p><a href="http://blog.golang.org/go-programming-language-turns-two">The original photograph of Go gophers by Chris Nokleberg</a> is licensed under the Creative Commons 3.0 Attributions license.</p>
<footer>© 2015 Hajime Hoshi</footer>

View File

@ -50,7 +50,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
if err := ebiten.Run(update, screenWidth, screenHeight, 1, "Hue (Ebiten Demo)"); err != nil {
if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Hue (Ebiten Demo)"); err != nil {
log.Fatal(err)
}
}

View File

@ -54,7 +54,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
if err := ebiten.Run(update, screenWidth, screenHeight, 1, "Mosaic (Ebiten Demo)"); err != nil {
if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Mosaic (Ebiten Demo)"); err != nil {
log.Fatal(err)
}
}

View File

@ -69,7 +69,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
if err := ebiten.Run(update, screenWidth, screenHeight, 1, "Perspective (Ebiten Demo)"); err != nil {
if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Perspective (Ebiten Demo)"); err != nil {
log.Fatal(err)
}
}

View File

@ -51,7 +51,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
if err := ebiten.Run(update, screenWidth, screenHeight, 1, "Rotate (Ebiten Demo)"); err != nil {
if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Rotate (Ebiten Demo)"); err != nil {
log.Fatal(err)
}
}

View File

@ -27,8 +27,7 @@ var canvas js.Object
var context *opengl.Context
func shown() bool {
w := js.Global.Get("window").Get("top")
return !w.Get("document").Get("hidden").Bool()
return !js.Global.Get("document").Get("hidden").Bool()
}
func Use(f func(*opengl.Context)) {