summaryrefslogtreecommitdiffstats
path: root/chalk/plugins/viewplugins/scripting/samples/ruby
diff options
context:
space:
mode:
Diffstat (limited to 'chalk/plugins/viewplugins/scripting/samples/ruby')
-rw-r--r--chalk/plugins/viewplugins/scripting/samples/ruby/Makefile.am18
-rw-r--r--chalk/plugins/viewplugins/scripting/samples/ruby/changecs.rb5
-rw-r--r--chalk/plugins/viewplugins/scripting/samples/ruby/changecs.rc9
-rw-r--r--chalk/plugins/viewplugins/scripting/samples/ruby/filterstest.rb31
-rw-r--r--chalk/plugins/viewplugins/scripting/samples/ruby/filterstest.rc9
-rw-r--r--chalk/plugins/viewplugins/scripting/samples/ruby/invert.rb45
-rw-r--r--chalk/plugins/viewplugins/scripting/samples/ruby/invertruby.rc9
-rw-r--r--chalk/plugins/viewplugins/scripting/samples/ruby/randompaint.rb98
-rw-r--r--chalk/plugins/viewplugins/scripting/samples/ruby/randompaint.rc9
-rw-r--r--chalk/plugins/viewplugins/scripting/samples/ruby/torture-filters.rb70
-rw-r--r--chalk/plugins/viewplugins/scripting/samples/ruby/torture-filters.rc9
-rw-r--r--chalk/plugins/viewplugins/scripting/samples/ruby/torture-painting.rb133
-rw-r--r--chalk/plugins/viewplugins/scripting/samples/ruby/torture-painting.rc9
13 files changed, 454 insertions, 0 deletions
diff --git a/chalk/plugins/viewplugins/scripting/samples/ruby/Makefile.am b/chalk/plugins/viewplugins/scripting/samples/ruby/Makefile.am
new file mode 100644
index 00000000..bebd4a71
--- /dev/null
+++ b/chalk/plugins/viewplugins/scripting/samples/ruby/Makefile.am
@@ -0,0 +1,18 @@
+scriptsinvertdir = $(kde_datadir)/chalk/scripts/invertruby
+scriptsinvert_SCRIPTS = invert.rb invertruby.rc
+
+scriptschangecsdir = $(kde_datadir)/chalk/scripts/changecs
+scriptschangecs_SCRIPTS = changecs.rb changecs.rc
+
+scriptsrandompaintdir = $(kde_datadir)/chalk/scripts/randompaint
+scriptsrandompaint_SCRIPTS = randompaint.rb randompaint.rc
+
+scriptsfilterstestdir = $(kde_datadir)/chalk/scripts/filterstest
+scriptsfilterstest_SCRIPTS = filterstest.rb filterstest.rc
+
+scriptstorturefiltersdir = $(kde_datadir)/chalk/scripts/torturefilters
+scriptstorturefilters_SCRIPTS = torture-filters.rb torture-filters.rc
+
+scriptstorturepaintingdir = $(kde_datadir)/chalk/scripts/torturepainting
+scriptstorturepainting_SCRIPTS = torture-painting.rb torture-painting.rc
+
diff --git a/chalk/plugins/viewplugins/scripting/samples/ruby/changecs.rb b/chalk/plugins/viewplugins/scripting/samples/ruby/changecs.rb
new file mode 100644
index 00000000..be7c0d89
--- /dev/null
+++ b/chalk/plugins/viewplugins/scripting/samples/ruby/changecs.rb
@@ -0,0 +1,5 @@
+require "krosschalkcore"
+
+doc = Krosschalkcore::get("ChalkDocument")
+image = doc.getImage()
+image.convertToColorspace("LABA")
diff --git a/chalk/plugins/viewplugins/scripting/samples/ruby/changecs.rc b/chalk/plugins/viewplugins/scripting/samples/ruby/changecs.rc
new file mode 100644
index 00000000..4121693d
--- /dev/null
+++ b/chalk/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/chalk/plugins/viewplugins/scripting/samples/ruby/filterstest.rb b/chalk/plugins/viewplugins/scripting/samples/ruby/filterstest.rb
new file mode 100644
index 00000000..bf76b018
--- /dev/null
+++ b/chalk/plugins/viewplugins/scripting/samples/ruby/filterstest.rb
@@ -0,0 +1,31 @@
+# This file is part of Chalk
+#
+# Copyright (c) 2005-2006 Cyrille Berger <cberger@cberger.net>
+#
+# 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 "krosschalkcore"
+
+doc = Krosschalkcore::get("ChalkDocument")
+
+image = doc.getImage()
+layer = image.getActivePaintLayer()
+width = layer.getWidth()
+height = layer.getHeight()
+
+filter = Krosschalkcore::getFilter("invert")
+
+filter.process(layer )
+filter.process(layer, 10, 10, 20, 20 )
diff --git a/chalk/plugins/viewplugins/scripting/samples/ruby/filterstest.rc b/chalk/plugins/viewplugins/scripting/samples/ruby/filterstest.rc
new file mode 100644
index 00000000..2f8dfb98
--- /dev/null
+++ b/chalk/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/chalk/plugins/viewplugins/scripting/samples/ruby/invert.rb b/chalk/plugins/viewplugins/scripting/samples/ruby/invert.rb
new file mode 100644
index 00000000..d9ad32f7
--- /dev/null
+++ b/chalk/plugins/viewplugins/scripting/samples/ruby/invert.rb
@@ -0,0 +1,45 @@
+# This file is part of Chalk
+#
+# Copyright (c) 2005-2006 Cyrille Berger <cberger@cberger.net>
+#
+# 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 "krosschalkcore"
+
+doc = Krosschalkcore::get("ChalkDocument")
+script = Krosschalkcore::get("ChalkScript")
+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/chalk/plugins/viewplugins/scripting/samples/ruby/invertruby.rc b/chalk/plugins/viewplugins/scripting/samples/ruby/invertruby.rc
new file mode 100644
index 00000000..9cc7bd6a
--- /dev/null
+++ b/chalk/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/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()
diff --git a/chalk/plugins/viewplugins/scripting/samples/ruby/randompaint.rc b/chalk/plugins/viewplugins/scripting/samples/ruby/randompaint.rc
new file mode 100644
index 00000000..3697f700
--- /dev/null
+++ b/chalk/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/chalk/plugins/viewplugins/scripting/samples/ruby/torture-filters.rb b/chalk/plugins/viewplugins/scripting/samples/ruby/torture-filters.rb
new file mode 100644
index 00000000..b92a67e0
--- /dev/null
+++ b/chalk/plugins/viewplugins/scripting/samples/ruby/torture-filters.rb
@@ -0,0 +1,70 @@
+# This file is part of Chalk
+#
+# Copyright (c) 2006 Cyrille Berger <cberger@cberger.net>
+#
+# 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 "krosschalkcore"
+
+doc = Krosschalkcore::get("ChalkDocument")
+
+image = doc.getImage()
+layer = image.getActivePaintLayer()
+
+def testFilter(layer, filterid)
+ print " applying filter ", filterid, "\n"
+ begin
+ filter = Krosschalkcore::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/chalk/plugins/viewplugins/scripting/samples/ruby/torture-filters.rc b/chalk/plugins/viewplugins/scripting/samples/ruby/torture-filters.rc
new file mode 100644
index 00000000..b3abde5b
--- /dev/null
+++ b/chalk/plugins/viewplugins/scripting/samples/ruby/torture-filters.rc
@@ -0,0 +1,9 @@
+<KrossScripting>
+ <ScriptAction
+ name="TortureFiltersRuby"
+ text="Torture Chalk with Filters"
+ description="Test all filters with all colorspaces (ruby)"
+ icon=""
+ interpreter="ruby"
+ file="torture-filters.rb" />
+</KrossScripting>
diff --git a/chalk/plugins/viewplugins/scripting/samples/ruby/torture-painting.rb b/chalk/plugins/viewplugins/scripting/samples/ruby/torture-painting.rb
new file mode 100644
index 00000000..b7c784fc
--- /dev/null
+++ b/chalk/plugins/viewplugins/scripting/samples/ruby/torture-painting.rb
@@ -0,0 +1,133 @@
+# This file is part of Chalk
+#
+# Copyright (c) 2006 Cyrille Berger <cberger@cberger.net>
+#
+# 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 "krosschalkcore"
+
+class TorturePainting
+
+ def initialize()
+
+ doc = Krosschalkcore::get("ChalkDocument")
+ @script = Krosschalkcore::get("ChalkScript")
+
+ @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 = Krosschalkcore::newRGBColor(0,0,0)
+
+ # set painting color
+ painter.setPaintColor( blackcolor )
+
+ # get the pattern
+ pattern = Krosschalkcore::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( 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()
+ end
+
+end
+
+TorturePainting.new() \ No newline at end of file
diff --git a/chalk/plugins/viewplugins/scripting/samples/ruby/torture-painting.rc b/chalk/plugins/viewplugins/scripting/samples/ruby/torture-painting.rc
new file mode 100644
index 00000000..51f2eee4
--- /dev/null
+++ b/chalk/plugins/viewplugins/scripting/samples/ruby/torture-painting.rc
@@ -0,0 +1,9 @@
+<KrossScripting>
+ <ScriptAction
+ name="TorturePainting"
+ text="Torture Chalk with Painting"
+ description="Paint on an image and create multiple layers"
+ icon=""
+ interpreter="ruby"
+ file="torture-painting.rb" />
+</KrossScripting>