Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
In the Image above (Top Image), suppose the black boundary is the phone.
What i was trying to achieve is to randomly generate the red path from the top of the screen and at the same time the red line (path) moves downwards.
Notice how the red path is random and does not have a uniform shape.
My question is how do i achieve this?
I know this has something to do with the random function.
But then generating the random path has been my main obstacle since 8 hours.
I could not generate a shape at every interval of the timer with a specific x coordinate and y coordinate but then as you can see in the next image, how would i generate the line at an angle (rotated)
Have tried hard to search everywhere on the internet but failed.
I always keep stackoverflow my last destination after I fail to achieve any functionality after numerous hours.
Would really appreciate if anyone could help me out with this.
It looks like you could achieve the effect you wish by starting at the top center, and repeatedly choosing 2 random numbers: how far down to go, and how far horizontally to go (positive or negative), until you got to the bottom of the screen. You'd have to be careful not to go off either edge, or you could instead choose a random x-coordinate each step.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
So, I have searched enough, got one or two ways but failed to get an exact solution to my problem. I have an image of a body like this:
Now when tapping on different body parts, those bodyparts will be highlighted like below image:
This is a back body portion image for reference.
Now I have small images like:
To highlight the body parts. Can anyone please suggest me a way how I can achieve this. Just guide me with a way that will be enough. Thanks in advance.
It should be fairly easy, let's say the full human body is 400x800, and you got like 5 body parts, then create 5x 400x800 images with each body parts in the exact location, stack each on top of each other, the invisible layer will match and display the whole body normally.
To highlight, simply switch the image in the corresponding imageView. To handle user touch, you should have a tap gesture to figure the location, then change the correct image layer.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm working on a little project in which I would like two circles to connect through a gooey effect. I've searched the web quiet a lot and came across some examples in the form of a tabbar, or sidebar menu, but that's all fixed and not what I'm looking for.
What I basically want is the following. So there is a circle and if I drag it closely to another circle it snaps together, also known as the gooey effect.
A code sample would be the best, but a direction / approach of how to do this will help me out as well.
Interesting problem.
Off the top of my head, here is how I might handle it:
Calculate the points of intersection of the 2 circles (I found this link for that: Circle-circle intersection points)
Calculate the arc ranges of the intersecting parts of each circle.
Widen those arc ranges by a few degrees. Define the arcs for the remaining parts of each circle (The parts that would be drawn "non-gooey")
Using trig and Catmull-Rom splines, create a closed path for the outer "non-gooey" parts of each circle.
The Catmull-Rom algorithm should fill in the gaps between the 2 part-circles using smooth curves that look a lot like the "Gooey" circles you show.
I have a project on github that includes Swift code for creating Catmull-Rom splines from a series of points: Trochoid demo
That project creates open curves, not closed paths. The technique for creating smoothed closed paths using Catmull-Rom Splines is a little different. I have another Github project called RandomBlobs (Written in Objective-C) that creates smoothed closed paths. You should be able to work out how to change the Swift code to create closed paths from the Objective-C code. It's been long enough since I wrote the RandomBlobs code that I don't remember exactly what I did.
I'm not sure if the approach I describe above would be fast enough to draw in real time, but I bet it would. That TrochoidDemo project is doing a lot of trig for each animation frame, and it's animation is pretty smooth. If your project isn't smooth enough you might need to do some optimization.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I'm trying to make a game where nodes fall from the top of the screen to the bottom, which I've done by using gravity. Now I want to move some nodes from the left side to the right.
I was wondering if I could change the gravity pull on different nodes instead of them falling down the screen the gravity could pull selected nodes left to right.
I know I can do this by using a NSTimer and a function but wondering if I could do this with gravity.
I have tried googling the answer but I can't find the answer to applying two gravity pulls.
I don't think you can have 2 distinct gravity forces into the same physics world.
However if you want some node to "fall" to right you could
Apply another acceleration (same as gravity but opposite direction) to that specific body (this will cancel the gravity pull)
Apply one more acceleration versus right to the specific node.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to draw a words grid that user can select the wrods, like the image below
I think the best way is to use a UICollectionView element for draw a grid but how can I handle touch events and mark selected letters?
There is no one answer to your question. You could use individual UIButtons for each letter or set up your own touch coordinate tracking system corresponding to letters or do something completely different. It boils down to what you feel comfortable working with and your experience level. To get the ball rolling, I would suggest you take a look at this Ray Wenderlich tutorial which shows how to create a letter word game by dragging letter tiles. The tech in this tutorial will definitely help you with your project.
Updated:
If you go the button route, you can create them programmatically and pretty much do anything you want. Change their title (in your case) letter, show or hide them, track various kind of touches, and so on. For the letters and tracking touches, there are probably a number of methods of doing this. Try putting your letters on a subview while keeping track of their center coordinates. Then add a new subview over your letters to track the user's touches.
You will have to read and understand the UIGestureRecognizer Class.
Here is an example of how to get a user's screen coordinates from a touch.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I want to display audio meters on the iPad consisting of many small green, red or black rectangles. They don't need to be fancy but there may be a lot of them. I am looking for the best technique to draw them quickly. Which of the following techniques is better: text atlas in CALayers or OpenGLES or another?
Thank you for your answers before the the question was closed for being too broad. Unfortunately I couldn't make the question narrow because I didn't know which technology to use. If I had known the answer I could have made the question very narrow.
The fastest drawing would be to use OpenGLES in a custom view.
An alternative method would be to use a texture atlas in CALayers. You could draw 9 sets of your boxes into a single image to start with (0-8 boxes on), and then create the 300 CALayers on screen all using that as their content. During each frame, you switch each layer to point at the part of the texture atlas it needs to use. I've never done this with 300 layers before, so I don't know if that may become a problem - I've only done it with a half dozen or so digits that were updating every frame, but that worked really well. See this blog post for more info:
http://supermegaultragroovy.com/2012/11/19/pragma-mark-calayer-texture-atlases/
The best way to draw something repeatedly is to avoid drawing it if it is already on the screen. Since audio meters tend to update frequently, but most of their area stay the same, because audio signals are relatively smooth, you should track what's drawn, and draw only the differences.
For example, if you have drawn a signal meter with fifty green squares in a previous update, and now you need to draw forty eight green squares, you should redraw only the two squares that are different from the previous update. This should save you a lot of quartz calls.
Postpone rendering to the point where it's absolutely necessary, i. e. assuming you're drawing with CoreGraphics, use paths, and only stroke/fill the path when you have added all the rectangles to it.