-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from tomoish/main3
mergeAll
- Loading branch information
Showing
28 changed files
with
405 additions
and
67 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package funcs | ||
|
||
import ( | ||
"fmt" | ||
"image/color" | ||
"log" | ||
|
||
"github.com/fogleman/gg" | ||
) | ||
|
||
func DrawBackground(level, kind string) { | ||
const ( | ||
// Width = 1200 | ||
// Height = 1800 | ||
Width = 800 | ||
Height = 1200 | ||
BorderSize = 10 // ボーダーのサイズ | ||
) | ||
|
||
// 新しい画像コンテキストを作成 | ||
dc := gg.NewContext(Width, Height) | ||
|
||
// 画像の背景を白に設定 | ||
dc.SetRGB(0.03, 0.03, 0.03) | ||
dc.Clear() | ||
|
||
// テキストの描画設定 | ||
// フォントの設定 | ||
|
||
// 関数呼び出しとエラーチェック | ||
if err := dc.LoadFontFace("Roboto-Medium.ttf", 28); err != nil { | ||
fmt.Println("フォントのロードに失敗しました:", err) | ||
} | ||
dc.SetColor(color.White) | ||
|
||
// テキストの座標を個別に指定して描画 | ||
text1 := "Hi, there! I'm Kota" | ||
x1, y1 := (25*Width)/100, (15*Height)/100 // テキスト1の座標 | ||
dc.DrawStringAnchored(text1, float64(x1), float64(y1), 0.5, 0.5) | ||
|
||
text2 := level | ||
x2, y2 := (18*Width)/100, (25*Height)/100 // テキスト2の座標(テキストの中央に持つ) | ||
dc.DrawStringAnchored(text2, float64(x2), float64(y2), 0.5, 0.5) | ||
|
||
if err := dc.LoadFontFace("NotoSansJP-ExtraLight.ttf", 50); err != nil { | ||
fmt.Println("フォントのロードに失敗しました:", err) | ||
} | ||
text3 := kind | ||
x3, y3 := (33*Width)/100, (25*Height)/100 // テキスト3の座標 | ||
dc.DrawStringAnchored(text3, float64(x3), float64(y3), 0.5, 0.5) | ||
|
||
// ボーダーを描画する新しいコンテキストを作成 | ||
dcBorder := gg.NewContext(Width, Height) | ||
dcBorder.SetRGB(1, 1, 1) // 白いボーダー | ||
dcBorder.Clear() | ||
dcBorder.DrawRectangle(0, 0, float64(Width), float64(Height)) | ||
dcBorder.SetLineWidth(BorderSize) | ||
dcBorder.Stroke() | ||
|
||
// ボーダーの上に背景画像を描画 | ||
dcBorder.DrawImage(dc.Image(), 0, 0) | ||
// 画像をPNG形式で保存 | ||
if err := dc.SavePNG("./images/background.png"); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
log.Println("Image with multiple text has been created and saved.") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.