doc: Add and remove examples

This commit is contained in:
Hajime Hoshi 2016-02-16 00:52:45 +09:00
parent 4c2048d77d
commit e6fbbc9ea9
11 changed files with 618 additions and 257 deletions

View File

@ -167,13 +167,16 @@ func versions() string {
}
var examples = []example{
{Name: "alphablending"},
{Name: "hue"},
{Name: "gamepad"},
{Name: "keyboard"},
{Name: "mosaic"},
{Name: "noise"},
{Name: "paint"},
{Name: "perspective"},
{Name: "piano"},
{Name: "rotate"},
{Name: "sprites"},
{Name: "blocks"},
}

View File

@ -0,0 +1,39 @@
<!DOCTYPE html>
<!--
Copyright 2014 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>
'use strict';
window.addEventListener('load', function() {
function isProduction() {
var l = window.top.location;
if (l.hash === '#_production') {
return true;
}
if (l.hostname === 'localhost' || l.hostname === '127.0.0.1') {
return false;
}
return true;
}
var s = document.createElement('script');
var src = 'alphablending.js';
if (isProduction()) {
src = '//hajimehoshi.github.io/ebiten.pagestorage/master/' + src;
}
s.src = src;
document.body.appendChild(s);
});
</script>

View File

@ -0,0 +1,116 @@
<!DOCTYPE html>
<!--
Copyright 2014 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.
-->
<link rel="shortcut icon" href="../favicon.png" type="image/png" >
<link rel="icon" href="../favicon.png" type="image/png" >
<title>Ebiten example - alphablending</title>
<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>Ebiten example - alphablending</h1>
<iframe src="alphablending.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/color&#34;
_ &#34;image/png&#34;
&#34;log&#34;
)
const (
screenWidth = 320
screenHeight = 240
)
var (
count int
tmpRenderTarget *ebiten.Image
ebitenImage *ebiten.Image
saved bool
)
func update(screen *ebiten.Image) error {
count&#43;&#43;
count %= 600
diff := float64(count) * 0.2
switch {
case 480 &lt; count:
diff = 0
case 240 &lt; count:
diff = float64(480-count) * 0.2
}
if err := tmpRenderTarget.Clear(); err != nil {
return err
}
for i := 0; i &lt; 10; i&#43;&#43; {
op := &amp;ebiten.DrawImageOptions{}
op.GeoM.Translate(15&#43;float64(i)*diff, 20)
op.ColorM.Scale(1.0, 1.0, 1.0, 0.5)
if err := tmpRenderTarget.DrawImage(ebitenImage, op); err != nil {
return err
}
}
screen.Fill(color.NRGBA{0x00, 0x00, 0x80, 0xff})
for i := 0; i &lt; 10; i&#43;&#43; {
op := &amp;ebiten.DrawImageOptions{}
op.GeoM.Translate(0, float64(i)*diff)
if err := screen.DrawImage(tmpRenderTarget, op); err != nil {
return err
}
}
return nil
}
func main() {
var err error
ebitenImage, _, err = ebitenutil.NewImageFromFile(&#34;images/ebiten.png&#34;, ebiten.FilterNearest)
if err != nil {
log.Fatal(err)
}
tmpRenderTarget, err = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterNearest)
if err != nil {
log.Fatal(err)
}
//update := update
//f, _ := os.Create(&#34;out.gif&#34;)
//update = ebitenutil.RecordScreenAsGIF(update, f, 100)
if err := ebiten.Run(update, screenWidth, screenHeight, 2, &#34;Alpha Blending (Ebiten Demo)&#34;); err != nil {
log.Fatal(err)
}
}
</code></pre>
<footer>© 2014 Hajime Hoshi</footer>

View File

@ -0,0 +1,39 @@
<!DOCTYPE html>
<!--
Copyright 2014 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>
'use strict';
window.addEventListener('load', function() {
function isProduction() {
var l = window.top.location;
if (l.hash === '#_production') {
return true;
}
if (l.hostname === 'localhost' || l.hostname === '127.0.0.1') {
return false;
}
return true;
}
var s = document.createElement('script');
var src = 'gamepad.js';
if (isProduction()) {
src = '//hajimehoshi.github.io/ebiten.pagestorage/master/' + src;
}
s.src = src;
document.body.appendChild(s);
});
</script>

View File

@ -0,0 +1,92 @@
<!DOCTYPE html>
<!--
Copyright 2014 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.
-->
<link rel="shortcut icon" href="../favicon.png" type="image/png" >
<link rel="icon" href="../favicon.png" type="image/png" >
<title>Ebiten example - gamepad</title>
<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>Ebiten example - gamepad</h1>
<iframe src="gamepad.content.html" width="640" height="480"></iframe>
<pre><code>package main
import (
&#34;fmt&#34;
&#34;github.com/hajimehoshi/ebiten&#34;
&#34;github.com/hajimehoshi/ebiten/ebitenutil&#34;
&#34;log&#34;
&#34;strconv&#34;
&#34;strings&#34;
)
const (
screenWidth = 320
screenHeight = 240
)
func update(screen *ebiten.Image) error {
// TODO: API to get the available, lowest ID
const gamepadID = 0
axes := []string{}
pressedButtons := []string{}
maxAxis := ebiten.GamepadAxisNum(gamepadID)
for a := 0; a &lt; maxAxis; a&#43;&#43; {
v := ebiten.GamepadAxis(gamepadID, a)
axes = append(axes, fmt.Sprintf(&#34;%d: %0.6f&#34;, a, v))
}
maxButton := ebiten.GamepadButton(ebiten.GamepadButtonNum(gamepadID))
for b := ebiten.GamepadButton(gamepadID); b &lt; maxButton; b&#43;&#43; {
if ebiten.IsGamepadButtonPressed(gamepadID, b) {
pressedButtons = append(pressedButtons, strconv.Itoa(int(b)))
}
}
str := `Gamepad
Axes:
{{.Axes}}
Pressed Buttons: {{.Buttons}}`
str = strings.Replace(str, &#34;{{.Axes}}&#34;, strings.Join(axes, &#34;\n &#34;), -1)
str = strings.Replace(str, &#34;{{.Buttons}}&#34;, strings.Join(pressedButtons, &#34;, &#34;), -1)
ebitenutil.DebugPrint(screen, str)
return nil
}
func main() {
if err := ebiten.Run(update, screenWidth, screenHeight, 2, &#34;Gamepad (Ebiten Demo)&#34;); err != nil {
log.Fatal(err)
}
}
</code></pre>
<footer>© 2014 Hajime Hoshi</footer>

View File

@ -29,7 +29,7 @@ window.addEventListener('load', function() {
}
var s = document.createElement('script');
var src = 'piano.js';
var src = 'noise.js';
if (isProduction()) {
src = '//hajimehoshi.github.io/ebiten.pagestorage/master/' + src;
}

View File

@ -0,0 +1,97 @@
<!DOCTYPE html>
<!--
Copyright 2014 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.
-->
<link rel="shortcut icon" href="../favicon.png" type="image/png" >
<link rel="icon" href="../favicon.png" type="image/png" >
<title>Ebiten example - noise</title>
<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>Ebiten example - noise</h1>
<iframe src="noise.content.html" width="640" height="480"></iframe>
<pre><code>package main
import (
&#34;fmt&#34;
&#34;github.com/hajimehoshi/ebiten&#34;
&#34;github.com/hajimehoshi/ebiten/ebitenutil&#34;
&#34;image&#34;
&#34;log&#34;
//&#34;math/rand&#34;
)
const (
screenWidth = 320
screenHeight = 240
)
var (
noiseImage *image.RGBA
)
type rand struct {
x, y, z, w uint32
}
func (r *rand) next() uint32 {
// math/rand is too slow to keep 60 FPS on web browsers.
// Use Xorshift instead: http://en.wikipedia.org/wiki/Xorshift
t := r.x ^ (r.x &lt;&lt; 11)
r.x, r.y, r.z = r.y, r.z, r.w
r.w = (r.w ^ (r.w &gt;&gt; 19)) ^ (t ^ (t &gt;&gt; 8))
return r.w
}
var randInstance = &amp;rand{12345678, 4185243, 776511, 45411}
func update(screen *ebiten.Image) error {
const l = screenWidth * screenHeight
for i := 0; i &lt; l; i&#43;&#43; {
x := randInstance.next()
noiseImage.Pix[4*i] = uint8(x &gt;&gt; 24)
noiseImage.Pix[4*i&#43;1] = uint8(x &gt;&gt; 16)
noiseImage.Pix[4*i&#43;2] = uint8(x &gt;&gt; 8)
noiseImage.Pix[4*i&#43;3] = 0xff
}
screen.ReplacePixels(noiseImage.Pix)
ebitenutil.DebugPrint(screen, fmt.Sprintf(&#34;FPS: %f&#34;, ebiten.CurrentFPS()))
return nil
}
func main() {
noiseImage = image.NewRGBA(image.Rect(0, 0, screenWidth, screenHeight))
if err := ebiten.Run(update, screenWidth, screenHeight, 2, &#34;Noise (Ebiten Demo)&#34;); err != nil {
log.Fatal(err)
}
}
</code></pre>
<footer>© 2014 Hajime Hoshi</footer>

View File

@ -1,253 +0,0 @@
<!DOCTYPE html>
<!--
Copyright 2014 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.
-->
<link rel="shortcut icon" href="../favicon.png" type="image/png" >
<link rel="icon" href="../favicon.png" type="image/png" >
<title>Ebiten example - piano</title>
<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>Ebiten example - piano</h1>
<iframe src="piano.content.html" width="640" height="480"></iframe>
<pre><code>package main
import (
&#34;bytes&#34;
&#34;fmt&#34;
&#34;image/color&#34;
&#34;log&#34;
&#34;math&#34;
&#34;github.com/hajimehoshi/ebiten&#34;
&#34;github.com/hajimehoshi/ebiten/ebitenutil&#34;
&#34;github.com/hajimehoshi/ebiten/examples/common&#34;
&#34;github.com/hajimehoshi/ebiten/exp/audio&#34;
)
const (
screenWidth = 320
screenHeight = 240
sampleRate = 44100
)
var pcm = make([]float64, 4*sampleRate)
const baseFreq = 220
func init() {
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 &lt; len(pcm); i&#43;&#43; {
v := 0.0
twoPiF := 2.0 * math.Pi * baseFreq
for j := 0; j &lt; len(amp); j&#43;&#43; {
a := amp[j] * math.Exp(-5*float64(i)/(x[j]*s))
v &#43;= a * math.Sin(float64(i)*twoPiF*float64(j&#43;1)/s)
}
pcm[i] = v / 5.0
}
}
var (
noteCache = map[int][]byte{}
)
func toBytes(l, r []int16) []byte {
if len(l) != len(r) {
panic(&#34;len(l) must equal to len(r)&#34;)
}
b := make([]byte, len(l)*4)
for i, _ := range l {
b[4*i] = byte(l[i])
b[4*i&#43;1] = byte(l[i] &gt;&gt; 8)
b[4*i&#43;2] = byte(r[i])
b[4*i&#43;3] = byte(r[i] &gt;&gt; 8)
}
return b
}
type stream struct {
*bytes.Reader
}
func (s *stream) Close() error {
return nil
}
func addNote(freq float64, vol float64) error {
f := int(freq)
if n, ok := noteCache[f]; ok {
p, err := audio.NewPlayer(&amp;stream{bytes.NewReader(n)}, sampleRate)
if err == audio.ErrTooManyPlayers {
return nil
}
if err != nil {
return err
}
p.Play()
return nil
}
length := len(pcm) * baseFreq / f
l := make([]int16, length)
r := make([]int16, length)
j := 0
jj := 0
for i := 0; i &lt; len(l); i&#43;&#43; {
p := pcm[j]
l[i] = int16(p * vol * math.MaxInt16)
r[i] = l[i]
jj &#43;= f
j = jj / baseFreq
}
n := toBytes(l, r)
noteCache[f] = n
p, err := audio.NewPlayer(&amp;stream{bytes.NewReader(n)}, sampleRate)
if err == audio.ErrTooManyPlayers {
return nil
}
if err != nil {
return err
}
p.Play()
return nil
}
var keys = []ebiten.Key{
ebiten.KeyQ,
ebiten.KeyA,
ebiten.KeyW,
ebiten.KeyS,
ebiten.KeyD,
ebiten.KeyR,
ebiten.KeyF,
ebiten.KeyT,
ebiten.KeyG,
ebiten.KeyH,
ebiten.KeyU,
ebiten.KeyJ,
ebiten.KeyI,
ebiten.KeyK,
ebiten.KeyO,
ebiten.KeyL,
}
var keyStates = map[ebiten.Key]int{}
func init() {
for _, key := range keys {
keyStates[key] = 0
}
}
func updateInput() {
for _, key := range keys {
if !ebiten.IsKeyPressed(key) {
keyStates[key] = 0
continue
}
keyStates[key]&#43;&#43;
}
}
var (
imagePiano *ebiten.Image
)
func init() {
var err error
imageEmpty, err := ebiten.NewImage(16, 16, ebiten.FilterNearest)
if err != nil {
panic(err)
}
imageEmpty.Fill(color.White)
imagePiano, err = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterNearest)
if err != nil {
panic(err)
}
whiteKeys := []string{&#34;A&#34;, &#34;S&#34;, &#34;D&#34;, &#34;F&#34;, &#34;G&#34;, &#34;H&#34;, &#34;J&#34;, &#34;K&#34;, &#34;L&#34;}
width := 24
y := 48
for i, k := range whiteKeys {
x := i*width &#43; 36
height := 112
op := &amp;ebiten.DrawImageOptions{}
w, h := imageEmpty.Size()
op.GeoM.Scale(float64(width-1)/float64(w), float64(height)/float64(h))
op.GeoM.Translate(float64(x), float64(y))
op.ColorM.Scale(1, 1, 1, 1)
imagePiano.DrawImage(imageEmpty, op)
common.ArcadeFont.DrawText(imagePiano, k, x&#43;8, y&#43;height-16, 1, color.Black)
}
blackKeys := []string{&#34;Q&#34;, &#34;W&#34;, &#34;&#34;, &#34;R&#34;, &#34;T&#34;, &#34;&#34;, &#34;U&#34;, &#34;I&#34;, &#34;O&#34;}
for i, k := range blackKeys {
if k == &#34;&#34; {
continue
}
x := i*width &#43; 24
height := 64
op := &amp;ebiten.DrawImageOptions{}
w, h := imageEmpty.Size()
op.GeoM.Scale(float64(width-1)/float64(w), float64(height)/float64(h))
op.GeoM.Translate(float64(x), float64(y))
op.ColorM.Scale(0, 0, 0, 1)
imagePiano.DrawImage(imageEmpty, op)
common.ArcadeFont.DrawText(imagePiano, k, x&#43;8, y&#43;height-16, 1, color.White)
}
}
func update(screen *ebiten.Image) error {
updateInput()
for i, key := range keys {
if keyStates[key] != 1 {
continue
}
if err := addNote(220*math.Exp2(float64(i-1)/12.0), 1.0); err != nil {
return err
}
}
screen.Fill(color.RGBA{0x80, 0x80, 0xc0, 0xff})
screen.DrawImage(imagePiano, nil)
ebitenutil.DebugPrint(screen, fmt.Sprintf(&#34;FPS: %0.2f&#34;, ebiten.CurrentFPS()))
return nil
}
func main() {
if err := ebiten.Run(update, screenWidth, screenHeight, 2, &#34;Piano (Ebiten Demo)&#34;); err != nil {
log.Fatal(err)
}
}
</code></pre>
<footer>© 2014 Hajime Hoshi</footer>

View File

@ -0,0 +1,39 @@
<!DOCTYPE html>
<!--
Copyright 2014 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>
'use strict';
window.addEventListener('load', function() {
function isProduction() {
var l = window.top.location;
if (l.hash === '#_production') {
return true;
}
if (l.hostname === 'localhost' || l.hostname === '127.0.0.1') {
return false;
}
return true;
}
var s = document.createElement('script');
var src = 'sprites.js';
if (isProduction()) {
src = '//hajimehoshi.github.io/ebiten.pagestorage/master/' + src;
}
s.src = src;
document.body.appendChild(s);
});
</script>

View File

@ -0,0 +1,183 @@
<!DOCTYPE html>
<!--
Copyright 2014 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.
-->
<link rel="shortcut icon" href="../favicon.png" type="image/png" >
<link rel="icon" href="../favicon.png" type="image/png" >
<title>Ebiten example - sprites</title>
<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>Ebiten example - sprites</h1>
<iframe src="sprites.content.html" width="640" height="480"></iframe>
<pre><code>package main
import (
&#34;fmt&#34;
&#34;github.com/hajimehoshi/ebiten&#34;
&#34;github.com/hajimehoshi/ebiten/ebitenutil&#34;
_ &#34;image/png&#34;
&#34;log&#34;
&#34;math/rand&#34;
)
const (
screenWidth = 320
screenHeight = 240
)
var (
ebitenImage *ebiten.Image
ebitenImageWidth = 0
ebitenImageHeight = 0
)
type Sprite struct {
image *ebiten.Image
x int
y int
vx int
vy int
}
func (s *Sprite) Update() {
s.x &#43;= s.vx
s.y &#43;= s.vy
if s.x &lt; 0 {
s.x = -s.x
s.vx = -s.vx
}
if s.y &lt; 0 {
s.y = -s.y
s.vy = -s.vy
}
w, h := s.image.Size()
if screenWidth &lt;= s.x&#43;w {
s.x = 2*(screenWidth-w) - s.x
s.vx = -s.vx
}
if screenHeight &lt;= s.y&#43;h {
s.y = 2*(screenHeight-h) - s.y
s.vy = -s.vy
}
}
type Sprites struct {
sprites []*Sprite
num int
}
func (s Sprites) Update() {
for _, sprite := range s.sprites {
sprite.Update()
}
}
func (s Sprites) Len() int {
return s.num
}
func (s Sprites) Dst(i int) (x0, y0, x1, y1 int) {
if s.num &lt;= i {
return 0, 0, 0, 0
}
ss := s.sprites[i]
return ss.x, ss.y, ss.x &#43; ebitenImageWidth, ss.y &#43; ebitenImageHeight
}
func (s Sprites) Src(i int) (x0, y0, x1, y1 int) {
if s.num &lt;= i {
return 0, 0, 0, 0
}
return 0, 0, ebitenImageWidth, ebitenImageHeight
}
const (
MinSprites = 0
MaxSprites = 10000
)
var sprites = &amp;Sprites{make([]*Sprite, MaxSprites), 500}
func update(screen *ebiten.Image) error {
if ebiten.IsKeyPressed(ebiten.KeyLeft) {
sprites.num -= 20
if sprites.num &lt; MinSprites {
sprites.num = MinSprites
}
}
if ebiten.IsKeyPressed(ebiten.KeyRight) {
sprites.num &#43;= 20
if MaxSprites &lt; sprites.num {
sprites.num = MaxSprites
}
}
sprites.Update()
op := &amp;ebiten.DrawImageOptions{
ImageParts: sprites,
}
op.ColorM.Scale(1.0, 1.0, 1.0, 0.5)
if err := screen.DrawImage(ebitenImage, op); err != nil {
return err
}
msg := fmt.Sprintf(`FPS: %0.2f
Num of sprites: %d
Press &lt;- or -&gt; to change the number of sprites`, ebiten.CurrentFPS(), sprites.Len())
ebitenutil.DebugPrint(screen, msg)
return nil
}
func main() {
var err error
ebitenImage, _, err = ebitenutil.NewImageFromFile(&#34;images/ebiten.png&#34;, ebiten.FilterNearest)
if err != nil {
log.Fatal(err)
}
ebitenImageWidth, ebitenImageHeight = ebitenImage.Size()
for i, _ := range sprites.sprites {
w, h := ebitenImage.Size()
x, y := rand.Intn(screenWidth-w), rand.Intn(screenHeight-h)
vx, vy := 2*rand.Intn(2)-1, 2*rand.Intn(2)-1
sprites.sprites[i] = &amp;Sprite{
image: ebitenImage,
x: x,
y: y,
vx: vx,
vy: vy,
}
}
if err := ebiten.Run(update, screenWidth, screenHeight, 2, &#34;Sprites (Ebiten Demo)&#34;); err != nil {
log.Fatal(err)
}
}
</code></pre>
<footer>© 2014 Hajime Hoshi</footer>

View File

@ -62,20 +62,26 @@ pre {
<h2>Example</h2>
<p>
<a href="examples/alphablending.html"><img src="images/examples/alphablending.png" width="320" height="240" alt="Ebiten example: alphablending" 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="examples/gamepad.html"><img src="images/examples/gamepad.png" width="320" height="240" alt="Ebiten example: gamepad" 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="examples/mosaic.html"><img src="images/examples/mosaic.png" width="320" height="240" alt="Ebiten example: mosaic" class="example"></a>
<a href="examples/noise.html"><img src="images/examples/noise.png" width="320" height="240" alt="Ebiten example: noise" 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="examples/perspective.html"><img src="images/examples/perspective.png" width="320" height="240" alt="Ebiten example: perspective" 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="examples/rotate.html"><img src="images/examples/rotate.png" width="320" height="240" alt="Ebiten example: rotate" class="example"></a>
<a href="examples/sprites.html"><img src="images/examples/sprites.png" width="320" height="240" alt="Ebiten example: sprites" 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>