doc: Update: changed the path for the script location

This commit is contained in:
Hajime Hoshi 2017-05-29 22:01:47 +09:00
parent 6db96f5442
commit fb65fe1fee
25 changed files with 101 additions and 132 deletions

View File

@ -16,7 +16,7 @@ window.addEventListener('load', function() {
var s = document.createElement('script');
var src = '{{.Example.Name}}.js';
if (isProduction()) {
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
}
s.src = src;
s.onload = function() {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@ -16,7 +16,7 @@ window.addEventListener('load', function() {
var s = document.createElement('script');
var src = 'alphablending.js';
if (isProduction()) {
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
}
s.src = src;
s.onload = function() {

View File

@ -48,26 +48,6 @@ var (
ebitenImage *ebiten.Image
)
type imageParts struct {
diff float64
}
func (p *imageParts) Src(i int) (int, int, int, int) {
w, h := ebitenImage.Size()
return 0, 0, w, h
}
func (p *imageParts) Dst(i int) (int, int, int, int) {
x := int(float64(i%10)*p.diff + 15)
y := int(float64(i/10)*p.diff + 20)
w, h := ebitenImage.Size()
return x, y, x + w, y + h
}
func (p *imageParts) Len() int {
return 10 * 10
}
func update(screen *ebiten.Image) error {
count++
count %= ebiten.FPS * 10
@ -84,10 +64,13 @@ func update(screen *ebiten.Image) error {
screen.Fill(color.NRGBA{0x00, 0x00, 0x80, 0xff})
op := &ebiten.DrawImageOptions{}
op.ColorM.Scale(1.0, 1.0, 1.0, 0.5)
op.ImageParts = &imageParts{
diff: diff,
for i := 0; i < 10*10; i++ {
op.GeoM.Reset()
x := float64(i%10)*diff + 15
y := float64(i/10)*diff + 20
op.GeoM.Translate(x, y)
screen.DrawImage(ebitenImage, op)
}
screen.DrawImage(ebitenImage, op)
return nil
}

View File

@ -16,7 +16,7 @@ window.addEventListener('load', function() {
var s = document.createElement('script');
var src = 'audio.js';
if (isProduction()) {
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
}
s.src = src;
s.onload = function() {

View File

@ -16,7 +16,7 @@ window.addEventListener('load', function() {
var s = document.createElement('script');
var src = 'blocks.js';
if (isProduction()) {
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
}
s.src = src;
s.onload = function() {

View File

@ -16,7 +16,7 @@ window.addEventListener('load', function() {
var s = document.createElement('script');
var src = 'font.js';
if (isProduction()) {
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
}
s.src = src;
s.onload = function() {

View File

@ -16,7 +16,7 @@ window.addEventListener('load', function() {
var s = document.createElement('script');
var src = 'gamepad.js';
if (isProduction()) {
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
}
s.src = src;
s.onload = function() {

View File

@ -16,7 +16,7 @@ window.addEventListener('load', function() {
var s = document.createElement('script');
var src = 'hsv.js';
if (isProduction()) {
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
}
s.src = src;
s.onload = function() {

View File

@ -16,7 +16,7 @@ window.addEventListener('load', function() {
var s = document.createElement('script');
var src = 'hue.js';
if (isProduction()) {
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
}
s.src = src;
s.onload = function() {

View File

@ -16,7 +16,7 @@ window.addEventListener('load', function() {
var s = document.createElement('script');
var src = 'infinitescroll.js';
if (isProduction()) {
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
}
s.src = src;
s.onload = function() {

View File

@ -16,7 +16,7 @@ window.addEventListener('load', function() {
var s = document.createElement('script');
var src = 'keyboard.js';
if (isProduction()) {
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
}
s.src = src;
s.onload = function() {

View File

@ -54,14 +54,22 @@ func init() {
}
var keyNames = map[ebiten.Key]string{
ebiten.KeyBackspace: "BS",
ebiten.KeyComma: ",",
ebiten.KeyDelete: "Del",
ebiten.KeyEnter: "Enter",
ebiten.KeyEscape: "Esc",
ebiten.KeyPeriod: ".",
ebiten.KeySpace: "Space",
ebiten.KeyTab: "Tab",
ebiten.KeyBackspace: "BS",
ebiten.KeyComma: ",",
ebiten.KeyEnter: "Enter",
ebiten.KeyEscape: "Esc",
ebiten.KeyPeriod: ".",
ebiten.KeySpace: "Space",
ebiten.KeyTab: "Tab",
ebiten.KeyMinus: "-",
ebiten.KeyEqual: "=",
ebiten.KeyBackslash: "\\",
ebiten.KeyGraveAccent: "`",
ebiten.KeyLeftBracket: "[",
ebiten.KeyRightBracket: "]",
ebiten.KeySemicolon: ";",
ebiten.KeyApostrophe: "'",
ebiten.KeySlash: "/",
// Arrows
ebiten.KeyDown: "Down",
@ -75,26 +83,10 @@ var keyNames = map[ebiten.Key]string{
ebiten.KeyAlt: "Alt",
}
type pressedKeysParts []string
func (p pressedKeysParts) Len() int {
return len(p)
}
func (p pressedKeysParts) Dst(i int) (x0, y0, x1, y1 int) {
k := p[i]
r, ok := keyboard.KeyRect(k)
if !ok {
return 0, 0, 0, 0
}
return r.Min.X, r.Min.Y, r.Max.X, r.Max.Y
}
func (p pressedKeysParts) Src(i int) (x0, y0, x1, y1 int) {
return p.Dst(i)
}
func update(screen *ebiten.Image) error {
if ebiten.IsRunningSlowly() {
return nil
}
const offsetX, offsetY = 24, 40
op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(offsetX, offsetY)
@ -123,11 +115,18 @@ func update(screen *ebiten.Image) error {
}
}
op = &ebiten.DrawImageOptions{
ImageParts: pressedKeysParts(pressed),
op = &ebiten.DrawImageOptions{}
for _, p := range pressed {
op.GeoM.Reset()
r, ok := keyboard.KeyRect(p)
if !ok {
continue
}
op.GeoM.Translate(float64(r.Min.X), float64(r.Min.Y))
op.GeoM.Translate(offsetX, offsetY)
op.SourceRect = &r
screen.DrawImage(keyboardImage, op)
}
op.GeoM.Translate(offsetX, offsetY)
screen.DrawImage(keyboardImage, op)
return nil
}

View File

@ -16,7 +16,7 @@ window.addEventListener('load', function() {
var s = document.createElement('script');
var src = 'life.js';
if (isProduction()) {
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
}
s.src = src;
s.onload = function() {

View File

@ -16,7 +16,7 @@ window.addEventListener('load', function() {
var s = document.createElement('script');
var src = 'masking.js';
if (isProduction()) {
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
}
s.src = src;
s.onload = function() {

View File

@ -16,7 +16,7 @@ window.addEventListener('load', function() {
var s = document.createElement('script');
var src = 'mosaic.js';
if (isProduction()) {
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
}
s.src = src;
s.onload = function() {

View File

@ -16,7 +16,7 @@ window.addEventListener('load', function() {
var s = document.createElement('script');
var src = 'noise.js';
if (isProduction()) {
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
}
s.src = src;
s.onload = function() {

View File

@ -16,7 +16,7 @@ window.addEventListener('load', function() {
var s = document.createElement('script');
var src = 'paint.js';
if (isProduction()) {
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
}
s.src = src;
s.onload = function() {

View File

@ -16,7 +16,7 @@ window.addEventListener('load', function() {
var s = document.createElement('script');
var src = 'perspective.js';
if (isProduction()) {
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
}
s.src = src;
s.onload = function() {

View File

@ -30,6 +30,7 @@
package main
import (
"image"
_ "image/jpeg"
"log"
@ -46,39 +47,25 @@ 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 + i*3/4
x := ((h - i) * 3 / 4) / 2
return x, i, x + width, i + 1
}
func (p parts) Src(i int) (x0, y0, x1, y1 int) {
w, _ := p.image.Size()
return 0, i, w, i + 1
}
func update(screen *ebiten.Image) error {
if ebiten.IsRunningSlowly() {
return nil
}
op := &ebiten.DrawImageOptions{
ImageParts: &parts{gophersImage},
}
op := &ebiten.DrawImageOptions{}
w, h := gophersImage.Size()
maxWidth := float64(w) + float64(h)*0.75
op.GeoM.Translate(-maxWidth/2, -float64(h)/2)
op.GeoM.Translate(screenWidth/2, screenHeight/2)
screen.DrawImage(gophersImage, op)
for i := 0; i < h; i++ {
op.GeoM.Reset()
width := w + i*3/4
x := ((h - i) * 3 / 4) / 2
op.GeoM.Scale(float64(width)/float64(w), 1)
op.GeoM.Translate(float64(x), float64(i))
maxWidth := float64(w) + float64(h)*3/4
op.GeoM.Translate(-maxWidth/2, -float64(h)/2)
op.GeoM.Translate(screenWidth/2, screenHeight/2)
r := image.Rect(0, i, w, i+1)
op.SourceRect = &r
screen.DrawImage(gophersImage, op)
}
return nil
}

View File

@ -16,7 +16,7 @@ window.addEventListener('load', function() {
var s = document.createElement('script');
var src = 'piano.js';
if (isProduction()) {
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
}
s.src = src;
s.onload = function() {

View File

@ -16,7 +16,7 @@ window.addEventListener('load', function() {
var s = document.createElement('script');
var src = 'rotate.js';
if (isProduction()) {
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
}
s.src = src;
s.onload = function() {

View File

@ -16,7 +16,7 @@ window.addEventListener('load', function() {
var s = document.createElement('script');
var src = 'sprites.js';
if (isProduction()) {
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
}
s.src = src;
s.onload = function() {

View File

@ -33,6 +33,7 @@ import (
"fmt"
_ "image/png"
"log"
"math"
"math/rand"
"github.com/hajimehoshi/ebiten"
@ -42,12 +43,11 @@ import (
const (
screenWidth = 320
screenHeight = 240
maxAngle = 256
)
var (
ebitenImage *ebiten.Image
ebitenImageWidth = 0
ebitenImageHeight = 0
ebitenImage *ebiten.Image
)
type Sprite struct {
@ -57,6 +57,7 @@ type Sprite struct {
y int
vx int
vy int
angle int
}
func (s *Sprite) Update() {
@ -76,6 +77,8 @@ func (s *Sprite) Update() {
s.y = 2*(screenHeight-s.imageHeight) - s.y
s.vy = -s.vy
}
s.angle++
s.angle %= maxAngle
}
type Sprites struct {
@ -89,31 +92,15 @@ func (s *Sprites) Update() {
}
}
func (s *Sprites) Len() int {
return s.num
}
func (s *Sprites) Dst(i int) (x0, y0, x1, y1 int) {
if s.num <= i {
return 0, 0, 0, 0
}
ss := s.sprites[i]
return ss.x, ss.y, ss.x + ebitenImageWidth, ss.y + ebitenImageHeight
}
func (s *Sprites) Src(i int) (x0, y0, x1, y1 int) {
if s.num <= i {
return 0, 0, 0, 0
}
return 0, 0, ebitenImageWidth, ebitenImageHeight
}
const (
MinSprites = 0
MaxSprites = 50000
)
var sprites = &Sprites{make([]*Sprite, MaxSprites), 500}
var (
sprites = &Sprites{make([]*Sprite, MaxSprites), 500}
op = &ebiten.DrawImageOptions{}
)
func update(screen *ebiten.Image) error {
if ebiten.IsKeyPressed(ebiten.KeyLeft) {
@ -133,29 +120,41 @@ func update(screen *ebiten.Image) error {
if ebiten.IsRunningSlowly() {
return nil
}
op := &ebiten.DrawImageOptions{
ImageParts: sprites,
w, h := ebitenImage.Size()
for i := 0; i < sprites.num; i++ {
s := sprites.sprites[i]
op.GeoM.Reset()
op.GeoM.Translate(-float64(w)/2, -float64(h)/2)
op.GeoM.Rotate(2 * math.Pi * float64(s.angle) / maxAngle)
op.GeoM.Translate(float64(w)/2, float64(h)/2)
op.GeoM.Translate(float64(s.x), float64(s.y))
screen.DrawImage(ebitenImage, op)
}
op.ColorM.Scale(1.0, 1.0, 1.0, 0.5)
screen.DrawImage(ebitenImage, op)
msg := fmt.Sprintf(`FPS: %0.2f
Num of sprites: %d
Press <- or -> to change the number of sprites`, ebiten.CurrentFPS(), sprites.Len())
ebitenutil.DebugPrint(screen, msg)
Press <- or -> to change the number of sprites`, ebiten.CurrentFPS(), sprites.num)
if err := ebitenutil.DebugPrint(screen, msg); err != nil {
return err
}
return nil
}
func main() {
var err error
ebitenImage, _, err = ebitenutil.NewImageFromFile("_resources/images/ebiten.png", ebiten.FilterNearest)
img, _, err := ebitenutil.NewImageFromFile("_resources/images/ebiten.png", ebiten.FilterNearest)
if err != nil {
log.Fatal(err)
}
ebitenImageWidth, ebitenImageHeight = ebitenImage.Size()
w, h := img.Size()
ebitenImage, _ = ebiten.NewImage(w, h, ebiten.FilterNearest)
op := &ebiten.DrawImageOptions{}
op.ColorM.Scale(1, 1, 1, 0.5)
ebitenImage.DrawImage(img, op)
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
a := rand.Intn(maxAngle)
sprites.sprites[i] = &Sprite{
imageWidth: w,
imageHeight: h,
@ -163,6 +162,7 @@ func main() {
y: y,
vx: vx,
vy: vy,
angle: a,
}
}
if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Sprites (Ebiten Demo)"); err != nil {