-
-
Save mirichi/7cc137a7dca8214ab0f06dca8181f6c9 to your computer and use it in GitHub Desktop.
NanoGLサンプル
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
require 'NanoGL' | |
include NanoGL | |
Video.SetSize(640, 480) # ウィンドウサイズ(これがデフォルト値) | |
Video.SetWindowTitle("sample") # ウィンドウタイトル設定 | |
Video.SetClearColor(Video.RGB(100, 100, 100)) # 背景色 | |
t = 0 | |
Video.Draw do | |
Video.Save() | |
x = 100 | |
y = 100 | |
w = 250 | |
h = 250 | |
hue = Math.sin(t * 0.12) | |
cx = x + w*0.5 | |
cy = y + h*0.5 | |
r1 = (w < h ? w : h) * 0.5 - 5.0 | |
r0 = r1 - 20.0 | |
aeps = 0.5 / r1 | |
6.times do |i| | |
a0 = i / 6.0 * Math::PI * 2.0 - aeps | |
a1 = (i + 1.0) / 6.0 * Math::PI * 2.0 + aeps | |
Video.Path do | |
Video.Arc(cx,cy, r0, a0, a1, :WINDING_CW) | |
Video.Arc(cx,cy, r1, a1, a0, :WINDING_CCW) | |
end | |
ax = cx + Math.cos(a0) * (r0+r1)*0.5 | |
ay = cy + Math.sin(a0) * (r0+r1)*0.5 | |
bx = cx + Math.cos(a1) * (r0+r1)*0.5 | |
by = cy + Math.sin(a1) * (r0+r1)*0.5 | |
paint = Video.LinearGradient(ax, ay, bx, by, Video.HSLA(a0/(Math::PI*2),1.0,0.55,255), Video.HSLA(a1/(Math::PI*2),1.0,0.55,255)) | |
Video.FillPaint(paint) | |
Video.Fill() | |
Video.BeginPath() | |
Video.Circle(cx, cy, r0 - 0.5) | |
Video.Circle(cx, cy, r1 + 0.5) | |
Video.StrokeColor(Video.RGBA(0, 0, 0, 64)) | |
Video.StrokeWidth(1.0) | |
Video.Stroke() | |
Video.Save() | |
Video.Translate(cx, cy) | |
Video.Rotate(hue * Math::PI * 2) | |
Video.StrokeWidth(2.0) | |
Video.BeginPath() | |
Video.Rect(r0 - 1 ,-3, r1 - r0 + 2, 6) | |
Video.StrokeColor(Video.RGBA(255, 255, 255, 192)) | |
Video.Stroke() | |
paint = Video.BoxGradient(r0 - 3, -5, r1 - r0 + 6, 10, 2, 4, Video.RGBA(0, 0, 0, 128), Video.RGBA(0, 0, 0, 0)) | |
Video.BeginPath() | |
Video.Rect(r0 - 2 - 10, -4 - 10, r1 - r0 + 4 + 20, 8 + 20) | |
Video.Rect(r0 - 2, -4, r1 - r0 + 4, 8) | |
Video.PathWinding(:SOLIDITY_HOLE) | |
Video.FillPaint(paint) | |
Video.Fill() | |
r = r0 - 6 | |
ax = Math.cos(120.0/180.0 * Math::PI) * r | |
ay = Math.sin(120.0/180.0 * Math::PI) * r | |
bx = Math.cos(-120.0/180.0 * Math::PI) * r | |
by = Math.sin(-120.0/180.0 * Math::PI) * r | |
Video.BeginPath() | |
Video.MoveTo(r, 0) | |
Video.LineTo(ax, ay) | |
Video.LineTo(bx, by) | |
Video.ClosePath() | |
paint = Video.LinearGradient(r, 0, ax,ay, Video.HSLA(hue,1.0,0.5,255), Video.RGBA(255,255,255,255)) | |
Video.FillPaint(paint) | |
Video.Fill() | |
paint = Video.LinearGradient((r + ax) * 0.5, (0 + ay) * 0.5, bx, by, Video.RGBA(0,0,0,0), Video.RGBA(0,0,0,255)) | |
Video.FillPaint(paint) | |
Video.Fill() | |
Video.StrokeColor(Video.RGBA(0,0,0,64)) | |
Video.Stroke() | |
Video.Restore | |
Video.Restore | |
t += 0.001 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment