Writing text on a curve in pygame - python-3.x

How do I write text like this over a curve like bezier, bspline etc. using pygame or python 3?

If you know the angles you want to display the text at, you could create images for each letter and then use pygame.transform.rotate on the letter to create a new, rotated image.

Pygame text functions are limited to monochrome text rendering in a straightline, using the font's hinting.
Cairo (and PyCairo) however, offer heavy duty drawing and text rendering APIs -
so you probably will have to learn how make your curved text in Cairo, and transfer the cairo image to a Pygame surface for your game.
There is a wiki page on how to transfer images between both here: http://pygame.org/wiki/CairoPygame - I am not sure if Cairo's API alone contemplates curved text, but it can render SVG - so you can create your curved text in SVG, render it in cairo, and paste it in Pygame.

Related

Recognize dark rectangles with Open CV - Node.js

I'm trying to do some image recognition using Open CV. I want to detect the position of a dark rectangle in a game called Diablo 2.
After detecting the position of the rectangle, I will extract the text of that rectangle using OCR.
I've prepared some examples using Photoshop of where are those rectangles located.
On the left you can see the game screenshot, on the right I've pointed out the dark rectangles using a red rectangle, that's the place I want to detect using OpenCV.
Which OpenCV method should I use to detect those dark rectangles?
I'm not sure if Open CV is capable of doing this kind of pattern recognition, would be great if anyone can point me out how to do it.

Making a drawing game using phaser

I am developing a game using Phaser where a user is rendered a triangular canvas. User can crop this canvas to any possible shape by drawing any crop pattern on the canvas. Besides this, i need to get this cropped canvas in suitable data format to be used as an image to render and also trace changes made on this canvas for undoing puspose.
Any help to get this through will be appreciated.
Thanks in advance.
Initial canvas
Canvas after crop
Cropped canvas used to create new canvas
So it's like folding a piece of paper and then cutting it so it looks like a snowflake? Interesting idea.
I think you could either use BitmapData to draw the initial cut out, then copy that bitmap 6 (or 12?) times and rotate and flip x-axis to construct the rest. Though maybe there will be seems, so like small lines, between the parts idk.
Another appproach would be to keep track of the initial cutlines like vectors. Then use math/trigonometry to calculate the result. No idea how to do this though, sorry.

Clear Text Overlay using opencv

i was wondering if there is a way to clear a text overlay using opencv. i nee to write text to the same area of the screen and it just writes over the initial overlay
You can draw a white rectangle at the place you want to write text.
cv::rectangle(image,topLeftPoint,bottomRightPoint,cv::Scalar(255,255,255),CV_FILLED);

Render text on canvas using WebGL

I want to render some text on a canvas using WebGL, which API of WebGL should be used?
Note: "text" can be either plain text or HTML snippet with CSS style
Most demos that I've seen that do text of any sort (like a FPS counter) simply create an HTML element with the text they want and position it over the canvas. This would probably be a good approach for most text that you would want to show "in" a canvas (ie: menus).
The only exception would be if you want the text to be an actual part of the 3d scene (like, say, text on a billboard), in which case the methodologies wouldn't be any different than rendering text in standard OpenGL. You can find a very good robust example here: http://dmedia.dprogramming.com/?n=Tutorials.TextRendering1
There's also a WebGL tutorial about text here.
For WebGL-rendered text, you can write text to a canvas "2d" context, then create a texture from the canvas. Denny Koch does that in his EnergizeGL framework.

Get Font Glyphs as Vectors, manipulate and product SVG or Bitmap

I have an application that needs to apply some transformations to text (including non-affine transformations). Does anyone know of a toolkit (or group of tools) that would let me bring in a True Type or Postscript Font, get the glyphs as outlines, then apply transformations to the outlines and render it as a bitmap or svg file ? Flash won't do non-affine transformations so it is out. Illustrator has a function which converts text to outlines, but Illustrator scripting is very unstable so I can't really use it for this. Thanks for any help.
You could use the Batik TTF to SVG Font converter. The SVG font format uses the same path data format that the SVG <path> element uses.
For example, this is the output from converting Gentium Basic Regular using the above tool. With the right coordinate system, you can just grab out the path data, transform it however you like, and then draw it with a <path>. Note though that the glyph coordinate system in SVG fonts is actually inverted, with the (0,0) at the bottom left corner of the glyph cell box, compared to the regular SVG canvas which has (0,0) at the top left corner. So don't forget to flip the glyph, e.g. by putting transform="scale(1,-1)" on the <path> you use to render the glyph.
Once you have the SVG document that renders the glyphs as shapes you can convert it to a bitmap using your favourite tool. (Batik can do that too.)
While Batik is a good answer, it will convert only TrueType fonts to SVG Fonts. If you have OpenType fonts, and they more and more dominate now, you can use FontForge to get an SVG Font for these. Another advantage of using OpenType is that the produced SVG uses not only quadratic but also cubic Beziers in the path which is more effective.

Resources