i need a help. How to make pillow clipping my progress bar against current exp. Because currently I have using resize but unfortunately when someone has little exp it does not look good, so I would like to make the bot trim my progress bar from right relative to missing exp
This is my actually code:
rectangle = Image.open("progress-bar.png")
rectangle = rectangle.resize((round(rectangle.size[0] * exp / lev), rectangle.size[1]))
levelcard.paste(rectangle, (440, 376))
levelcard.save("profile2.png")
await ctx.reply(file=discord.File("profile2.png"))
(and rectangle.crop don't work)
(I want it to sort of crop the middle of my progress bar (I can show you a picture) so that the beginning of the bar and the end of the bar are rounded, because when I use resize it just makes my bar square on both sides)
Firstly: Please give more information and a more In-Depth explanation of your problem, the example picture you mentioned would be of great use to understand what you need.
Secondly: Are you sure you want to resize the progressbar to the exp divided by the level? That doesn't seem like it would work.
If the levels don't exponentially increase, and the exp goes to 0 every level up, then you might wanna just do the exp multiplied by this magical number x_pixel_size_of_progressbar / max_xp_to_level_up. IE: if the x size of the progressbar is 200, and the max xp is 100, the magic number is 2 (200 / 100 = 2), so if you had full xp, the xp bar would be full (100 * 2 = 200), so instead of rectangle = rectangle.resize((round(rectangle.size[0] * exp / lev), rectangle.size[1])), you would do rectangle = rectangle.resize((round(exp * (rectangle.size[0] / maxexp)), rectangle.size[1]))
And if the exp doesn't go to 0 at levelup kind of like a "global" xp system, then you can do something like this_levels_xp = exp - (levup_xp * lev) and then apply the stuff mentioned before.
Related
I know this question has been asked a million times before, however I'm trying to do this a different way, a much simpler way because I don't have to support all the major browsers.
For every image on our site, we know the width and the height before runtime as the cdn returns this info for us, once an image registers I basically extract the CURRENT width and figure out the percentage decrease (if any) of that image.
Example:
var originalWidth = 640;
var originalHeight = 480;
var actualWidth = 431;
var decrease = (originalWidth-actualWidth)/originalWidth*100;
Now that I've got the decrease from it's original size, I wanted to do something with the calc css method, seeing as all our images resize proportionally. I've tried this:
$element.css('height', `calc(${originalHeight}px - (${originalHeight}px * ${decrease} / 100 ))` );
I've can't even get this to apply to the element, if I make a much simpler calc css method it works, but this wont even apply, I'm assuming it's because the actual evaluation is failing, but I can't seem to get the units correct
Maybe it's only a parenthesis problem, try with this
$element.css('height', `calc((${originalHeight}px - ((${originalHeight}px * ${decrease}) / 100 )))` );
Using the code shown at http://processing.org/reference/saveFrame_.html I seem to be getting a grey overlay on every frame I try and output from any number of different sketchs? The grey bar overlay seems to grow as the more frame are saved. Has anyone else experienced this? Have I done something incorrect?
The code that is doing this gray area in your sketch is this:
if (xport < 100) {
line(xport, 0, xport, 100);
xport = xport + 1;
}
I don't exactly know what you wanted to do, but its drawing a vertical line with xport as x and from 0 to 100 as y
I'm trying to use the answers I found in these questions:
How to save a plot into a PDF file without a large margin around
Get rid of the white space around matlab figure's pdf output
External source
to print a matlab plot to pdf without having the white margins included.
However using this code:
function saveTightFigure( h, outfilename, orientation )
% SAVETIGHTFIGURE(H,OUTFILENAME) Saves figure H in file OUTFILENAME without
% the white space around it.
%
% by ``a grad student"
% http://tipstrickshowtos.blogspot.com/2010/08/how-to-get-rid-of-white-margin-in.html
% get the current axes
ax = get(h, 'CurrentAxes');
% make it tight
ti = get(ax,'TightInset');
set(ax,'Position',[ti(1) ti(2) 1-ti(3)-ti(1) 1-ti(4)-ti(2)]);
% adjust the papersize
set(ax,'units','centimeters');
pos = get(ax,'Position');
ti = get(ax,'TightInset');
set(h, 'PaperUnits','centimeters');
set(h, 'PaperSize', [pos(3)+ti(1)+ti(3) pos(4)+ti(2)+ti(4)]);
set(h, 'PaperPositionMode', 'manual');
set(h, 'PaperPosition',[0 0 pos(3)+ti(1)+ti(3) pos(4)+ti(2)+ti(4)]);
% save it
%saveas(h,outfilename);
if( orientation == 1)
orient portrait
else
orient landscape
end
print( '-dpdf', outfilename );
end
Results in this output:
As you can see the 'PaperSize' seems to be set not properly. Any idea of possible fixes?
NOTE
If I change the orientation between landscape and portrait the result is the same, simply the image is chopped in a different way.
However if I save the image with the saveas(h,outfilename); instruction the correct output is produced.
Why is this? And what is the difference between the two saving instructions?
Alltogether the answers you mentioned offer a lot of approaches, but most of them didn't worked for me neither. Most of them screw up your papersize when you want to get the tight inset, the only which worked for me was:
set(axes_handle,'LooseInset',get(axes_handle,'TightInset'));
I finally wrote a function, where I specify the exact height and width of the output figure on paper, and the margin I want (or just set it to zero). Be aware that you also need to pass the axis handle. Maybe this functions works for you also.
function saveFigure( fig_handle, axes_handle, name , height , width , margin)
set(axes_handle,'LooseInset',get(axes_handle,'TightInset'));
set(fig_handle, 'Units','centimeters','PaperUnits','centimeters')
% the last two parameters of 'Position' define the figure size
set(fig_handle,'Position',[-margin -margin width height],...
'PaperPosition',[0 0 width+margin height+margin],...
'PaperSize',[width+margin height+margin],...
'PaperPositionMode','auto',...
'InvertHardcopy', 'on',...
'Renderer','painters'... %recommended if there are no alphamaps
);
saveas(fig_handle,name,'pdf')
end
Edit: if you use painters as renderer saveas and print should produce similar results. For jpegs print is preferable as you can specify the resolution.
I am working on a filter in which the instead of using fixed size filtering window, I use a adaptive window size based on noise density. For example, let say the window size is 3x3, it has 9 pixels. when all these 9 pixels are detected as corrupted pixels it is useless to proceed to next step as I need some noisy free pixels in window to process next step. In this case, I change the window size to 5x5 and scan again. If once again all the pixels(25 pixels) are detected as corrupted, I go for 7x7 window. To implement I have written a code but it is too large as I represented all the elements in each window. I am unsure to implement it otherwise but I am sure there will other easy way to do it.
The Code, I written for the above stated purpose is
if((S1==1) && (S2==1))
5x5 window===> V=[L(p-2,q-2) L(p-2,q-1) L(p-2,q) L(p-2,q+1) L(p-2,q+2) L(p-1,q-2) L(p-1,q-1) L(p-1,q) L(p-1,q+1) L(p-1,q+2) L(p,q-2) L(p,q-1) L(p,q+1) L(p,q+2) L(p+1,q-2) L(p+1,q-1) L(p+1,q) L(p+1,q+1) L(p+1,q+2) L(p+2,q-2) L(p+2,q-1) L(p+2,q) L(p+2,q+1) L(p+2,q+2)]; % 5x5 window
for k=1:24
if((V(k) == 0) || (V(k) == 255))
else
N(a)=V(k);
a=a+1;
end
end
if((a-1)>= 1)
Y(p,q)=round(Median(N(1:a-1)));
%disp(Y(p,q));
a=1;
else
7x7 window===> V1=[L(p-3,q-3) L(p-3,q-2) L(p-3,q-1) L(p-3,q) L(p-3,q+1) L(p-3,q+2) L(p-3,q+3) L(p-2,q-3) L(p-2,q-2) L(p-2,q-1) L(p-2,q) L(p-2,q+1) L(p-2,q+2) L(p-2,q+3) L(p-1,q-3) L(p-1,q-2) L(p-1,q-1) L(p-1,q) L(p-1,q+1) L(p-1,q+2) L(p-1,q+3) L(p,q-3) L(p,q-2) L(p,q-1) L(p,q+1) L(p,q+2) L(p,q+3) L(p+1,q-3) L(p+1,q-2) L(p+1,q-1) L(p+1,q) L(p+1,q+1) L(p+1,q+2) L(p+1,q+3) L(p+2,q-3) L(p+2,q-2) L(p+2,q-1) L(p+2,q) L(p+2,q+1) L(p+2,q+2) L(p+2,q+3) L(p+3,q-3) L(p+3,q-2) L(p+3,q-1) L(p+3,q) L(p+3,q+1) L(p+3,q+2) L(p+3,q+3)]; % 7x7 window
Similarly, I have used windows upto 11x11. I want to represent V and V1 vector easily rather than writing these much of codes.
An arbitrary window centered at [p,q] of size n can be read from an image as
halfSize = floor(n/2); %# n has to be odd
window = image(p-halfSize:p+halfSize,q-halfSize:q+halfSize);
Note that you want to pad your image with the maximum value of halfSize, or alternatively, test that e.g. p>halfSize and p<imageSize-halfSize+1 (same for q), so that you don't get indexing errors.
I've written a home-brew view_port class for a 2D strategy game. The panning (with arrow keys) and zooming (with mouse wheel) work fine, but I'd like the view to also home towards wherever the cursor is placed, as in Google Maps or Supreme Commander
I'll spare you the specifics of how the zoom is implemented and even what language I'm using: this is all irrelevant. What's important is the zoom function, which modifies the rectangle structure (x,y,w,h) that represents the view. So far the code looks like this:
void zoom(float delta, float mouse_x, float mouse_y)
{
zoom += delta;
view.w = window.w/zoom;
view.h = window.h/zoom;
// view.x = ???
// view.y = ???
}
Before somebody suggests it, the following will not work:
view.x = mouse_x - view.w/2;
view.y = mouse_y - view.h/2;
This picture illustrates why, as I attempt to zoom towards the smiley face:
As you can see when the object underneath the mouse is placed in the centre of the screen it stops being under the mouse, so we stop zooming towards it!
If you've got a head for maths (you'll need one) any help on this would be most appreciated!
I managed to figure out the solution, thanks to a lot of head-scratching a lot of little picture: I'll post the algorithm here in case anybody else needs it.
Vect2f mouse_true(mouse_position.x/zoom + view.x, mouse_position.y/zoom + view.y);
Vect2f mouse_relative(window_size.x/mouse_pos.x, window_size.y/mouse_pos.y);
view.x = mouse_true.x - view.w/mouse_relative.x;
view.y = mouse_true.y - view.h/mouse_relative.y;
This ensures that objects placed under the mouse stay under the mouse. You can check out the code over on github, and I also made a showcase demo for youtube.
In my concept there is a camera and a screen.
The camera is the moving part. The screen is the scalable part.
I made an example script including a live demo.
The problem is reduced to only one dimension in order to keep it simple.
https://www.khanacademy.org/cs/cam-positioning/4772921545326592
var a = (mouse.x + camera.x) / zoom;
// now increase the zoom e.g.: like that:
zoom = zoom + 1;
var newPosition = a * zoom - mouse.x;
camera.setX(newPosition);
screen.setWidth(originalWidth * zoom);
For a 2D example you can simply add the same code for the height and y positions.