GIMP Chat
http://gimpchat.com/

Place a Star on the center of the Canvas (Solved)
http://gimpchat.com/viewtopic.php?f=9&t=18306
Page 1 of 1

Author:  Pocholo [ Tue May 05, 2020 11:23 am ]
Post subject:  Place a Star on the center of the Canvas (Solved)

Hello everyone, I hope you are fine and staying safe!

I'm still learning how to write script-fu script and before I ask the question, I will like to thank all the experienced coder here and also the Gimp-Forum.net, that are been helping me through out this learning process.

Now, I will like to know the script-fu procedure to place a Star on the center of the canvas using the "Star brush. Thank you in advanced!

Author:  Pocholo [ Tue May 05, 2020 2:38 pm ]
Post subject:  Re: Place a Star on the center of the Canvas

Ok, I saw an example here
https://stackoverflow.com/questions/490 ... imple-line
and here
https://renenyffenegger.ch/notes/design ... ions/index

And I was be able to place the Star on the middle of the Canvas. This is what I achieve:


Image




(define (script-fu-create-a-Star)
    (let* (
         
      (imgWidht 700)
      (ImgHeight 700)
      (points (cons-array 4 'double) )   
      
      (img  (car (gimp-image-new imgWidht ImgHeight RGB)))
      (layer (car (gimp-layer-new img imgWidht ImgHeight RGB-IMAGE "Background" 100 LAYER-MODE-NORMAL)))
      
      
      
      
      )
      
      
      ;Create the Background
      (gimp-image-insert-layer img layer 0 0)
      (gimp-context-set-foreground '(0 0 0))
      (gimp-drawable-fill layer FILL-FOREGROUND)
      (gimp-context-set-brush "2. Star")
      (gimp-context-set-brush-size 210)
      (gimp-context-set-brush-aspect-ratio 2)
      (gimp-context-set-brush-angle 54)
      (gimp-context-get-brush)
      (gimp-context-set-foreground '(255 255 255))
      
      
      (aset points 0 350)
      (aset points 1 350)
      (aset points 2 350)
      (aset points 3 350)
      (gimp-paintbrush-default layer 4 points)
               
      
      (gimp-display-new img)

Author:  nelo [ Wed May 06, 2020 4:42 am ]
Post subject:  Re: Place a Star on the center of the Canvas (Solved)

Thnks for posting your solution here ... surely helpful for others who come across this topic.
Your link to stackoverflow doesn't lead to the question/answer. If you can still find where it was, can you correct it?

Author:  Pocholo [ Wed May 06, 2020 12:08 pm ]
Post subject:  Re: Place a Star on the center of the Canvas (Solved)

I’m not a coder and I don’t really know how to explain it. I search on the web for a hard explanation and I could find much. I use and exemption on what I saw and read from different places. This link gave a little perspective.
https://renenyffenegger.ch/notes/design ... ions/index

I learned from https://www.gimp.org/tutorials/Basic_Scheme2/
How to draw a line procedure, setting the cons-array and setting the coordinate points with this sample.


(set! points (cons-array 4 'double))

(aset points 0 0) ; (x0, y0)
(aset points 1 0)
(aset points 2 320) ; (x1, y1)
(aset points 3 240)
(gimp-paintbrush-default layer 4 points)



I know you need at least two points coordinate x, y in your image to construct an array. With GIMP “aset function” you can fill those coordinates values. I figured that if you make those coordinates points in the same place on the Canvas, it will fill with a value(s). In my case, I have a 700 x 700 square canvas and I set the both points x, y at 350, (center) and used an constant array of doubles. This I figured that will paint the “Star” in the center. I don’t know if that make sense, Like I said I’m new and I know it but don’t know how to put it in words.


P.S I found out that you don’t need to construct a 4 points coordinate to paint, in my case, the “Star” on the center of the Canvas. You need just two to accomplish what I did, thank to Ofnuts.






(define (script-fu-create-a-Star)
    (let* (
         
      (imgWidht 700)
      (ImgHeight 700)
      (points (cons-array 2 'double) )
      
      (img  (car (gimp-image-new imgWidht ImgHeight RGB)))
      (layer (car (gimp-layer-new img imgWidht ImgHeight RGB-IMAGE "Background" 100 LAYER-MODE-NORMAL)))
      
      )
            
      ;Create the Background
      (gimp-image-insert-layer img layer 0 0)
      (gimp-context-set-foreground '(0 0 0))
      (gimp-drawable-fill layer FILL-FOREGROUND)
      (gimp-context-set-brush "2. Star")
      (gimp-context-set-brush-size 210)
      (gimp-context-set-brush-aspect-ratio 2)
      (gimp-context-set-brush-angle 54)
      (gimp-context-get-brush)
      (gimp-context-set-foreground '(255 255 255))
      
      (aset points 0 350)
      (aset points 1 350)
      
      (gimp-paintbrush-default layer 2 points)

Author:  nelo [ Wed May 06, 2020 12:48 pm ]
Post subject:  Re: Place a Star on the center of the Canvas (Solved)

Thank you @pocholo

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/