diff options
Diffstat (limited to 'krita/plugins/viewplugins/scripting/samples/ruby')
13 files changed, 454 insertions, 0 deletions
diff --git a/krita/plugins/viewplugins/scripting/samples/ruby/Makefile.am b/krita/plugins/viewplugins/scripting/samples/ruby/Makefile.am new file mode 100644 index 00000000..2aa79416 --- /dev/null +++ b/krita/plugins/viewplugins/scripting/samples/ruby/Makefile.am @@ -0,0 +1,18 @@ +scriptsinvertdir = $(kde_datadir)/krita/scripts/invertruby +scriptsinvert_SCRIPTS = invert.rb invertruby.rc + +scriptschangecsdir = $(kde_datadir)/krita/scripts/changecs +scriptschangecs_SCRIPTS = changecs.rb changecs.rc + +scriptsrandompaintdir = $(kde_datadir)/krita/scripts/randompaint +scriptsrandompaint_SCRIPTS = randompaint.rb randompaint.rc + +scriptsfilterstestdir = $(kde_datadir)/krita/scripts/filterstest +scriptsfilterstest_SCRIPTS = filterstest.rb filterstest.rc + +scriptstorturefiltersdir = $(kde_datadir)/krita/scripts/torturefilters +scriptstorturefilters_SCRIPTS = torture-filters.rb torture-filters.rc + +scriptstorturepaintingdir = $(kde_datadir)/krita/scripts/torturepainting +scriptstorturepainting_SCRIPTS = torture-painting.rb torture-painting.rc + diff --git a/krita/plugins/viewplugins/scripting/samples/ruby/changecs.rb b/krita/plugins/viewplugins/scripting/samples/ruby/changecs.rb new file mode 100644 index 00000000..f5d99a3f --- /dev/null +++ b/krita/plugins/viewplugins/scripting/samples/ruby/changecs.rb @@ -0,0 +1,5 @@ +require "krosskritacore" + +doc = Krosskritacore::get("KritaDocument") +image = doc.getImage() +image.convertToColorspace("LABA") diff --git a/krita/plugins/viewplugins/scripting/samples/ruby/changecs.rc b/krita/plugins/viewplugins/scripting/samples/ruby/changecs.rc new file mode 100644 index 00000000..4121693d --- /dev/null +++ b/krita/plugins/viewplugins/scripting/samples/ruby/changecs.rc @@ -0,0 +1,9 @@ +<KrossScripting> + <ScriptAction + name="ChangeColorspaceRuby" + text="Change Colorspace" + description="Demonstrate how to change the colorspace in a script" + icon="" + interpreter="ruby" + file="changecs.rb" /> +</KrossScripting> diff --git a/krita/plugins/viewplugins/scripting/samples/ruby/filterstest.rb b/krita/plugins/viewplugins/scripting/samples/ruby/filterstest.rb new file mode 100644 index 00000000..20d42dbf --- /dev/null +++ b/krita/plugins/viewplugins/scripting/samples/ruby/filterstest.rb @@ -0,0 +1,31 @@ +# This file is part of Krita +# +# Copyright (c) 2005-2006 Cyrille Berger <[email protected]> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +require "krosskritacore" + +doc = Krosskritacore::get("KritaDocument") + +image = doc.getImage() +layer = image.getActivePaintLayer() +width = layer.getWidth() +height = layer.getHeight() + +filter = Krosskritacore::getFilter("invert") + +filter.process(layer ) +filter.process(layer, 10, 10, 20, 20 ) diff --git a/krita/plugins/viewplugins/scripting/samples/ruby/filterstest.rc b/krita/plugins/viewplugins/scripting/samples/ruby/filterstest.rc new file mode 100644 index 00000000..2f8dfb98 --- /dev/null +++ b/krita/plugins/viewplugins/scripting/samples/ruby/filterstest.rc @@ -0,0 +1,9 @@ +<KrossScripting> + <ScriptAction + name="FiltersTestRuby" + text="Filters Test" + description="Test of filters in scripting (ruby)" + icon="" + interpreter="ruby" + file="filterstest.rb" /> +</KrossScripting> diff --git a/krita/plugins/viewplugins/scripting/samples/ruby/invert.rb b/krita/plugins/viewplugins/scripting/samples/ruby/invert.rb new file mode 100644 index 00000000..0a055028 --- /dev/null +++ b/krita/plugins/viewplugins/scripting/samples/ruby/invert.rb @@ -0,0 +1,45 @@ +# This file is part of Krita +# +# Copyright (c) 2005-2006 Cyrille Berger <[email protected]> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +require "krosskritacore" + +doc = Krosskritacore::get("KritaDocument") +script = Krosskritacore::get("KritaScript") +image = doc.getImage() +layer = image.getActivePaintLayer() + +if(layer.colorSpaceId() != "RGBA" ) + raise("This script works only for 8bit RGBA layers") +end + +width = layer.getWidth() +height = layer.getHeight() +script.setProgressTotalSteps(width * height) +layer.beginPainting("invert") +it = layer.createRectIterator( 0, 0, width, height ) +while (it.isDone() == 0) + p = it.getRGBA() + p[0] = 255 - p[0] + p[1] = 255 - p[1] + p[2] = 255 - p[2] + it.setRGBA(p) + script.incProgress() + it.next() +end + +layer.endPainting() diff --git a/krita/plugins/viewplugins/scripting/samples/ruby/invertruby.rc b/krita/plugins/viewplugins/scripting/samples/ruby/invertruby.rc new file mode 100644 index 00000000..9cc7bd6a --- /dev/null +++ b/krita/plugins/viewplugins/scripting/samples/ruby/invertruby.rc @@ -0,0 +1,9 @@ +<KrossScripting> + <ScriptAction + name="InvertRuby" + text="Invert (ruby)" + description="Invert the pixel of an image (ruby)" + icon="" + interpreter="ruby" + file="invert.rb" /> +</KrossScripting> 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 00000000..9e2f504f --- /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() diff --git a/krita/plugins/viewplugins/scripting/samples/ruby/randompaint.rc b/krita/plugins/viewplugins/scripting/samples/ruby/randompaint.rc new file mode 100644 index 00000000..3697f700 --- /dev/null +++ b/krita/plugins/viewplugins/scripting/samples/ruby/randompaint.rc @@ -0,0 +1,9 @@ +<KrossScripting> + <ScriptAction + name="RandomPaintRuby" + text="Random Paint" + description="Demonstrate how to use the Painter script API and paint random shape on screen" + icon="" + interpreter="ruby" + file="randompaint.rb" /> +</KrossScripting> diff --git a/krita/plugins/viewplugins/scripting/samples/ruby/torture-filters.rb b/krita/plugins/viewplugins/scripting/samples/ruby/torture-filters.rb new file mode 100644 index 00000000..58cddcd6 --- /dev/null +++ b/krita/plugins/viewplugins/scripting/samples/ruby/torture-filters.rb @@ -0,0 +1,70 @@ +# This file is part of Krita +# +# Copyright (c) 2006 Cyrille Berger <[email protected]> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +require "krosskritacore" + +doc = Krosskritacore::get("KritaDocument") + +image = doc.getImage() +layer = image.getActivePaintLayer() + +def testFilter(layer, filterid) + print " applying filter ", filterid, "\n" + begin + filter = Krosskritacore::getFilter(filterid) + filter.process(layer) + rescue + print " WARNING: this filter is incompatible with this colorspace\n" + end +end + + +def testColorspace(layer, colorspaceid) + print "Testing for ", colorspaceid, "\n" + if (layer.colorSpaceId() != colorspaceid) + layer.convertToColorspace(colorspaceid) + end + testFilter(layer, "invert") + testFilter(layer, "bumpmap") + testFilter(layer, "cimg") + testFilter(layer, "desaturate") + testFilter(layer, "autocontrast") + testFilter(layer, "brightnesscontrast") + testFilter(layer, "gaussian blur") + testFilter(layer, "cubism") + testFilter(layer, "emboss") + testFilter(layer, "simplenoisereducer") + testFilter(layer, "waveletnoisereducer") + testFilter(layer, "oilpaint") + testFilter(layer, "pixelize") + testFilter(layer, "raindrops") + testFilter(layer, "roundcorners") + testFilter(layer, "smalltiles") + testFilter(layer, "sobel") +end + +testColorspace(layer, "RGBA") +testColorspace(layer, "RGBA16") +testColorspace(layer, "RGBAF16HALF") +testColorspace(layer, "RGBAF32") +testColorspace(layer, "CMYK") +testColorspace(layer, "CMYKA16") +testColorspace(layer, "CMYK") +testColorspace(layer, "CMYKA16") +testColorspace(layer, "LABA") +testColorspace(layer, "LMSAF32") diff --git a/krita/plugins/viewplugins/scripting/samples/ruby/torture-filters.rc b/krita/plugins/viewplugins/scripting/samples/ruby/torture-filters.rc new file mode 100644 index 00000000..c56c2818 --- /dev/null +++ b/krita/plugins/viewplugins/scripting/samples/ruby/torture-filters.rc @@ -0,0 +1,9 @@ +<KrossScripting> + <ScriptAction + name="TortureFiltersRuby" + text="Torture Krita with Filters" + description="Test all filters with all colorspaces (ruby)" + icon="" + interpreter="ruby" + file="torture-filters.rb" /> +</KrossScripting> diff --git a/krita/plugins/viewplugins/scripting/samples/ruby/torture-painting.rb b/krita/plugins/viewplugins/scripting/samples/ruby/torture-painting.rb new file mode 100644 index 00000000..67042de2 --- /dev/null +++ b/krita/plugins/viewplugins/scripting/samples/ruby/torture-painting.rb @@ -0,0 +1,133 @@ +# This file is part of Krita +# +# Copyright (c) 2006 Cyrille Berger <[email protected]> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +require "krosskritacore" + +class TorturePainting + + def initialize() + + doc = Krosskritacore::get("KritaDocument") + @script = Krosskritacore::get("KritaScript") + + @image = doc.getImage() + @width = @image.getWidth() + @height = @image.getHeight() + + @script.setProgressTotalSteps(30 * 10) + + testColorspace("RGBA") + testColorspace("RGBA16") + testColorspace("RGBAF16HALF") + testColorspace("RGBAF32") + testColorspace("CMYK") + testColorspace("CMYKA16") + testColorspace("CMYK") + testColorspace("CMYKA16") + testColorspace("LABA") + testColorspace("LMSAF32") + + + end + + def randomizeStyle(painter) + painter.setFillStyle(4 *rand) + painter.setStrokeStyle(2 *rand) + end + + + def testColorspace(cs) + print "Torturing for ", cs, "\n" + layer = @image.createPaintLayer("torture", 255 * rand, "RGBA" ); + torture(layer) + end + + + def torture(layer) + layer.beginPainting("torture painting") + + painter = layer.createPainter() + + # create painting color + blackcolor = Krosskritacore::newRGBColor(0,0,0) + + # set painting color + painter.setPaintColor( blackcolor ) + + # get the pattern + pattern = Krosskritacore::getPattern("Bricks") + + # set the pattern + painter.setPattern(pattern) + + # define the paint operation + painter.setPaintOp("paintbrush") + + # randomly rect or circle paint + for i in 1..30 + # 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() + end + +end + +TorturePainting.new()
\ No newline at end of file diff --git a/krita/plugins/viewplugins/scripting/samples/ruby/torture-painting.rc b/krita/plugins/viewplugins/scripting/samples/ruby/torture-painting.rc new file mode 100644 index 00000000..6b54fa9d --- /dev/null +++ b/krita/plugins/viewplugins/scripting/samples/ruby/torture-painting.rc @@ -0,0 +1,9 @@ +<KrossScripting> + <ScriptAction + name="TorturePainting" + text="Torture Krita with Painting" + description="Paint on an image and create multiple layers" + icon="" + interpreter="ruby" + file="torture-painting.rb" /> +</KrossScripting> |