japanese_bigbrush.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # ##### BEGIN GPL LICENSE BLOCK #####
  2. #
  3. # This program is free software; you can redistribute it and/or
  4. # modify it under the terms of the GNU General Public License
  5. # as published by the Free Software Foundation; either version 2
  6. # of the License, or (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program; if not, write to the Free Software Foundation,
  15. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. #
  17. # ##### END GPL LICENSE BLOCK #####
  18. # Filename : japanese_bigbrush.py
  19. # Author : Stephane Grabli
  20. # Date : 04/08/2005
  21. # Purpose : Simulates a big brush fr oriental painting
  22. from freestyle.chainingiterators import ChainSilhouetteIterator
  23. from freestyle.functions import pyInverseCurvature2DAngleF0D
  24. from freestyle.predicates import (
  25. NotUP1D,
  26. QuantitativeInvisibilityUP1D,
  27. pyDensityUP1D,
  28. pyHigherLengthUP1D,
  29. pyHigherNumberOfTurnsUP1D,
  30. pyLengthBP1D,
  31. pyParameterUP0D,
  32. )
  33. from freestyle.shaders import (
  34. BezierCurveShader,
  35. ConstantColorShader,
  36. ConstantThicknessShader,
  37. SamplingShader,
  38. TipRemoverShader,
  39. pyNonLinearVaryingThicknessShader,
  40. pySamplingShader,
  41. )
  42. from freestyle.types import IntegrationType, Operators
  43. Operators.select(QuantitativeInvisibilityUP1D(0))
  44. Operators.bidirectional_chain(ChainSilhouetteIterator(), NotUP1D(QuantitativeInvisibilityUP1D(0)))
  45. ## Splits strokes at points of highest 2D curvature
  46. ## when there are too many abrupt turns in it
  47. func = pyInverseCurvature2DAngleF0D()
  48. Operators.recursive_split(func, pyParameterUP0D(0.2, 0.8), NotUP1D(pyHigherNumberOfTurnsUP1D(3, 0.5)), 2)
  49. ## Keeps only long enough strokes
  50. Operators.select(pyHigherLengthUP1D(100))
  51. ## Sorts so as to draw the longest strokes first
  52. ## (this will be done using the causal density)
  53. Operators.sort(pyLengthBP1D())
  54. shaders_list = [
  55. pySamplingShader(10),
  56. BezierCurveShader(30),
  57. SamplingShader(50),
  58. ConstantThicknessShader(10),
  59. pyNonLinearVaryingThicknessShader(4, 25, 0.6),
  60. ConstantColorShader(0.2, 0.2, 0.2,1.0),
  61. TipRemoverShader(10),
  62. ]
  63. ## Use the causal density to avoid cluttering
  64. Operators.create(pyDensityUP1D(8, 0.4, IntegrationType.MEAN), shaders_list)