I'm trying to export frames from a Processing sketch using the saveFrame() function, but they come out very rough, specially the fonts. I'm on a Mac with retina display and even though when I'm running the sketch everything looks good and sharp, when I save the frames they look bad.
I have included the following lines (in the setup function) but they don't improve the outcome of the saveFrame() function:
size(1280, 720, "processing.core.PGraphicsRetina2D");
hint(ENABLE_RETINA_PIXELS);
smooth(8);
Any ideas?
Text is clean with this sketch, do you run it in java mode ?
// size(960, 540); //
size(960, 540, "processing.core.PGraphicsRetina2D");
hint(ENABLE_RETINA_PIXELS);
textSize(32);
text("word", 10, 30);
fill(0, 102, 153);
text("word", 10, 60);
fill(0, 102, 153, 51);
text("word", 10, 90);
If you like a clean retina screenshot, you need to double your sketch size with size(1920,1080).
If you need this picture for a website you can use this html <img src="retina" width="960" height="540">
Related
I am trying to add an image as a background of a button in pygame gui. I have the button created now and I just need to add the image. How can I add the image to the button?
This is my code
game1 = pygame.Rect(150 , 100, 200, 150) # creates a rect object
pygame.draw.rect(screen, [255, 100, 0], game1) # draw objects down here
it works fine
You're probably looking for pygame.Surface.blit (http://www.pygame.org/docs/ref/surface.html#pygame.Surface.blit)
Load your background image and blit it wherever you want.
img = pygame.image.load('thisisanimage.png')
WhateverYourDisplayNameIs.blit(img,(x,y))
Just in case you're confused, it looks like you're using screen as your display surface.
I'm trying to make fade in fade out effect in Processing. When I press the key 'z', the transparency of the rectangle go from 0 to 255, stay there for 1 sec then fade out from 255 to 0. Thank you in advance!
Here is one of my latest attempt:
int alphaValue;
void setup() {
size(640, 360);
rect1 = createShape(RECT,292, 85, 55, 55, 2);
rect2 = createShape(RECT,347, 140, 55, 55, 2);
rect1.setFill(0);
rect1.setStroke(color(255));
rect2.setFill(0);
rect2.setStroke(color(255));
}
void keyPressed() {
if (key == 'z')
{
fadingrectangle();
}
}
void fadingrectangle() {
rect1.setFill(color(229, 229, 229, alphaValue));
if (alphaValue < 255) {
alphaValue++;
}
}
I just can make it fading in but I don't know how to make it automatically fading out after appearing 1 second.
Stack Overflow isn't really designed for general "how do I do this" type questions. It's for specific "I tried X, expected Y, but got Z instead" type questions. But I'll try to help in a general sense.
First off, you need to break your problem down into smaller pieces. For example, can you create a simple program that just shows a rectangle? Can you create a separate program that just prints something to the console when the user presses the Z key? Get those working perfectly by themselves before you move on.
From there, you need to store the current state of your sketch. In your case, maybe that's a single variable that stores the transparency of the rectangle. Then you need to use that variable to draw each frame, and change that variable to make the rectangle fade in and out. Here is a tutorial I wrote about animation in Processing.
But again, you need to break your problem down into smaller pieces. Approach each piece by itself, and post a MCVE along with a specific technical question if you get stuck. Good luck.
we have a problem again. We are drawing a bunch of circles. In the middle of one of these drawingCountry Methods it suddenly doesn't draw circles anymore. Also following drawingCountry Methods don't draw circles anymore, but they still get called. We tested it by inserting println("test"). Does anyone have an idea why this happens?
Our code looks similar to this:
public void drawRussia(){
canvas.ellipseMode(CORNER);
canvas.ellipse(705*factorWidth, 149*factorHeight, 75, 75);
canvas.ellipse(629.5*factorWidth, 161.5*factorHeight, 75, 75);
canvas.ellipse(523*factorWidth, 164*factorHeight, 75, 75);
canvas.ellipse(562*factorWidth, 244*factorHeight, 10, 10);
canvas.ellipse(555*factorWidth, 253*factorHeight, 10, 10);
//--------------------------stops drawing circles -------------------
canvas.ellipse(720*factorWidth, 223*factorHeight, 15, 15);
canvas.ellipse(673*factorWidth, 116*factorHeight, 50, 50);
canvas.ellipse(777*factorWidth, 121*factorHeight, 75, 75);
}
After drawRussia(), there are similar methods following (which don't draw). Before everything works well.
Is there some kind of buffer, or limit in drawing ...
Thanks for your help.
I found an odd behavior while working on my pet game. I wanted to draw few objects on canvas, some of them required image / icon to be rotated. It is quite common use case, usual solution is to make use of context's rotate method. Going with the blow I used also translate to nicely and consistently put images in desired place.
This worked fine, until I tried Chrome on Windows laptop, with hardware acceleration enabled. Images started to blink and teleport across the screen. I found that it is related to acceleration (turning off accelerated graphics fixes problem) and my best guess is that when updating frame the renderer assumes that drawing calls are independent and can be executed in parallel. When context transforms take place it is not the case because context state changes.
Example of undesired behavior: having a canvas element with ID 'screen' try the following:
var canvas = document.getElementById("screen"),
ctx = canvas.getContext("2d");
var drawrect = function () {
ctx.fillStyle = this.color;
ctx.translate(this.x+10, this.y+10);
ctx.rotate(this.rotation);
ctx.fillRect(-10, -10, 20, 20);
ctx.rotate(-this.rotation);
ctx.translate(-this.x-10, -this.y-10);
};
var red = {
x: 22,
y: 22,
rotation: 0,
color: "#ff0000",
draw: drawrect
};
var blu = {
x: 22,
y: 111,
rotation: 0,
color: "#0000ff",
draw: drawrect
};
function main_loop() {
ctx.clearRect(0, 0, 450, 450);
frameId = requestAnimationFrame(main_loop);
red.draw();
red.x += 1;
red.rotation +=0.1;
blu.draw();
blu.x += 1;
blu.rotation -=0.1;
}
main_loop();
Working example: http://jsfiddle.net/1u2d7uhr/7/ (tested on Chrome, Chromium, Firefox; accelerated Chrome glitches, others do not)
I was able to 'fix' this by removing translations and rendering rotating elements to separate canvas, which is then (after rotations) drawn onto the main one. This seems hackish to me though.
Is it code error on my part?
In this case what is the right way to render rotations (perhaps with this question I should go do codereview, but I'm not sure if this is the case)?
Or is it buggy behavior on browser side? I understand the logic behind it but it can be very much surprising (and cause some confusion) to developers. Or am I only one...
I load a PNG image in a QPixmap/QImage and I want to crop it. Is there a function that does that in Qt, or how should I do it otherwise?
You can use QPixmap::copy:
QRect rect(10, 20, 30, 40);
QPixmap original('image.png');
QPixmap cropped = original.copy(rect);
There is also QImage::copy:
QRect rect(10, 20, 30, 40);
QImage original('image.png');
QImage cropped = original.copy(rect);
Use QImage instead of QPixmap:
QImage image("initial_image.jpg");
QImage copy ;
copy = image.copy( 0, 0, 128, 128);
copy.save("cropped_image.jpg");
This code will save a file cropped to upper left corner 128x128px.
Since you use QPixmap, you can use its copy method and supply it with a QRect to perform the actual crop.
Just use of the QPixmap's copy() functions.
This text is result of reading the first comment on your quiestion:
Sometimes it is better to wrap around an image. That is to have an image that is part of another image or in other words points to a part of another image. This is way the wrapped image does not require additional memory, except for its header. You can display or save the wrapped image without worries. The downside is that the original image must remain valid until you use the wrapped image, also if you are drawing in the wrapped image it will affect the source.