When using save() function my canvas is always grey

Hey I could use a little help, as my title says I am having trouble getting some high resolution files of my artwork. Here is my code please let me know what I could do to get high resolution images of the artwork I make.

<

t = 0
points =

def setup():
size(1260,800)
save(“this3.jpg”)
noStroke()

def draw():
background(255)
translate(width/2,height/2)
points =
t = 0
while t < 1000:
points.append(harmonograph(t))
t += 0.01

for i,p in enumerate(points):
    stroke(255,0,0) 
    if i < len(points) - 1:
        line(p[0],p[1], points[i+1][0],points[i+1][1])

def harmonograph(t):
a1=a2=a3=a4 = 100
f1,f2,f3,f4 = 2.01,3,3,2
p1,p2,p3,p4 = -PI/2,0,-PI/16,0
d1,d2,d3,d4 = 0.00085,0.0065,0,0
x = a1cos(f1t + p1)exp(-d1t) + a3cos(f3t + p3)exp(-d3t)
y = a2sin(f2t + p2)exp(-d2t) + a4cos(f4t + p4)exp(-d4t)
return [x,y]

Thank you, Drel

Welcome, Drel

Your save() function is in the setup(). You’re saving an image before Processing has a chance to draw anything.

Perhaps you could activate this using a mouse-press instead:

def setup():
    size(1260,800)
    #save("this3.jpg")
    ...

def mousePressed():
    save("this3.jpg")

Alternatively, you could add a save() function to the draw(), but add some condition to avoid it saving every frame.

Thank you @tabreturn, i shall use the mousePressed and try to work on my conditional statements, I like the latter but my coding rough.

1 Like

Does the save function warrant high resolution images or do I need to learn the create graphics function?

What do mean by “high resolution images”? Your sketch 1260 × 800 pixels. You can just increase the values in your size() function for more pixels.

You can insert your save() function at the end of your draw() loop, followed by an exit() function. This way the window will save the graphic on the first frame then close again.

1 Like

By high resolution I meant, with keeping the window at a size I can view on my computer screen without blowing it past my screens borders ( ie 1260 x 800), i can successfully save now but when I go to zoom in the picture is bitmapped.

Would drawing to the Pgraphics and then saving to a vector format supersede my problem?

A JPG is a raster/bitmap image. Zoom in far enough, and you’ll always see pixels.

I’m not sure why you’re using a draw() function? After all, you’re saving a single frame? Moreover, why does the Processing output need to fit within your screen borders? Here’s some code that generates and saves an image 5× the resolution of your screen and closes immediately:

size(6300, 4000)
circle(width/2, height/2, width/3)
save('this3.jpg')
exit()

You can always scale the JPG to fit your screen (in your image viewer or similar software); it’ll have the resolution to handle more ‘zooming in’ .

Alternatively, you could render an SVG (vector) version of the sketch:

add_library('svg')

def setup():
    size(1260, 800, SVG, 'this3.svg')

def draw():
    circle(width/2, height/2, width/3)
    exit()

You can leave that file as vector, or rasterize it at your desired resolution (using GIMP, Photoshop, etc.).

1 Like

Thank you for your response on making this clearer.

I thought I needed to include the draw() command for the software to produce anything on the screen.

Now I understand it’s just for doing more than one frame.

Disregard the notion of it only fitting in my screen boarders, you can scale in a viewfinder yes…. Thank you

I’m just starting out in processing and have made some pretty Frankenstein sketches just looking at what’s on the web and combining and writing.

2 Likes