Jump to content
GreenGirl

Drawing Automation based on formulae and range of input values?

Recommended Posts

38 minutes ago, v_kyr said:

Well I didn't draw that myself, instead I let a C program do all the tedious work here generating the SVG code as an output. So it's finally more coding a program with some procedures/functions for the needed math and then running the prog to produce the whole, instead of drawing those things manually.

 

 

@v_kyr Wow! LOL, you totally wen't Medieval on it's a##! hehehehe

That's one way to do it I suppose... Amazing work btw... huge contribution to the community. 

I may have to read up on my C to get my formulas in, but this obviously works. Kudos. 

Just wish there was a 'visual' way to have done this. 

Share this post


Link to post
Share on other sites
17 minutes ago, John Rostron said:

@v_kyr, Your C program source code managed to crash/freeze my Chrome browser on my tablet. (I am on my PC now). Could you please remove the source code from the message. Presumably this is in the zip file link.

That's just the forums Code function (<>) with plain pasted in text as C style type, so just plain formatted text and nothing from a ZIP-archive. The ZIP-Archive is seperately included as an archive attachment.


☛ Affinity Designer 1.7.3 ◆ Affinity Photo 1.7.3 ◆ OSX El Capitan

Share this post


Link to post
Share on other sites
3 minutes ago, v_kyr said:

That's just the forums Code function (<>) with plain pasted in text as C style type, so just plain formatted text and nothing from a ZIP-archive. The ZIP-Archive is seperately included as an archive attachment.

It still crashes my browser. It is the quantity of text that seems to do it.  I was suggesting that if you removed that Code section I would then be able to read that thread. Otherwise I will not be able to do so on my tablet. The Code was presumably included in the zip file so, should anyone want the code they could access it there.

John


Windows 10, Affinity Photo 1.7 and Designer 1.7, (mainly Photo), now ex-Adobe CC

CPU: AMD A6-3670. RAM: 16 GB DDR3 @ 666MHz, Graphics: 2047MB NVIDIA GeForce GT 630

Share this post


Link to post
Share on other sites
2 minutes ago, John Rostron said:

It still crashes my browser. It is the quantity of text that seems to do it.  I was suggesting that if you removed that Code section I would then be able to read that thread. Otherwise I will not be able to do so on my tablet. The Code was presumably included in the zip file so, should anyone want the code they could access it there.

I removed the source code and leaved just a one line comment inside, you might want to give it another try now, or also check if another web browser (Firefox etc.) behaves differently here for your tablet.


☛ Affinity Designer 1.7.3 ◆ Affinity Photo 1.7.3 ◆ OSX El Capitan

Share this post


Link to post
Share on other sites

@v_kyr  Also, and this is common to most programmers, even though you know what you're writing, other people don't; so especially if you're sharing code, you should always try and keep in mind that it's better to name your variables with what they are, virtually every IDE has code completion if typing more characters is the issue - but having single character variables, whilst it makes sense to you, means nothing to everyone else, unless they have to either work it out from first principles themselves, or they already knew how to do it.

So, for me, when looking at r, w, p, etc... it's not much help. 

Whereas:

if you typed radius instead of r and centre for c etc then it's obvious to everyone without having to read minds or waste time working it out from scratch. 

After all, code if for HUMANS to read, it all gets reduced to machine code by the compiler and interpreter... so why not just make it readable in the first place?

Just £0.02, doesn't detract from the effort you've gone to or the skill you've demonstrated... 

Share this post


Link to post
Share on other sites

That code was a quick take over for internal testing and initially not mean't at all for public purposes or something which can be carved in stone. So it wasn't meant for educational purposes or other audience than personal tryouts, thus it's instead pretty short coded, uncommented and inefficent hacked together. - It also wasn't meant to be used by you at all, just to give an idea how the previously shown SVG is generated.

 


☛ Affinity Designer 1.7.3 ◆ Affinity Photo 1.7.3 ◆ OSX El Capitan

Share this post


Link to post
Share on other sites
5 minutes ago, v_kyr said:

That code was a quick take over for internal testing and initially not mean't at all for public purposes or something which can be carved in stone. So it wasn't meant for educational purposes or other audience than personal tryouts, thus it's instead pretty short coded, uncommented and inefficent hacked together. - It also wasn't meant to be used by you at all, just to give an idea how the previously shown SVG is generated.

 

Ha! Okay then... cause I've worked a few bits out, but other bits... j for example... no idea. 

I'll see about coding my own then... 

Share this post


Link to post
Share on other sites
9 minutes ago, GreenGirl said:

Ha! Okay then... cause I've worked a few bits out, but other bits... j for example... no idea. 

I'll see about coding my own then... 

i, j ... etc. are commonly used as inner loop index vars, so mostly used inside loops for loop count iterations. - You better code your own prog here, maybe using Python or Swift  etc. then, for some test based approaching and using an interactive playground style environment, so you can better see what your code does.

 


☛ Affinity Designer 1.7.3 ◆ Affinity Photo 1.7.3 ◆ OSX El Capitan

Share this post


Link to post
Share on other sites

 

3 hours ago, v_kyr said:

i, j ... etc. are commonly used as inner loop index vars, so mostly used inside loops for loop count iterations. - You better code your own prog here, maybe using Python or Swift  etc. then, for some test based approaching and using an interactive playground style environment, so you can better see what your code does.

 

Sure, I got that it was a loop variable, but I didn't know what the loop was trying to do. 

Share this post


Link to post
Share on other sites

Those are used inside of for loops in the calculations for several tic marks, mainly for applying the scale ranges, distances and gaps of scale subdivisions.

Don't know if you ever programmed something on your Mac and thus if you possibly have Apple's XCode and the appropriate Apple developer command line tools installed on your Mac (?), if yes, then you can throw and run that little program through the debugger there, setting some breakpoints, inspecting the program flow and the variable values during certain program stages. - Alternatively you could also use Microsofts Visual Studio Code editor for MacOS and run/debug with that one, as far as you have Apple developer command line tools installed.

What do you want to use for your program (which programming or scripting language)?


☛ Affinity Designer 1.7.3 ◆ Affinity Photo 1.7.3 ◆ OSX El Capitan

Share this post


Link to post
Share on other sites
18 hours ago, v_kyr said:

I removed the source code and leaved just a one line comment inside, you might want to give it another try now, or also check if another web browser (Firefox etc.) behaves differently here for your tablet.

Thanks for that, I can now read the thread. I tried Firefox, but by the time I did, you had removed the C source.

I have used many programming languages in my time, beginning with Fortran in the sixties, but I have never actually programmed in C or any of its variants.

John


Windows 10, Affinity Photo 1.7 and Designer 1.7, (mainly Photo), now ex-Adobe CC

CPU: AMD A6-3670. RAM: 16 GB DDR3 @ 666MHz, Graphics: 2047MB NVIDIA GeForce GT 630

Share this post


Link to post
Share on other sites

Update:

Okay, so after lots of testing, I can confirm that Designer's SVG support is broken. Both exporting AND importing. It doesn't abide by what's been written in the SVG and editing the import doesn't maintain the transformations.

I've now tried:

Sketch - imports the edited SVG perfectly, but when you try and change the text, the alignment of the text gets changed.

Gravit Designer Pro - This exports completely unformatted SVG XML BUT the SVG is perfect and the resulting file can be imported correctly (no wonky translations) into EVERYTHING, including Designer. However, again, upon editing any of the rotated text, the centreline doesn't get adhered to.

Adobe Illustrator CC 2019 - Same thing, imports the SVG that was created in Designer and edited with spreadsheet info perfectly, but again doesn't support correct text alignment when you change the text.

 

So... after all that, it appears that I have to EITHER:

a) Find some way to change the text in the SVG to the 'input numbers' from the spreadsheet so that the rotation will work correctly, but understand that text can't be edited, resized or anything when back in a Vector app...

 

or 

 

b) write code to spit out perfect syntactical SVG (so I have to learn TWO things) and use that to generate the SVG that Designer can import and edit.

 

...unless anyone knows how to solve for 'a'...?

 

Share this post


Link to post
Share on other sites
7 minutes ago, John Rostron said:

Thanks for that, I can now read the thread. I tried Firefox, but by the time I did, you had removed the C source.

I have used many programming languages in my time, beginning with Fortran in the sixties, but I have never actually programmed in C or any of its variants.

John

Here's the code.

kreisskala.c

Share this post


Link to post
Share on other sites
17 hours ago, v_kyr said:

That code was a quick take over for internal testing and initially not mean't at all for public purposes or something which can be carved in stone. So it wasn't meant for educational purposes or other audience than personal tryouts, thus it's instead pretty short coded, uncommented and inefficent hacked together. - It also wasn't meant to be used by you at all, just to give an idea how the previously shown SVG is generated.

 

Sure, but now to make it 'readable' you'd have to go over it again... whereas the best approach would have just been make it readable from the start.

That's something I can never seem to 'convince' most programmers of... I don't know where that kind of mindset comes from, but it really strikes me as odd... lol

Share this post


Link to post
Share on other sites
21 hours ago, John Rostron said:

Having said that I am aware that a rotated object does 'remember' it's original orientation in some circumstances. I also recall that there is is a way to make it forget, but I cannot remember how! I will investigate further.

Apparently, you can reset the bounding box of your basic tic by simply pressing the '.' (period or full stop) key! One of Designer's more useful, but well-hidden features.

  1. I created an oblique line,
  2. I then rotated it to the vertical. It maintained its bounding box.
  3. Pressing the '.' key reset the bounding box.

However the exported svg from this ignored this and was the same as that produced by stage 2.

An older workaround (if your object is a closed path) is to create a box around it with the rectangle tool, and use the intersect tool on the pair. This doesn't work either. It still reverts back to stage 2 above.

I have put in a bug report on this under svg export.

John


Windows 10, Affinity Photo 1.7 and Designer 1.7, (mainly Photo), now ex-Adobe CC

CPU: AMD A6-3670. RAM: 16 GB DDR3 @ 666MHz, Graphics: 2047MB NVIDIA GeForce GT 630

Share this post


Link to post
Share on other sites
2 hours ago, GreenGirl said:

Sure, but now to make it 'readable' you'd have to go over it again... whereas the best approach would have just been make it readable from the start.

That's something I can never seem to 'convince' most programmers of... I don't know where that kind of mindset comes from, but it really strikes me as odd... lol 

As said before, that was a personal/private quick tryout hack and initially not meant for others, since I can read just from the code what that does. - If I would have coded instead something for the public I would have used another for other people easier to read and follow programming language and commented the code ...

import Cocoa

extension Double {
    /// Rounds the double to decimal places value
    func rounded(toPlaces places:Int) -> Double {
        let divisor = pow(10.0, Double(places))
        return (self * divisor).rounded() / divisor
    }
}

// Draws a tic line for a SVG <path> via the inner line commands
// M = Move to aka Mx1 y1
// L = Line to aka Lx2 y2
func drawTic(radius: Double, width: Double, tic: Double) {
    let x1: Double = radius * sin(tic)
    let y1: Double = -radius * cos(tic)
    let x2: Double = (radius + width) * sin(tic)
    let y2: Double = -(radius + width) * cos(tic)
    
    print("M\(x1) \(y1)L\(x2) \(y2)")
}

// A test call with a loop from 0.6 to 10 (excluding the 10) in 0.1 increment steps
for index in stride(from: 0.6, to: 10, by: 0.1) {
    drawTic(radius: 6.0, width: 2.5, tic: 3.0)
}

...

... then probably more something you can interactively follow and try out, like Swift for a Swift Playground ...

swift-playground.jpg.653583d86b65d074c3dacd98fe6e9a6b.jpg


☛ Affinity Designer 1.7.3 ◆ Affinity Photo 1.7.3 ◆ OSX El Capitan

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

Please note the Annual Company Closure section in the Terms of Use. These are the Terms of Use you will be asked to agree to if you join the forum. | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.