Reply to topic  [ 79 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6  Next
Dipping the toe in - Swift, Xcode, adaptive layouts 
Author Message
What's a life?
User avatar

Joined: Thu Apr 23, 2009 6:27 pm
Posts: 12251
Reply with quote
Fogmeister wrote:
Also, if don't think you need to put the day night image into the mask layer. You should just be able to set the mask as the mask property on it.


It tried that. The mask rotated too, so it's a child of the masked layer. I also will be needing some kind of shadow in there to suggest a bit of depth, and my thinking is that should be using the same mask.

I really wish there was a GUI way to build all of this. It seems crazy that there isn't.

_________________
All the best,
Paul
brataccas wrote:
your posts are just combo chains of funny win

I’m on Twitter, tweeting away... My Photos Random Avatar Explanation


Last edited by paulzolo on Mon Nov 17, 2014 12:16 pm, edited 1 time in total.



Sat Nov 15, 2014 10:56 pm
Profile
What's a life?
User avatar

Joined: Thu Apr 23, 2009 7:26 pm
Posts: 17040
Reply with quote
There is. It's called PaintCode. It's moderately expensive.


Sat Nov 15, 2014 11:16 pm
Profile
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 7:35 pm
Posts: 6580
Location: Getting there
Reply with quote
jonbwfc wrote:
There is. It's called PaintCode. It's moderately expensive.

Hmm, I have mixed feelings about things like paint code.

For things like this clock it means that every frame of the animation etc it's going to redraw the entire clock. Face, hands, day night thing, everything.

For something simple this might be fine but for something like this I can't see any benefit.

What you end up with is unchangeable. The code is unintelligible. The numbers used are laughable. Everything is done as one draw so editing it later is difficult. The last time I looked it wasn't really possible tip use images in an effective way.

Also, having everything as one draw process will decrease performance.

It may be worth a try though.

_________________
Oliver Foggin - iPhone Dev

JJW009 wrote:
The count will go up until they stop counting. That's the way counting works.


Doodle Sub!
Game Of Life

Image Image


Sun Nov 16, 2014 9:07 am
Profile WWW
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 7:35 pm
Posts: 6580
Location: Getting there
Reply with quote
Also, layers have built in shadows. Take a look at the shadowColour, radius, offset etc.

Apply the shadow to the mask layer (i think)

_________________
Oliver Foggin - iPhone Dev

JJW009 wrote:
The count will go up until they stop counting. That's the way counting works.


Doodle Sub!
Game Of Life

Image Image


Sun Nov 16, 2014 9:10 am
Profile WWW
What's a life?
User avatar

Joined: Thu Apr 23, 2009 6:27 pm
Posts: 12251
Reply with quote
I saw PaintCode - I’m not sure about it. I have iDraw, and that dumps out paths etc., but the numbers are all fixed, so if you’re wanting to scale, it could be a problem.

Anyho, this is where I am with it:
ImageClick for large view - Uploaded with Skitch

I want to change the day/night graphics a bit. Also noticing that on proper analogue clocks, the aperture is not semi-circular:
ImageClick for large view - Uploaded with Skitch

So, in the interests of “doing it properly”, I’ll be changing the mask.

Someone else just asked me if I will be making an Apple Watch face out of it. :shock: :D

_________________
All the best,
Paul
brataccas wrote:
your posts are just combo chains of funny win

I’m on Twitter, tweeting away... My Photos Random Avatar Explanation


Mon Nov 17, 2014 12:25 pm
Profile
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 7:35 pm
Posts: 6580
Location: Getting there
Reply with quote
How doo you mean not semi circular? Is it less than half but still a circle or not a circle?

You could just change the start and end angle of the path in my code to create less or more of a circle.

_________________
Oliver Foggin - iPhone Dev

JJW009 wrote:
The count will go up until they stop counting. That's the way counting works.


Doodle Sub!
Game Of Life

Image Image


Mon Nov 17, 2014 2:56 pm
Profile WWW
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 7:35 pm
Posts: 6580
Location: Getting there
Reply with quote
Also, looks awesome[WHITE SMILING FACE]

Did you create all the images yourself?

_________________
Oliver Foggin - iPhone Dev

JJW009 wrote:
The count will go up until they stop counting. That's the way counting works.


Doodle Sub!
Game Of Life

Image Image


Mon Nov 17, 2014 2:57 pm
Profile WWW
What's a life?
User avatar

Joined: Thu Apr 23, 2009 6:27 pm
Posts: 12251
Reply with quote
Fogmeister wrote:
Also, looks awesome[WHITE SMILING FACE]

Did you create all the images yourself?


Yes - all my own work. My first thing is graphics and photos, which is why I've been building it like I have - some code, some images, etc. etc.. All the images for my clock were created in Affinity Design.

To answer your second question - if you look at the photo of the silver clock above, you'll see that the day/night thing is a semi-circle, with two smallest ones along the bottom - I've seen this a lot. I've actually got this working, screen shot later when I've finished tinkering with the paths so it looks how I want it to.

_________________
All the best,
Paul
brataccas wrote:
your posts are just combo chains of funny win

I’m on Twitter, tweeting away... My Photos Random Avatar Explanation


Mon Nov 17, 2014 4:41 pm
Profile
What's a life?
User avatar

Joined: Thu Apr 23, 2009 6:27 pm
Posts: 12251
Reply with quote
Looks like to get what I want, I’m going to have to read my way through this http://www.raywenderlich.com/33193/core ... -and-paths because I’ll need less than full semi circles! :shock: :lol:

_________________
All the best,
Paul
brataccas wrote:
your posts are just combo chains of funny win

I’m on Twitter, tweeting away... My Photos Random Avatar Explanation


Tue Nov 18, 2014 10:11 am
Profile
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 7:35 pm
Posts: 6580
Location: Getting there
Reply with quote
Crap! Made a mistake in my drawing, what I have labelled as "radius" is not the radius.

It's actually half the distance that the arc covers. I'll keep it meaning that as it actually makes it easier to work with. Just be aware of it.


Yeah paths are sometimes a pain but not too hard to work out if you spend time with pen and paper to begin with.

I'm guessing you need the sizes to be relative too (i.e. the circles will be bigger on an iPad than iPhone). So you can't do absolute sizes, you need to calculate absolute sizes at run time.

So...

First thing you need to do is work out how to do the entire path in one stroke.

Then it's just a matter of working out how to get the values for startAngle, endAngle and center when you're drawing the arcs.

Image
Image

The first drawing shows how to think of the path as a single stroke.
The rest of it is working out angles and stuff.
Anyway, the last part of the second image shows how you can do arcs from a certain point with a given angle.

Create a method something like...

Code:
- (void)addArcToBezierPath:(UIBezierPath *)bezierPath withAngle:(CGFloat)angle startPoint:(CGPoint)startPoint distance:(CGFloat)distance clockwise:(BOOL)clockwise
{
    CGFloat tanAngle = tan(angle);

    CGPoint center;
    CGFloat startAngle;
    CGFloat endAngle;

    CGFloat radius = (distance * 0.5) / sin(angle);

    if (clockwise) {
        center = CGPointMake(startPoint.x + radius, startPoint.y + (radius / tanAngle));
        startAngle = 3.0 * M_PI / 2.0 - angle;
        endAngle = 3.0 * M_PI / 2.0 + angle;
    } else {
        center = CGPointMake(startPoint.x - radius, startPoint.y + (radius / tanAngle));
        startAngle = 3.0 * M_PI / 2.0 + angle;
        endAngle = 3.0 * M_PI / 2.0 - angle;
    }

    [bezierPath addArcWithCenter:center radius:radius startAngle:startAngle endAngle:andAngle clockwise:clockwise];
}


This will add a circle with a given angle (where angle * 2 is the angle of the entire arc) from a given startPoint and with a given radius and either clockwise or anti-clockwise.

So your path can be built something like...

Code:
Create bezierPath.
Move to point (the right hand point of the entire path) (100, 0) for example
[self addArcToBezierPath:bezierPath withAngle:M_PI / 2.0 startPoint:currentPoint distance:100 clockwise:NO];
Now you will be at the left hand point in the path
Add line to point (10, 0) //or whatever it is
[self addArcToBezierPath:bezierPath withAngle:M_PI / 2.3 startPoint:currentPoint distance:30 clockwise:YES];
Add line to point (60, 0) // or whatever
[self addArcToBezierPath:bezierPath withAngle:M_PI / 2.3 startPoint:currentPoint distance:30 clockwise:YES];
Close Path

_________________
Oliver Foggin - iPhone Dev

JJW009 wrote:
The count will go up until they stop counting. That's the way counting works.


Doodle Sub!
Game Of Life

Image Image


Last edited by Fogmeister on Tue Nov 18, 2014 5:01 pm, edited 1 time in total.



Tue Nov 18, 2014 11:01 am
Profile WWW
What's a life?
User avatar

Joined: Thu Apr 23, 2009 6:27 pm
Posts: 12251
Reply with quote
Thanks, Oli. :D I wasn’t asking you to do all the work for me. It’s very good of you to do so, though.

What I found out the other day was the path drawing works very much like it does in apps I am used to - Illustrator, Fontographer, Font Lab, etc.. That is to punch a hole out of something, you use clockwise/anticlockwise directions. So what I have done is something like this:

ImageClick for large view - Uploaded with Skitch

The big semi-circle arc is drawn in one direction, the smaller ones the other. The result is that the smaller ones are subtracted from the larger one, resulting in this:
ImageClick for large view - Uploaded with Skitch

Far from perfect, I know, but it’s something I worked out myself after a pile of reading and Googling. Anyway, Art decrees that those smaller semi circles should be, perhaps, a smaller (say 1/4 circles), so I’m off to do some thinking about that.

I’ll post another screen shot of the app when I’ve done this.

FWIW - this is the furthest I have ever got with am XCode project. I’ve dabbled before in the past, and when Apple had the AppleScript studio as part of it, I used that for a couple of things. This time, I’ve passed anything I’ve ever done before with it.

_________________
All the best,
Paul
brataccas wrote:
your posts are just combo chains of funny win

I’m on Twitter, tweeting away... My Photos Random Avatar Explanation


Tue Nov 18, 2014 12:08 pm
Profile
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 7:35 pm
Posts: 6580
Location: Getting there
Reply with quote
Ah, I didn't know that about "subtracting" paths. Good to know :)

No worries though, I was bored so it gave me something to do :D

_________________
Oliver Foggin - iPhone Dev

JJW009 wrote:
The count will go up until they stop counting. That's the way counting works.


Doodle Sub!
Game Of Life

Image Image


Tue Nov 18, 2014 1:11 pm
Profile WWW
What's a life?
User avatar

Joined: Thu Apr 23, 2009 6:27 pm
Posts: 12251
Reply with quote
Ok - I’m trying to follow the example above, and bend it to my will. What is flooring me is the Radians. I’ve never worked with them before, and I have a real problem trying to see what things like M_PI/2 actually mean. I’m used to Degrees.

So, for example, in your function (which I’ve converted to Swift), it’m calling it like this:

Code:
addArcToBezierPath( pathRef , angle: CGFloat(M_PI/2) , startPointX: 0.0 , startPointY:sizeOfDialRadius , distance:sizeOfDial , clockwise: false )


I’m not sure what the angle: CGFloat(M_PI/2) means in this context - firstly, what’s that in degrees, and secondly, I can’t see what it’s doing in the context of the functuon. What I am getting is the semi-circle at a rakish angle, not with the base horizontal. I am assuming that if I can somehow push 180 degrees, I’ll get what I want.

Again in the function that adds the Bezier path, I have this:
Quote:
startAngle = ((2.0 * CGFloat(M_PI)) / 3.0) - angle


I’m not at a loss what that calculation is doing - I just can’t see what it’s doing.

What I have got (and I’ve been using this a little) is a function that converts degrees to radians:
Code:
func radians( myAngle: CGFloat ) -> CGFloat {
return myAngle * CGFloat(M_PI/180)
}


You see my point, I hope. I’ve been trying to substitute the radians function for various PI based calculations, and getting nowhere:
Code:
addArcToBezierPath( pathRef , angle: radians(180), startPointX: 0.0 , startPointY:sizeOfDialRadius , distance:sizeOfDial , clockwise: false )


I’ll keep on tinkering with this, but this is stumping me.

_________________
All the best,
Paul
brataccas wrote:
your posts are just combo chains of funny win

I’m on Twitter, tweeting away... My Photos Random Avatar Explanation


Tue Nov 18, 2014 3:41 pm
Profile
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 7:35 pm
Posts: 6580
Location: Getting there
Reply with quote
Oops, sorry, got that equation wrong, will explain it properly in here.

Trigonometry functions all work in radians. Also, all rotation and transforms in Objective-C and Swift use radians too.

In radians a full circle is 2*pi radians.

This means that half a circle is pi radians.

One quarter of a circle is pi / 2 radians.

And so on.

Your function will convert correctly.

In all my examples, theta is in radians.

Where the equation comes from

The bit where I say startAngle = ((2.0 * CGFloat(M_PI)) / 3.0) - angle comes from the diagram on the left hand side of the second picture.

The diagram here is just the scaffolding part of the arc that is being drawn. I left the arc out purely so I could concentrate on the bit I wanted because we needed to find the center for the function. The center of the arc in the diagram is the point where the two triangles meet at the bottom.

The line coming straight out to the right from that point is where all the angles are measured from in the UIBezierPath functions. So in the UIBezierPath functions 0 radians (0 degrees) is to the right and pi/2 radians (90 degrees) is straight down.

From the diagram the startAngle goes from this "measurement" line to the hypotenuse of the left triangle. But we need to know what that is in terms of theta. You can get that angle by starting at 3pi/2 radians (270degrees) (straight up) and subtracting theta from it.

That's where I get 3pi/2 - angle.

Similarly for the endAngle we can start at 3pi/2 and add the theta angle.

Again though, all you need to do is work in radians. So take your value of theta (the angle) in degrees, convert it to radians and then plug into that function.

It doesn't matter if you think in degrees or radians as long as the input of that function is in radians.

If that makes sense?

OMG, reading through this again I just realised I messed up that function. It should be 3pi/2 not 2pi/3. Sorry :(

Just to explain what 3pi/2 means...

3pi/2 = 3 * (pi/2)
pi/2 (from above) is quarter of a circle (90 degrees)
so
3 * (pi/2) = 3 * quarter of a circle (270 degrees)

Easier to understand when the moron who wrote it didn't get it wrong in the first place (sorry).

_________________
Oliver Foggin - iPhone Dev

JJW009 wrote:
The count will go up until they stop counting. That's the way counting works.


Doodle Sub!
Game Of Life

Image Image


Tue Nov 18, 2014 5:00 pm
Profile WWW
What's a life?
User avatar

Joined: Thu Apr 23, 2009 6:27 pm
Posts: 12251
Reply with quote
I used Oli’s revised formula, and noticed that it drew the paths upside down. Thjat’s OK - I inverted the startAngle and endAngle variables, and it worked as expected. :D Thanks for helping on that.

I decided, though, that two smaller semi-circles were a bit too obstructive, so I amended code from this page which draws an arc based on a supplied rectangle.
http://www.raywenderlich.com/33193/core ... -and-paths
This means that I can adjust the width/height of the smaller “bumps” based on coordinates I feed into it. The result:
ImageClick for large view - Uploaded with Skitch

Which is pretty much what I wanted from the start. I need to do a little juggling with numbers so that the height of the arc is calculated relatively to the size of the dial, so that it looks the same on an iPad, though, TBH, it’s not looking too bad as it stands with fixed numbers.

Anyway, I’m happy with how it looks now.

Oli mentioned changing the graphics being as “easy as changing a string” - I’ve got to consider that idea more. Having a couple of options would be nice - it’s something I’ll be considering as this moves along, especially if I decide to push it into an Apple Watch app in the future. I have a couple of ideas I’d like to add - possibly a little more modern looking than this one.

_________________
All the best,
Paul
brataccas wrote:
your posts are just combo chains of funny win

I’m on Twitter, tweeting away... My Photos Random Avatar Explanation


Wed Nov 19, 2014 10:27 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 79 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6  Next

Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software.