summaryrefslogtreecommitdiffstats
path: root/chalk/plugins/viewplugins/scripting/samples/ruby/randompaint.rb
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2011-06-26 00:41:16 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2011-06-26 00:41:16 +0000
commit698569f8428ca088f764d704034a1330517b98c0 (patch)
treebf45be6946ebbbee9cce5a5bcf838f4c952d87e6 /chalk/plugins/viewplugins/scripting/samples/ruby/randompaint.rb
parent2785103a6bd4de55bd26d79e34d0fdd4b329a73a (diff)
downloadkoffice-698569f8428ca088f764d704034a1330517b98c0.tar.gz
koffice-698569f8428ca088f764d704034a1330517b98c0.zip
Finish rebranding of Krita as Chalk
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1238363 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'chalk/plugins/viewplugins/scripting/samples/ruby/randompaint.rb')
-rw-r--r--chalk/plugins/viewplugins/scripting/samples/ruby/randompaint.rb98
1 files changed, 98 insertions, 0 deletions
diff --git a/chalk/plugins/viewplugins/scripting/samples/ruby/randompaint.rb b/chalk/plugins/viewplugins/scripting/samples/ruby/randompaint.rb
new file mode 100644
index 00000000..1ec25dcd
--- /dev/null
+++ b/chalk/plugins/viewplugins/scripting/samples/ruby/randompaint.rb
@@ -0,0 +1,98 @@
+def randomizeStyle(painter)
+ painter.setFillStyle(4 *rand)
+ painter.setStrokeStyle(2 *rand)
+end
+
+require "krosschalkcore"
+
+doc = Krosschalkcore::get("ChalkDocument")
+script = Krosschalkcore::get("ChalkScript")
+
+image = doc.getImage()
+layer = image.getActivePaintLayer()
+width = layer.getWidth()
+height = layer.getHeight()
+
+script.setProgressTotalSteps(110)
+layer.beginPainting("random paint")
+
+painter = layer.createPainter()
+
+# create painting color
+blackcolor = Krosschalkcore::newRGBColor(0,0,0)
+
+# set painting color
+painter.setPaintColor( blackcolor )
+
+# get the brush
+brush = Krosschalkcore::getBrush("Circle (05)")
+
+# define the brush
+painter.setBrush(brush)
+
+# get the pattern
+pattern = Krosschalkcore::getPattern("Bricks")
+
+# set the pattern
+painter.setPattern(pattern)
+
+# define the paint operation
+painter.setPaintOp("paintbrush")
+
+# randomly paint
+for i in 1..10
+ # set painting color
+ painter.setPaintColor( Krosschalkcore::newRGBColor(rand*255,rand*255,rand*255) )
+ painter.paintAt(rand * width , rand * height,1.1)
+ script.incProgress()
+end
+
+# randomly rect or circle paint
+for i in 1..100
+ # set painting color
+ painter.setPaintColor( Krosschalkcore::newRGBColor(rand*255,rand*255,rand*255) )
+ painter.setBackgroundColor( Krosschalkcore::newRGBColor(rand*255,rand*255,rand*255) )
+ painter.setOpacity( rand*255 )
+# set the brush
+ if(rand < 0.5)
+ painter.setBrush( Krosschalkcore::newRectBrush(rand*20,rand*20,rand*10,rand*10) )
+ else
+ painter.setBrush( Krosschalkcore::newCircleBrush(rand*20,rand*20,rand*10,rand*10) )
+ end
+ # paint a point
+ tqshape = rand * 7
+ painter.setStrokeStyle(1)
+ if( tqshape < 1 )
+ painter.paintAt(rand * width , rand * height,1.1)
+ elsif(tqshape < 2 )
+ xs = Array.new
+ ys = Array.new
+ for i in 0..6
+ xs[i] = rand*width
+ ys[i] = rand*height
+ end
+ painter.paintPolyline(xs,ys)
+ elsif(tqshape < 3)
+ painter.paintLine(rand * width, rand * height, 1.1, rand * width, rand * height,1.1)
+ elsif(tqshape < 4)
+ painter.paintBezierCurve(rand * width, rand * height, 1.1, rand * width, rand * height, rand * width , rand * height, rand * width, rand * height, 1.1)
+ elsif(tqshape < 5)
+ randomizeStyle(painter)
+ painter.paintEllipse(rand * width, rand * height, rand * width, rand * height, 1.1)
+ elsif(tqshape < 6)
+ xs = Array.new
+ ys = Array.new
+ for i in 0..6
+ xs[i] = rand*width
+ ys[i] = rand*height
+ end
+ randomizeStyle(painter)
+ painter.paintPolygon(xs, ys)
+ elsif(tqshape < 7)
+ randomizeStyle(painter)
+ painter.paintRect(rand * width, rand * height, rand * width, rand * height, 1.1)
+ end
+ script.incProgress()
+end
+
+layer.endPainting()