1 2local r = { left = 10, top = 10, right = 100, bottom = 80 } 3local x = 0; 4 5local paint = Sk.newPaint(); 6paint:setAntiAlias(true); 7 8local image -- = Sk.loadImage('/skia/sailboat.jpg'); 9function setImageFilename(filename) 10 image = Sk.loadImage(filename) 11end 12 13 14local color = {a = 1, r = 1, g = 0, b = 0}; 15 16function rnd(range) 17 return math.random() * range; 18end 19 20rndX = function () return rnd(640) end 21rndY = function () return rnd(480) end 22 23function 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 44end 45 46function onStartup() 47 local paint = Sk.newPaint(); 48 paint:setColor{a=1, r=1, g=0, b=0}; 49 if false then 50 local doc = Sk.newDocumentPDF('out/test.pdf'); 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 56end 57 58function 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; 72 73 return true -- so we can animate 74end 75 76onStartup() 77