diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-20 01:29:50 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-20 01:29:50 +0000 |
commit | 8362bf63dea22bbf6736609b0f49c152f975eb63 (patch) | |
tree | 0eea3928e39e50fae91d4e68b21b1e6cbae25604 /krita/plugins/viewplugins/scripting/samples/ruby/randompaint.rb | |
download | koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.tar.gz koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.zip |
Added old abandoned KDE3 version of koffice
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1077364 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'krita/plugins/viewplugins/scripting/samples/ruby/randompaint.rb')
-rw-r--r-- | krita/plugins/viewplugins/scripting/samples/ruby/randompaint.rb | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/krita/plugins/viewplugins/scripting/samples/ruby/randompaint.rb b/krita/plugins/viewplugins/scripting/samples/ruby/randompaint.rb new file mode 100644 index 000000000..9e2f504f0 --- /dev/null +++ b/krita/plugins/viewplugins/scripting/samples/ruby/randompaint.rb @@ -0,0 +1,98 @@ +def randomizeStyle(painter) + painter.setFillStyle(4 *rand) + painter.setStrokeStyle(2 *rand) +end + +require "krosskritacore" + +doc = Krosskritacore::get("KritaDocument") +script = Krosskritacore::get("KritaScript") + +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 = Krosskritacore::newRGBColor(0,0,0) + +# set painting color +painter.setPaintColor( blackcolor ) + +# get the brush +brush = Krosskritacore::getBrush("Circle (05)") + +# define the brush +painter.setBrush(brush) + +# get the pattern +pattern = Krosskritacore::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( Krosskritacore::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( Krosskritacore::newRGBColor(rand*255,rand*255,rand*255) ) + painter.setBackgroundColor( Krosskritacore::newRGBColor(rand*255,rand*255,rand*255) ) + painter.setOpacity( rand*255 ) +# set the brush + if(rand < 0.5) + painter.setBrush( Krosskritacore::newRectBrush(rand*20,rand*20,rand*10,rand*10) ) + else + painter.setBrush( Krosskritacore::newCircleBrush(rand*20,rand*20,rand*10,rand*10) ) + end + # paint a point + shape = rand * 7 + painter.setStrokeStyle(1) + if( shape < 1 ) + painter.paintAt(rand * width , rand * height,1.1) + elsif(shape < 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(shape < 3) + painter.paintLine(rand * width, rand * height, 1.1, rand * width, rand * height,1.1) + elsif(shape < 4) + painter.paintBezierCurve(rand * width, rand * height, 1.1, rand * width, rand * height, rand * width , rand * height, rand * width, rand * height, 1.1) + elsif(shape < 5) + randomizeStyle(painter) + painter.paintEllipse(rand * width, rand * height, rand * width, rand * height, 1.1) + elsif(shape < 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(shape < 7) + randomizeStyle(painter) + painter.paintRect(rand * width, rand * height, rand * width, rand * height, 1.1) + end + script.incProgress() +end + +layer.endPainting() |