[Solved] Color Gradient maker

Keyboard macros or custom scripts

[Solved] Color Gradient maker

Postby Mr.Dandy » Mon Jul 30, 2018 4:12 pm

Hello,

I try to create a gradient between 2 RGB colors.
This is my code:
Code: Select all   Expand viewCollapse view
Sub GradientMe
    nBeg = RGB(255, 51, 51) 'red
    nEnd = RGB(102, 102, 255) 'blue
    nSteps = 25
    r1 = Red(nBeg) : g1 = Green(nBeg) : b1 = Blue(nBeg)
    r2 = Red(nEnd) : g2 = Green(nEnd) : b2 = Blue(nEnd)
    if ( nBeg < nEnd ) then
        dr = Int((r2-r1) / nSteps)
        dg = Int((g2-g1) / nSteps)
        db = Int((b2-b1) / nSteps)
    else
        dr = Int((r1-r2) / nSteps)
        dg = Int((g1-g2) / nSteps)
        db = Int((b1-b2) / nSteps)
    endif
    oSheet = ThisComponent.CurrentController.ActiveSheet
    For i = 0 to nSteps -1
        oCell = oSheet.getCellByPosition(0,i)
        oCell.setPropertyValue("CellBackColor", nBeg)
        if ( nBeg > nEnd ) then
            r1 = r1 - dr : g1 = g1 - dg : b1 = b1 - db
        else
            r1 = r1 + dr : g1 = g1 + dg : b1 = b1 + db
        endif
        nBeg = RGB(r1, g1, b1)
    Next i
End sub

But in last cells, color is wrong.
Any advice welcome
Last edited by Mr.Dandy on Thu Aug 02, 2018 2:47 pm, edited 1 time in total.
OpenOffice 4.1.3 - Windows 7
User avatar
Mr.Dandy
 
Posts: 288
Joined: Tue Dec 11, 2012 4:22 pm

Re: Color Gradient maker

Postby JeJe » Mon Jul 30, 2018 8:57 pm

change / to \

Code: Select all   Expand viewCollapse view
dr = Int((r2-r1) \ nSteps)
        dg = Int((g2-g1) \ nSteps)
        db = Int((b2-b1) \ nSteps)
    else
        dr = Int((r1-r2) \ nSteps)
        dg = Int((g1-g2) \ nSteps)
        db = Int((b1-b2) \ nSteps)
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 484
Joined: Wed Mar 09, 2016 2:40 pm

Re: Color Gradient maker

Postby Mr.Dandy » Thu Aug 02, 2018 2:41 pm

:bravo: JeJe

But, could you explain what is this weird operator?
I don't find in help file and dev guide.
OpenOffice 4.1.3 - Windows 7
User avatar
Mr.Dandy
 
Posts: 288
Joined: Tue Dec 11, 2012 4:22 pm

Re: [Solved] Color Gradient maker

Postby JeJe » Thu Aug 02, 2018 5:47 pm

\ is division giving a whole number.

https://wiki.openoffice.org/wiki/Docume ... /Operators
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 484
Joined: Wed Mar 09, 2016 2:40 pm


Return to OpenOffice Basic, Python, BeanShell, JavaScript

Who is online

Users browsing this forum: No registered users and 0 guests