jdf / Processing.py-Bugs

A home for all bugs and feature requests about Python Mode for the Processing Development Environment.
41 stars 8 forks source link

Colormode shifts between SVG and screen #305

Closed 3D2Code closed 3 years ago

3D2Code commented 3 years ago

Not sure whether this is an issue or not. I am new to processing and and still trying to figure out the context/scope of setup vs draw.

When I run the following sketch, the screen shows circles in different hues per the colorMode(HSB,255) in setup. However, SVG export seems to interpret the line fill(int(random(255)),250,255) in RGB mode. Green and Blue channels are clamped to 250 and 255 respectively. So the SVG file shows a bunch of cyan tone circles. If I uncomment the colorMode(HSB,255) within draw(), the SVG file captures the same hues as shown on screen.

add_library('svg')

def setup(): size(800, 600) colorMode(HSB,255) beginRecord(SVG,'filename.svg')

frameRate(1)

def draw(): background(200)

colorMode(HSB,255)

for i in range(10):
    c_x=random(0,width)
    c_y=random(0,height)
    r0=random(20,100)
    fill(int(random(255)),250,255)
    ellipse(c_x,c_y, r0, r0)

if  mousePressed:
    endRecord()
    #exit()
villares commented 3 years ago

Hi @3D2Code ! You are lucky, this is no bug :)

You have to put colorMode(HSB,255) inside the SVG recording, after beginRecord(), otherwise it has no effect on the exported file (but it still has effect on your screen).

…
beginRecord(SVG,'filename.svg')
colorMode(HSB,255)
…

Let me seize this opportunity to invite you to join us at https://discourse.processing.org/c/processing-py/9 !

3D2Code commented 3 years ago

Thanks a bunch Villares. I will try to remember.