reed | 09445a4 | 2014-10-10 20:31:24 -0700 | [diff] [blame] | 1 | |
| 2 | local r = { left = 10, top = 10, right = 100, bottom = 80 } |
| 3 | local x = 0; |
| 4 | |
| 5 | local paint = Sk.newPaint(); |
| 6 | paint:setAntiAlias(true); |
| 7 | |
| 8 | local image -- = Sk.loadImage('/skia/sailboat.jpg'); |
| 9 | function setImageFilename(filename) |
| 10 | image = Sk.loadImage(filename) |
| 11 | end |
| 12 | |
| 13 | |
| 14 | local color = {a = 1, r = 1, g = 0, b = 0}; |
| 15 | |
| 16 | function rnd(range) |
| 17 | return math.random() * range; |
| 18 | end |
| 19 | |
| 20 | rndX = function () return rnd(640) end |
| 21 | rndY = function () return rnd(480) end |
| 22 | |
| 23 | function draw_rand_path(canvas); |
| 24 | if not path_paint then |
| 25 | path_paint = Sk.newPaint(); |
| 26 | path_paint:setAntiAlias(true); |
| 27 | end |
| 28 | path_paint:setColor({a = 1, r = math.random(), g = math.random(), b = math.random() }); |
| 29 | |
| 30 | local path = Sk.newPath(); |
| 31 | path:moveTo(rndX(), rndY()); |
| 32 | for i = 0, 50 do |
| 33 | path:quadTo(rndX(), rndY(), rndX(), rndY()); |
| 34 | end |
| 35 | canvas:drawPath(path, path_paint); |
| 36 | |
| 37 | paint:setColor{a=1,r=0,g=0,b=1}; |
| 38 | local align = { 'left', 'center', 'right' }; |
| 39 | paint:setTextSize(30); |
| 40 | for k, v in next, align do |
| 41 | paint:setTextAlign(v); |
| 42 | canvas:drawText('Hamburgefons', 320, 200 + 30*k, paint); |
| 43 | end |
| 44 | end |
| 45 | |
| 46 | function onStartup() |
| 47 | local paint = Sk.newPaint(); |
| 48 | paint:setColor{a=1, r=1, g=0, b=0}; |
| 49 | if false then |
Ben Wagner | c6c10b4 | 2017-08-07 09:56:21 -0400 | [diff] [blame] | 50 | local doc = Sk.newDocumentPDF('out/test.pdf'); |
reed | 09445a4 | 2014-10-10 20:31:24 -0700 | [diff] [blame] | 51 | local canvas = doc:beginPage(72*8.5, 72*11); |
| 52 | canvas:drawText('Hello Lua', 300, 300, paint); |
| 53 | doc:close(); |
| 54 | doc = nil; |
| 55 | end |
| 56 | end |
| 57 | |
| 58 | function onDrawContent(canvas) |
| 59 | draw_rand_path(canvas); |
| 60 | color.g = x / 100; |
| 61 | paint:setColor(color) |
| 62 | canvas:translate(x, 0); |
| 63 | canvas:drawOval(r, paint) |
| 64 | x = x + 1; |
| 65 | local r2 = {} |
| 66 | r2.left = x; |
| 67 | r2.top = r.bottom + 50; |
| 68 | r2.right = r2.left + image:width() * 1; |
| 69 | r2.bottom = r2.top + image:height() * 1; |
| 70 | canvas:drawImageRect(image, nil, r2, 0.75); |
| 71 | if x > 200 then x = 0 end; |
reed | 18ea777 | 2014-10-11 11:28:07 -0700 | [diff] [blame] | 72 | |
| 73 | return true -- so we can animate |
reed | 09445a4 | 2014-10-10 20:31:24 -0700 | [diff] [blame] | 74 | end |
| 75 | |
| 76 | onStartup() |