2021-06-01 18:50:49 +00:00
|
|
|
import pixie, wNim/wApp, wNim/wFrame, wNim/wImage, wNim/wPaintDC
|
2021-05-27 02:15:24 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
w = 256
|
|
|
|
h = 256
|
|
|
|
|
|
|
|
var
|
|
|
|
screen = newImage(w, h)
|
|
|
|
ctx = newContext(screen)
|
|
|
|
frameCount = 0
|
|
|
|
image = Image(w, h)
|
|
|
|
app = App()
|
2021-10-27 21:44:22 +00:00
|
|
|
frame = Frame(title = "wNim/Pixie")
|
2021-05-27 02:15:24 +00:00
|
|
|
|
|
|
|
proc draw() =
|
|
|
|
# draw shiny sphere on gradient background
|
2021-08-06 23:08:21 +00:00
|
|
|
let linerGradient = newPaint(pkGradientLinear)
|
2021-05-27 02:15:24 +00:00
|
|
|
linerGradient.gradientHandlePositions.add(vec2(0, 0))
|
|
|
|
linerGradient.gradientHandlePositions.add(vec2(0, 256))
|
|
|
|
linerGradient.gradientStops.add(
|
2021-10-04 22:08:36 +00:00
|
|
|
ColorStop(color: color(0, 0, 0, 1), position: 0))
|
2021-05-27 02:15:24 +00:00
|
|
|
linerGradient.gradientStops.add(
|
2021-10-04 22:08:36 +00:00
|
|
|
ColorStop(color: color(1, 1, 1, 1), position: 1))
|
2021-05-27 02:15:24 +00:00
|
|
|
ctx.fillStyle = linerGradient
|
|
|
|
ctx.fillRect(0, 0, 256, 256)
|
|
|
|
|
2021-08-06 23:08:21 +00:00
|
|
|
let radialGradient = newPaint(pkGradientRadial)
|
2021-05-27 02:15:24 +00:00
|
|
|
radialGradient.gradientHandlePositions.add(vec2(128, 128))
|
|
|
|
radialGradient.gradientHandlePositions.add(vec2(256, 128))
|
|
|
|
radialGradient.gradientHandlePositions.add(vec2(128, 256))
|
|
|
|
radialGradient.gradientStops.add(
|
2021-10-04 22:08:36 +00:00
|
|
|
ColorStop(color: color(1, 1, 1, 1), position: 0))
|
2021-05-27 02:15:24 +00:00
|
|
|
radialGradient.gradientStops.add(
|
2021-10-04 22:08:36 +00:00
|
|
|
ColorStop(color: color(0, 0, 0, 1), position: 1))
|
2021-05-27 02:15:24 +00:00
|
|
|
ctx.fillStyle = radialGradient
|
2021-10-04 22:08:36 +00:00
|
|
|
ctx.fillCircle(circle(
|
|
|
|
vec2(128.0, 128.0 + sin(float32(frameCount)/10.0) * 20),
|
|
|
|
76.8
|
|
|
|
))
|
2021-05-27 02:15:24 +00:00
|
|
|
inc frameCount
|
|
|
|
|
|
|
|
proc render() =
|
|
|
|
|
|
|
|
proc GdipCreateBitmapFromScan0(width: cint, height: cint, stride: cint,
|
|
|
|
format: cint, scan0: pointer, bitmap: pointer): cint
|
|
|
|
{.stdcall, discardable, dynlib: "gdiplus", importc.}
|
|
|
|
|
|
|
|
proc GdipDisposeImage(image: pointer): cint
|
|
|
|
{.stdcall, discardable, dynlib: "gdiplus", importc.}
|
|
|
|
|
|
|
|
const PixelFormat32bppARGB = 2498570
|
|
|
|
|
|
|
|
GdipDisposeImage(image.mGdipBmp)
|
|
|
|
|
|
|
|
GdipCreateBitmapFromScan0(cint w, cint h, cint w * 4,
|
|
|
|
PixelFormat32bppARGB, ctx.image.data[0].addr, addr image.mGdipBmp)
|
|
|
|
|
|
|
|
frame.clientSize = (w, h)
|
|
|
|
|
|
|
|
frame.startTimer(0.01)
|
|
|
|
|
|
|
|
frame.wEvent_Timer do ():
|
|
|
|
draw()
|
|
|
|
render()
|
|
|
|
frame.refresh(false)
|
|
|
|
|
|
|
|
frame.wEvent_Paint do ():
|
|
|
|
var dc = PaintDC(frame)
|
|
|
|
dc.drawImage(image)
|
|
|
|
|
|
|
|
frame.show()
|
|
|
|
app.mainLoop()
|