mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 11:18:54 +01:00
doc: Add server.go
This commit is contained in:
parent
c54b5c4b06
commit
b6f6cfa866
7
_docs/README.md
Normal file
7
_docs/README.md
Normal file
@ -0,0 +1,7 @@
|
||||
# How to generate the doc
|
||||
|
||||
`go run gen.go`
|
||||
|
||||
# How to run HTTP server
|
||||
|
||||
`go run server.go`
|
@ -61,7 +61,7 @@ func update(screen *ebiten.Image) error {
|
||||
w, h := gophersImage.Size()
|
||||
op := &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))
|
||||
op.ColorM.RotateHue(float64(count%360) * 2 * math.Pi / 360)
|
||||
if err := screen.DrawImage(gophersImage, op); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ func update(screen *ebiten.Image) error {
|
||||
op.GeoM.Translate(float64(mx), float64(my))
|
||||
op.ColorM.Scale(1.0, 0.25, 0.25, 1.0)
|
||||
theta := 2.0 * math.Pi * float64(count%60) / 60.0
|
||||
op.ColorM.Concat(ebiten.RotateHue(theta))
|
||||
op.ColorM.RotateHue(theta)
|
||||
if err := canvasImage.DrawImage(brushImage, op); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -152,11 +152,18 @@ func updateInput() {
|
||||
}
|
||||
}
|
||||
|
||||
var pianoImage *ebiten.Image
|
||||
var (
|
||||
imagePiano *ebiten.Image
|
||||
)
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
pianoImage, err = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterNearest)
|
||||
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)
|
||||
}
|
||||
@ -166,8 +173,13 @@ func init() {
|
||||
for i, k := range whiteKeys {
|
||||
x := i*width + 36
|
||||
height := 112
|
||||
pianoImage.DrawFilledRect(x, y, width-1, height, color.White)
|
||||
common.ArcadeFont.DrawText(pianoImage, k, x+8, y+height-16, 1, color.Black)
|
||||
op := &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+8, y+height-16, 1, color.Black)
|
||||
}
|
||||
|
||||
blackKeys := []string{"Q", "W", "", "R", "T", "", "U", "I", "O"}
|
||||
@ -177,8 +189,13 @@ func init() {
|
||||
}
|
||||
x := i*width + 24
|
||||
height := 64
|
||||
pianoImage.DrawFilledRect(x, y, width-1, height, color.Black)
|
||||
common.ArcadeFont.DrawText(pianoImage, k, x+8, y+height-16, 1, color.White)
|
||||
op := &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+8, y+height-16, 1, color.White)
|
||||
}
|
||||
}
|
||||
|
||||
@ -192,7 +209,7 @@ func update(screen *ebiten.Image) error {
|
||||
}
|
||||
|
||||
screen.Fill(color.RGBA{0x80, 0x80, 0xc0, 0xff})
|
||||
screen.DrawImage(pianoImage, nil)
|
||||
screen.DrawImage(imagePiano, nil)
|
||||
|
||||
ebitenutil.DebugPrint(screen, fmt.Sprintf("FPS: %0.2f", ebiten.CurrentFPS()))
|
||||
return nil
|
||||
|
35
_docs/server.go
Normal file
35
_docs/server.go
Normal file
@ -0,0 +1,35 @@
|
||||
// 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.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
var port = flag.Int("port", 8000, "port number")
|
||||
|
||||
func init() {
|
||||
flag.Parse()
|
||||
}
|
||||
|
||||
func main() {
|
||||
http.Handle("/", http.FileServer(http.Dir("public")))
|
||||
fmt.Printf("http://localhost:%d/\n", *port)
|
||||
log.Fatal(http.ListenAndServe(":"+strconv.Itoa(*port), nil))
|
||||
}
|
Loading…
Reference in New Issue
Block a user