Is it possible to simulate a erase action without having to create an extra shape in KonvaJS? - konvajs

I am following this guide which contains a brush and eraser functionality. The guide's code sets the "globalCompositeOperation" to "destination-out" and basically ends up creating another line that will cover whatever you have drawn before with the brush.
This would work pretty well in some cases, but if I made my "destination-out" lines not-draggable and the "source-over" lines draggable, then if I drag the "source-over" lines around the canvas these lines would still be intact and it would not look like as if they were erased.
In a better attempt to explain my problem, I provide you this example: If I were to create two parallel lines, line1(x1,y1) and line2(x2,y2), and then I decide to draw a "destination-out" line in the middle of both, is there a way I can keep that "erased" part in the middle of line1 and line2 if I were to move one of the lines away from the "destination-out" line?
I'm sure it is not like this, but is it possible to change certain points inside the line as "destination-out" while the rest of the points are "source-over" If not, how can we simulate this action without having to create a long static extra "destination-out" line?

Related

How to connect lines using angle?

Working in Julia, I've a set of lines on an image. Each line has a separate label assigned to it. The following image shows Note that these lines are not straight always, for instance,
I've used the solution here. I'm working on the result of this statement labels = label_components(thinned, trues(3,3)). So I'm not sure how to get angle per label. I was thinking some PROTOTYPE like
for label in labels
getangle_per_label(label)
end
then
interpolate labels with similar angles
I'm not sure how to implement it, any ideas?

How to addlines of various pen styles?

I have a TChart and want to draw horizontal lines as markers. That far, that easy. These lines shall have different pens, like widths and colors. What ever I try, I end up with my horizontal lines all looking the same!
This is what I tried:
Linien:=TDrawLineTool.Create(Self); // creates the drawtool <br>
CustomChart.Tools.Add(Linien);<br>
Linien.Pen.Width:=20;<br>
Linien.Lines.AddLine(0,d,high(Trades_),d); // first line<br>
Linien.Pen.Width:=40;<br>
Linien.Lines.AddLine(0,d2,high(Trades_),d2); // another line<br>
=> ends up with both being 40 (or red or whatever).
How can I draw every line in its own style? Must I create more Linien, if yes: how to appostrophe them? Or must every line be its own drawing tool (creating lots of them?)
TDrawLineTool holds collection of lines - but stores only their coordinates, not attributes for every line.
From help:
Description The Pen property refers to the TDrawLineTool owner of
every line. All Lines share the same Pen object.
So yes, you have to create separate TDrawLineTool for every line style/width.

Find available grid position

I'm building a color box connecting game with objective-C and trying to figure out how to find the correct position when a block of boxes is placed incorrectly over another block of boxes.
See the attach image. In the image, you only need to move the left box one step to the right in order to connect the boxes and win.
However, if you place the left box on top of the other box (Image 2), I want to move it to the closest available free grid position.
This would be easy if the box was a simple square (a 1x1 grid, 2x2 grid, etc), but since the boxes can be complex, It's harder. There might also be a lot of boxes on the grid.
Any suggestions would be very appreciated.
If you're new to heuristics like this, just take the KISS approach.
It couldn't be easier...
The user tries the object at x,y ok?
It does not "fit" there.
So, simply "spiral" outwards, trying it in other possible places.
Just keep trying until you find one where it fits.
234
915
876
so that's like "radius 1", you see? then try "radius 2"
and so on.
It's that easy. Just keep trying until you find one that "does work".
Work from the start position outwards, so that, you find the closest one.

Core Text: Drop caps + paragraph styles: Incompatible?

I'm attempting to draw a richly laid out text view on iPhone that features:
Custom paragraph spacing (kCTParagraphStyleSpecifierParagraphSpacing)
Custom paragraph first-line indentation (kCTParagraphStyleSpecifierFirstLineHeadIndent)
Justified alignment (kCTParagraphStyleSpecifierAlignment)
Finally, a drop cap on my first paragraph
I'm using OHAttributedLabel. The first three points I achieved without much trouble by just setting some paragraph style attributes on my NSAttributedString.
The drop cap I managed to implement by hacking OHAttributedLabel:
Cut out a rectangular region out of the main paragraph's CGMutablePathRef the size of the drop cap by adding an extra CGPathAddRect, as detailed in this excellent blog post.
Drawing the large character in this region with an extra CTFrameDraw call.
My problem: The paragraph styles and the custom text path are incompatible. When I cut a rectangular chunk out of the main text's path, all the paragraph styles seem to get thrown away.
Does anyone know a way to make them work together? Or can anyone think of another way to implement drop caps? (Short of using a UIWebView + CSS, which I'd rather not have the overhead of!)
Thanks!
You can use straight Core Text to achieve this, in the following post I explain the use of 2 framesetters to lay out text with drop caps in a UIView. In the code example (there's also a link to a github repo) you'll be able to see where the paragraph styles are created and applied to the main text view.
https://stackoverflow.com/a/14639864/1218605

XNA drawing text on screen

Is there a way to draw a long text on the screen using SpriteBatch.DrawString? I mean inserts new lines when comes to the end of the screen.
I'd suggest looking at XNAwiki - TextRendering.
Inserting new lines is something you'd have to calculate yourself it's not something you an do automatically with the XNA framework, but yes it's possible to write code to do that.
One way to do it would be to take the string want to write and to move through it a word at a time an measure it until you get enough words to fill the width of whatever area it is you want to fill. Once you've found that width, you'd either change the Y Position of the string you want to draw and move onto the next line or insert a new line character into the string at that point and start calculating the amount of words that should be on the next line.
A thing to pay attention to is that string manipulation is expensive and generates a lot of garbage so you should try and minimize the amount of times you do something like that. If the text is static and never changes it would be ideal to do this one and never again while the game is running.

Resources