Skip to content

Instantly share code, notes, and snippets.

@josepablo-espinoza
Created August 3, 2024 03:57
Show Gist options
  • Select an option

  • Save josepablo-espinoza/2ab680e86aeac926c4e4c39c47403118 to your computer and use it in GitHub Desktop.

Select an option

Save josepablo-espinoza/2ab680e86aeac926c4e4c39c47403118 to your computer and use it in GitHub Desktop.
change
from krita import * # type: ignore
from PyQt5.QtGui import QColor
import random
'''
HSVshifter for Krita:
This script uses the background color to generate
a new color based on the following ranges to shift:
hue_range
sat_range
val_range
Install:
1. Save or download this script.
2. Place it in any preferred folder.
3. Name it e.g. "hsv-shifter.py".
4. On Krita use ten script plugin to assing this script to a shortcut.
How to use:
1. Set the background color to the color you would like to use as a pivot for shifting HSV
2. fire the shortcut.
3. change the *_range variables to widen or narrow the shift.
'''
def main():
app = Krita.instance() # type: ignore
view = app.activeWindow().activeView()
pivot_color = view.backgroundColor()
currentHsv = pivot_color.colorForCanvas(view.canvas())
h = currentHsv.hue()
s = currentHsv.saturation()
v = currentHsv.value()
#CHANGE THIS RANGES AS YOU LIKE
hue_range = 3
sat_range = 2
val_range = 5
# Generate random shifts
hue_shift = random.randint(-hue_range, hue_range)
sat_shift = random.randint(-sat_range, sat_range)
val_shift = random.randint(-val_range, val_range)
# Apply shifts
new_hue = colorClamp(h + hue_shift)
new_sat = colorClamp(s + sat_shift)
new_val = colorClamp(v + val_shift)
# print(f"c({h}, {s}, {v})")
# print(f"n({new_hue}, {new_sat}, {new_val})")
newColor = QColor()
newColor.setHsv(new_hue, new_sat, new_val)
view.setForeGroundColor(ManagedColor.fromQColor(newColor, view.canvas()))# type: ignore
def colorClamp(n, minn=1, maxn=254):
return max(min(maxn, n), minn)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment