1. Post #6401
    Gold Member
    NixNax123's Avatar
    August 2007
    5,133 Posts
    You could make a program to convert a .jpg to a .png or something along those lines. Or import a .png and change it to black and white.

    It seems complicated, but once you have the file input correct, you just have to learn the specifications of the file format and create your own parser/lexer. Should be relatively simple and fun with the proper documentation.
    Oooh! Good idea! I'll try that, and I'll learn stuff too! I love learning stuff like that, that's actually useful.

    Edited:

    Anyone know of a way to use regex to select whole words?
    For example, even including the quotes.

    "This is some text."
    "Yolo, swag, and bae."

    The words I want to select,

    "This is some text."
    "Yolo, swag, and bae."

    I am still in my infancy with my ruby knowledge as well as regex. So I'm trying to expand on it.
    Code:
    \s*("[^"]+"|[^ ,]+)
    that would include stuff enclosed in quotes too

    Edited:

    of course if you don't need any of that you could just use
    Code:
    \S+
    Edited:

    i could be terribly wrong though
    Reply With Quote Edit / Delete United States Show Events

  2. Post #6402
    Gold Member
    Dennab
    December 2008
    6,828 Posts
    Does anyone have any small projects that I can work on in Java that are simple to do, but just good programming practice and experience?
    Make a program that converts a number of one base (say, base 10), and converts it to another base (say, hexadecimal). No using Logarithms
    Reply With Quote Edit / Delete United States Show Events

  3. Post #6403
    Gold Member
    NixNax123's Avatar
    August 2007
    5,133 Posts
    Make a program that converts a number of one base (say, base 10), and converts it to another base (say, hexadecimal). No using Logarithms
    Okay!
    Reply With Quote Edit / Delete United States Show Events

  4. Post #6404
    Gold Member
    blacksam's Avatar
    July 2007
    2,339 Posts
    Oooh! Good idea! I'll try that, and I'll learn stuff too! I love learning stuff like that, that's actually useful.

    Edited:


    Code:
    \s*("[^"]+"|[^ ,]+)
    that would include stuff enclosed in quotes too

    Edited:

    of course if you don't need any of that you could just use
    Code:
    \S+
    Edited:

    i could be terribly wrong though
    It's all good in the hood. I was fiddling around with it, found (/(\w+)/) works for what I want.
    Reply With Quote Edit / Delete Linux United States Show Events

  5. Post #6405
    Gold Member
    NixNax123's Avatar
    August 2007
    5,133 Posts
    Make a program that converts a number of one base (say, base 10), and converts it to another base (say, hexadecimal). No using Logarithms
    blam
    Code:
    public class BaseConverter {
    
        public static String convert(int n, int radix) {
            String result = "";
            
            int v = 1;
            while(v <= n/radix) 
                v *= radix; 
    
            while(v > 0) {
                if(n < v) 
                    result += "0";
                else {
                    int place = n/v % radix;
                    if(place < 10)
                        result += place;
                    else
                        switch (place) {
                            case 10:
                                result += "A";
                                break;
                            case 11:
                                result += "B";
                                break;
                            case 12:
                                result += "C";
                                break;
                            case 13: 
                                result += "D";
                                break;
                            case 14: 
                                result += "E";
                                break;
                            case 15:
                                result += "F";
                        }
                    n -= v;
                }
                v /= radix;
            }
            
            return result;
    
        }
        public static void main(String[] args) {
            int n = 231;
            System.out.println(convert(n, 2));
            System.out.println(convert(n, 10));
            System.out.println(convert(n, 16));
        }
    }


    (:

    Edited:

    Only handles up to base 16, but it's easily modifiable to include more bases.
    Reply With Quote Edit / Delete United States Show Events

  6. Post #6406
    Write a divide and conquer sorting algorithm.
    Reply With Quote Edit / Delete Netherlands Show Events

  7. Post #6407
    Gold Member
    NixNax123's Avatar
    August 2007
    5,133 Posts
    Write a divide and conquer sorting algorithm.
    What does that mean?
    Reply With Quote Edit / Delete United States Show Events

  8. Post #6408
    What does that mean?
    A divide and conquer algorithm is one that divides one big task up into smaller tasks until it's trivial to solve, take a look at merge sort or quicksort.
    Reply With Quote Edit / Delete Netherlands Show Events

  9. Post #6409
    Gold Member
    NixNax123's Avatar
    August 2007
    5,133 Posts
    A divide and conquer algorithm is one that divides one big task up into smaller tasks until it's trivial to solve, take a look at merge sort or quicksort.
    Oh, so like binary sort!
    Reply With Quote Edit / Delete United States Show Events

  10. Post #6410
    Reply With Quote Edit / Delete Netherlands Show Events

  11. Post #6411
    Gold Member
    NixNax123's Avatar
    August 2007
    5,133 Posts
    snip
    Reply With Quote Edit / Delete United States Show Events

  12. Post #6412
    BIG TITLE
    Dennab
    November 2009
    11,564 Posts
    at my mum's engagement party last night, I met a man who owns a large software company and after some talking he said he'll give me a job programming for him over the summer. Now I've got a few months until then and I'm very rusty at C++ so I was hoping that I could get some good resources to brush up. Also he said he has some ideas for a few apps and I don't know how to develop apps.
    this is a big opportunity for me and I don't want to fuck it up.
    Reply With Quote Edit / Delete Windows 8 Australia Show Events

  13. Post #6413
    Gold Member
    NixNax123's Avatar
    August 2007
    5,133 Posts
    Make a program that converts a number of one base (say, base 10), and converts it to another base (say, hexadecimal). No using Logarithms

    i learned even more by making a GUI for it! (:
    Reply With Quote Edit / Delete United States Show Events Programming King Programming King x 1Friendly Friendly x 1 (list)

  14. Post #6414
    Gold Member
    Dennab
    December 2008
    6,828 Posts
    blam
    Code:
    public class BaseConverter {
    
        public static String convert(int n, int radix) {
            String result = "";
            
            int v = 1;
            while(v <= n/radix) 
                v *= radix; 
    
            while(v > 0) {
                if(n < v) 
                    result += "0";
                else {
                    int place = n/v % radix;
                    if(place < 10)
                        result += place;
                    else
                        switch (place) {
                            case 10:
                                result += "A";
                                break;
                            case 11:
                                result += "B";
                                break;
                            case 12:
                                result += "C";
                                break;
                            case 13: 
                                result += "D";
                                break;
                            case 14: 
                                result += "E";
                                break;
                            case 15:
                                result += "F";
                        }
                    n -= v;
                }
                v /= radix;
            }
            
            return result;
    
        }
        public static void main(String[] args) {
            int n = 231;
            System.out.println(convert(n, 2));
            System.out.println(convert(n, 10));
            System.out.println(convert(n, 16));
        }
    }


    (:
    comment your code d00d

    Edited:

    at my mum's engagement party last night, I met a man who owns a large software company and after some talking he said he'll give me a job programming for him over the summer. Now I've got a few months until then and I'm very rusty at C++ so I was hoping that I could get some good resources to brush up. Also he said he has some ideas for a few apps and I don't know how to develop apps.
    this is a big opportunity for me and I don't want to fuck it up.
    Am I the only one who has an innate distrust of business types? Like when they say they'll give you a job just for knowing them, I fear it always turns out that they work for vector marketing or some shit

    edit: read Barney Toasterstrudel
    Reply With Quote Edit / Delete United States Show Events

  15. Post #6415
    Gold Member
    NixNax123's Avatar
    August 2007
    5,133 Posts
    comment your code d00d

    Edited:



    Am I the only one who has an innate distrust of business types? Like when they say they'll give you a job just for knowing them, I fear it always turns out that they work for vector marketing or some shit

    edit: read Barney Toasterstrudel
    I commented the shit out of it, and improved the functionality, I'll post it tomorrow because I'm in bed now!
    Reply With Quote Edit / Delete United States Show Events

  16. Post #6416

    January 2011
    495 Posts
    Does anyone have any small projects that I can work on in Java that are simple to do, but just good programming practice and experience?
    https://www.reddit.com/r/dailyprogrammer
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  17. Post #6417
    johnnyaka's Avatar
    January 2012
    469 Posts
    Someone worked with EasyHook before?

    My injected DLL somehow does not get ejected, it stays in the Process.
    Already looked at their codeplex site, but did not find any answers yet.

    Is there any way to properly remove the injected DLL from the process?
    Reply With Quote Edit / Delete Windows 7 Germany Show Events

  18. Post #6418
    Gold Member
    meek's Avatar
    February 2014
    798 Posts
    I'm looking at an introductory programming class that uses Python.
    One of the tasks is writing a stopwatch. I'm having trouble with the function that formats time into a string.

    The string must have this format: A:BC:D where A is minutes, BC is seconds and D is tenths of seconds.
    I'm having trouble with it once the timer hits 1 minute. I can't find a way to reset the tens/seconds/tenths back to 00.0 and then keep counting from scratch and I dunno how else to do it. Maths has never been my strong suit.

    Here is what I have:

    Code:
    def format(t):
        timelist = [0, 0, 0, 0]
        if t < 10:
            timelist[3] = str(t)[-1]
        elif t >= 10 and t < 100:
            timelist[3] = str(t)[-1]
            timelist[2] = str(t)[-2]
        elif t >= 100 and t < 600:
            timelist[3] = str(t)[-1]
            timelist[2] = str(t)[-2]
            timelist[1] = str(t)[-3]
        elif t % 60 == 0:
            timelist[0] += 1
                
        timeText  = str(timelist[0]) + ':' + str(timelist[1]) + str(timelist[2]) + '.' + str(timelist[3])
        return timeText
    I'm not supposed to import other modules here other than the one we use for the GUI+timer. I've been googling to no avail, I'm pretty sure I'm just being retarded with numbers. But my head is starting to hurt so if someone can give me some pointers I'd appreciate it.
    Reply With Quote Edit / Delete Windows 7 Portugal Show Events

  19. Post #6419
    Gold Member
    NixNax123's Avatar
    August 2007
    5,133 Posts
    You could make a program to convert a .jpg to a .png or something along those lines. Or import a .png and change it to black and white.

    It seems complicated, but once you have the file input correct, you just have to learn the specifications of the file format and create your own parser/lexer. Should be relatively simple and fun with the proper documentation.
    Ok, so I've started out making an Image class (seemed the most logical thing to do)
    Code:
    public class Image {
        
    
        /**
         * filename for image
         */
        public String filename;
    
        /**
         * image extension
         */
        public String ext;
    
        /**
         * width of image
         */
        public int width;
    
        /**
         * height of image
         */
        public int height;
    
        /**
         * various image effects
         */
        public enum Effect {
            /*
             * no effect
            */
            NO_EFFECT,
            /*
             * black & white effect
            */
            NOIR
        }
    
        /**
         * image effect
         */
        public Effect effect;
             
        /**
         * loads and displays an image with desired effect
         * @param filename filename of image to be loaded
         * @param ext extension of image to be loaded
         * @param width width of image to be displayed
         * @param height height of image to be displayed
         * @param effect effect of image to be displayed
         */
        public Image(   String filename, 
                        String ext,
                        int width, 
                        int height,
                        Effect effect) {
            
            this.filename = filename;
            this.ext = ext;
            this.width = width;
            this.height = height;
            this.effect = effect;
            
            // not implemented yet
            // this.display(); 
        }
    But I really don't know how to set up classes in a way that makes sense. I've never been taught, and never had a good resource. So what should I do from here? Is my class alright so far? Can anyone give me an example skeleton of my class to help me out?
    Reply With Quote Edit / Delete United States Show Events

  20. Post #6420
    shrek yourself before you shrek yourself
    Duskling's Avatar
    March 2012
    1,051 Posts
    Ok, so I've started out making an Image class (seemed the most logical thing to do)
    Code:
    public class Image {
        
    
        /**
         * filename for image
         */
        public String filename;
    
        /**
         * image extension
         */
        public String ext;
        
        // image width
    
        /**
         * width of image
         */
        public int width;
        
        // image height
    
        /**
         * height of image
         */
        public int height;
    
        /**
         * various image effects
         */
        public enum Effect {
            /*
             * no effect
            */
            NO_EFFECT,
            /*
             * black & white effect
            */
            NOIR
        }
    
        /**
         * image effect
         */
        public Effect effect;
             
        /**
         * loads and displays an image with desired effect
         * @param filename filename of image to be loaded
         * @param ext extension of image to be loaded
         * @param width width of image to be displayed
         * @param height height of image to be displayed
         * @param effect effect of image to be displayed
         */
        public Image(   String filename, 
                        String ext,
                        int width, 
                        int height,
                        Effect effect) {
            
            this.filename = filename;
            this.ext = ext;
            this.width = width;
            this.height = height;
            this.effect = effect;
            
            // not implemented yet
            // this.display(); 
        }
    But I really don't know how to set up classes in a way that makes sense. I've never been taught, and never had a good resource. So what should I do from here? Is my class alright so far? Can anyone give me an example skeleton of my class to help me out?
    Everything seems alright. The file extension should be it's own class. You would have a Type ( or something ) base class and then like a PNG class or TGA class, each with their own specifications built right into the class so that you can write importers based of of those classes.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  21. Post #6421
    Gold Member
    NixNax123's Avatar
    August 2007
    5,133 Posts
    Everything seems alright. The file extension should be it's own class. You would have a Type ( or something ) base class and then like a PNG class or TGA class, each with their own specifications built right into the class so that you can write importers based of of those classes.
    That makes sense, thank you! I'll report on my progress!

    Edited:

    Everything seems alright. The file extension should be it's own class. You would have a Type ( or something ) base class and then like a PNG class or TGA class, each with their own specifications built right into the class so that you can write importers based of of those classes.
    So I'm making a Format class, and the PNG/TGA/etc classes will be subclasses of that. What methods/fields should I give to Format? I'm not quite sure.
    Reply With Quote Edit / Delete United States Show Events

  22. Post #6422
    LilDood's Avatar
    November 2008
    122 Posts
    I'm looking at an introductory programming class that uses Python.
    One of the tasks is writing a stopwatch. I'm having trouble with the function that formats time into a string.

    The string must have this format: A:BC:D where A is minutes, BC is seconds and D is tenths of seconds.
    I'm having trouble with it once the timer hits 1 minute. I can't find a way to reset the tens/seconds/tenths back to 00.0 and then keep counting from scratch and I dunno how else to do it. Maths has never been my strong suit.

    Here is what I have:

    [code]

    I'm not supposed to import other modules here other than the one we use for the GUI+timer. I've been googling to no avail, I'm pretty sure I'm just being retarded with numbers. But my head is starting to hurt so if someone can give me some pointers I'd appreciate it.
    There are two things you can do here to make your life easier.
    The first is to do with converting from seconds to minutes/seconds/tenths-of-seconds, the easy way to do this is to use the modulo operator and divide and round down, in Python the modulo operator is % and although you've used it at the bottom the else-if chain won't reach it until t is greater then 600, and even then if t is a floating point t % 60 will probably never be 0.
    The modulo operator gives you the remained when you divide by something so:
    Code:
    65 % 60 = 5
    As a minute is 60 seconds you can use this to determine how many seconds you have left over after you have your minutes.
    To get your minutes you can use // which, in Python, divides and rounds down so
    Code:
     65 // 60 = 1
    Or if you have less than a minute
    Code:
     55 // 60 = 0
    So using these you can turn a number of seconds into minutes, seconds and tenths of seconds.

    The next is formatting the numbers as a string.
    Rather than keeping track of the tens and seconds and single digits of seconds separately, the above will give you a two digit number, if you were to just use str() on it you wouldn't always get two digits e.g
    Code:
    str(5) = '5'
    Python includes some string formatting capabilities that can help you get around this.
    The simple way is to create a format string that acts as a template and then fill it in with your values, this makes use of % again, but this time in relation to strings rather than numbers so the effect is different.
    If you just had minutes and seconds you could do "%d:%d", here the %d will eventually be replaced with something, the 'd' means it will be a number and in particular an integer number.
    To actually do the replacement you would do
    Code:
     "%d:%d" % (5,6) = '5:6'
    Note: you need to put the things you're putting into the string in brackets if you have more than one item and they're placed in the string in the order they're given.

    The in order to force the seconds to be two digits you can do "%d:%02d", when replacing this will give:
    Code:
    "%d:%02d" % (5,6) = '5:06'
    Where the 02 before the d specifies that the number should always be a minimum of two digits (so you could still put 500 into the %02d just fine).

    This ended up being quite a long post but it should give you everything you need, and while I've only talked about minutes and seconds extending it to m:ss:t shouldn't be too difficult.
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events Friendly Friendly x 1 (list)

  23. Post #6423

    June 2014
    552 Posts
    I am making a chat application for Windows Desktop (C#), Android (Java) and Browser.
    What would be the best way to make sure that in all 3 clients user sends and receives messages instantly?
    I mean is there ONE service that could provide this all?
    So far I found GCM (Google Cloud Messaging) and WebSockets, however it seems that GCM is same as WebSockets except it's all automated (I think).

    I mean I could call refresh in all clients every second but that seems like a huge resource waste.
    Browsr could use Ajax I guess to get newest chat messages.

    Android could use GCM.

    But what can Windows use? I've never really properly made Windows software.

    Any suggestions?
    Thanks.
    Reply With Quote Edit / Delete Windows 7 Ireland Show Events

  24. Post #6424
    shrek yourself before you shrek yourself
    Duskling's Avatar
    March 2012
    1,051 Posts
    So I'm making a Format class, and the PNG/TGA/etc classes will be subclasses of that. What methods/fields should I give to Format? I'm not quite sure.
    I'm unsure, never really dealt with file header specifications. You would probably have variables that hold the difference, in bytes, between each part of the file header, as well as ways to store the header format.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  25. Post #6425

    December 2013
    1,797 Posts
    I've been messing around with Sublime Text 3 plugins ( my first time using Python ) and I can't seem to figure out what the args argument wants. I've tried using a mapping, which seems to be what it wants, but it gives me this error:

    Code:
    >>> view.run_command( 'example', { 'one': 1 } ) 
    Traceback (most recent call last):
      File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 543, in run_
        return self.run(edit, **args)
    TypeError: run() got an unexpected keyword argument 'one'
    Any suggestions?
    Reply With Quote Edit / Delete Windows 7 Poland Show Events

  26. Post #6426
    Gold Member
    vexx21322's Avatar
    December 2008
    10,328 Posts
    I've been messing around with Sublime Text 3 plugins ( my first time using Python ) and I can't seem to figure out what the args argument wants. I've tried using a mapping, which seems to be what it wants, but it gives me this error:

    Code:
    >>> view.run_command( 'example', { 'one': 1 } ) 
    Traceback (most recent call last):
      File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 543, in run_
        return self.run(edit, **args)
    TypeError: run() got an unexpected keyword argument 'one'
    Any suggestions?
    it means your method definition 'run' doesn't accept keyword arguments.
    Reply With Quote Edit / Delete Windows 7 United States Show Events Programming King Programming King x 1 (list)

  27. Post #6427

    December 2013
    1,797 Posts
    it means your method definition 'run' doesn't accept keyword arguments.
    Thanks! After some searching, I found out I needed ** before the argument.
    Reply With Quote Edit / Delete Windows 7 Poland Show Events

  28. Post #6428
    Gold Member
    NixNax123's Avatar
    August 2007
    5,133 Posts
    So I'm looking at the BMP file header format (http://www.fastgraph.com/help/bmp_header_format.html), and I have a few questions.

    For the first part, the 4D42 hex, how would I interpret that? Would I just have
    Code:
    byte signature = 0x4D42;
    ?

    Also, I'm a bit confused on the whole thing in general. I completely understand bits and bytes (8 bits in a byte etc) but would the file have those bytes in binary? And if an offset is size 2 but must be 0, would that place in the file be 0000000000000000?
    Reply With Quote Edit / Delete United States Show Events Disagree Disagree x 1 (list)

  29. Post #6429
    Gold Member
    DrTaxi's Avatar
    September 2009
    5,599 Posts
    For the first part, the 4D42 hex, how would I interpret that? Would I just have
    Code:
    byte signature = 0x4D42;
    ?
    Yes, except that's two bytes.
    Also, I'm a bit confused on the whole thing in general. I completely understand bits and bytes (8 bits in a byte etc) but would the file have those bytes in binary? And if an offset is size 2 but must be 0, would that place in the file be 0000000000000000?
    The offset is the field position. The first field, the magic number 4D 42, is right at the start of the file, so at offset 0, and it has a size of 2 bytes.
    The field after that is, of course, at offset 2, so 2 bytes after the start of the file. And that happens to have a size of 4 bytes. So the next field is at offset 6, and so on.

    You might wanna take a BMP file and look at it in a hex editor.
    Reply With Quote Edit / Delete Germany Show Events

  30. Post #6430

    December 2013
    1,797 Posts
    -snip- got it working.
    Reply With Quote Edit / Delete Windows 7 Poland Show Events

  31. Post #6431
    Gold Member
    NixNax123's Avatar
    August 2007
    5,133 Posts
    Yes, except that's two bytes.

    The offset is the field position. The first field, the magic number 4D 42, is right at the start of the file, so at offset 0, and it has a size of 2 bytes.
    The field after that is, of course, at offset 2, so 2 bytes after the start of the file. And that happens to have a size of 4 bytes. So the next field is at offset 6, and so on.

    You might wanna take a BMP file and look at it in a hex editor.
    So I would have
    Code:
    byte s1 = 0x4D;
    byte s2 = 0x42;
    right?

    And I'll do that! That should help out a lot.

    Edited:

    Aha! This REALLY helps!

    Edited:

    Now that I understand how file formats work, I still need some help on creating classes and subclasses.
    This is my Format class so far:

    Code:
    public class Format {
        
        public byte[][] header;
        
        public byte[] signature;
        
        public byte[] offsets;
        
    }
    with subclass BMP
    Code:
    public class BMP extends Format {
    }

    It's probably terrible, but I really don't know how to create classes to do what needs to be done, because I don't understand what needs to be done, or what needs to go in these classes, or what methods these classes need.
    Reply With Quote Edit / Delete United States Show Events

  32. Post #6432
    Facepunch's Local Lycanthrope
    Contron's Avatar
    December 2008
    1,781 Posts
    That seems like a good design to me. You're avoiding the God object pattern by splitting up your code into separate classes, which is good.

    I would recommend that you add some abstract methods in your format classes that actually handle the saving and loading part of the format. Abstract methods are basically methods that you can define in one class, and thus any classes that extend from that class will have to provide an implementation of it.
    Reply With Quote Edit / Delete Windows 8 Jersey Show Events

  33. Post #6433
    Gold Member
    DrTaxi's Avatar
    September 2009
    5,599 Posts
    Seems good to me too, but:
    public byte[] offsets;
    What's the offsets array for?
    Reply With Quote Edit / Delete Germany Show Events

  34. Post #6434
    Gold Member
    NixNax123's Avatar
    August 2007
    5,133 Posts
    That seems like a good design to me. You're avoiding the God object pattern by splitting up your code into separate classes, which is good.

    I would recommend that you add some abstract methods in your format classes that actually handle the saving and loading part of the format. Abstract methods are basically methods that you can define in one class, and thus any classes that extend from that class will have to provide an implementation of it.
    Thank you! It's encouraging knowing that I at least got some stuff right.
    I was thinking about that, and how it does make a lot of sense, but I wasn't sure how to implement it. Thank you! Also, what do you mean "handle the saving/loading part"? I'm not quite sure what to do with it, I know in the end I want to output the image to a Swing GUI and have an option to save a file/load a file/export a file, but I will need to flesh out all of my formats before I even think about that.

    Edited:

    Seems good to me too, but:


    What's the offsets array for?
    To determine the offsets between each section of the format. I wasn't really sure to put in that class, so I just put whatever came to mind.
    Reply With Quote Edit / Delete United States Show Events

  35. Post #6435
    Gold Member
    meek's Avatar
    February 2014
    798 Posts
    [super helpful and nice post]
    Thank you so much for your reply! It helped me organise things a bit differently. Here is what I have now for the format() function:

    Code:
    def format(t):
        global minutes, seconds, tenths
        tenths  = t % 10
        seconds = t // 10
        minutes = t // 600
        timeText = '%d:%02d.%d' % ( minutes, seconds, tenths)
        return timeText
    Which is MUCH MUCH nicer than what I had lol
    I forgot to mention t is in tenths of a second, so this function is called every 0.1 seconds.

    This whole thing is a lot clearer to me now but I am still having trouble "resetting" the seconds back to start counting from 0 again once it ticks past a minute. So essentially 68.3 seconds looks like 1:68.3 instead of 1:13.8 which is what I need it to do.

    Simply assigning seconds a different value if it's higher than 59 like such:

    Code:
    if seconds > 59:
        seconds = 0
    doesn't seem to work, probably because the function reassigns seconds to t // 10 every time it is called or something? (This is all still magic to me)

    If you or someone else can help me figure out a way to do this I would be so grateful.
    Reply With Quote Edit / Delete Windows 7 Portugal Show Events

  36. Post #6436
    Facepunch's Local Lycanthrope
    Contron's Avatar
    December 2008
    1,781 Posts
    Thank you! It's encouraging knowing that I at least got some stuff right.
    I was thinking about that, and how it does make a lot of sense, but I wasn't sure how to implement it. Thank you! Also, what do you mean "handle the saving/loading part"? I'm not quite sure what to do with it, I know in the end I want to output the image to a Swing GUI and have an option to save a file/load a file/export a file, but I will need to flesh out all of my formats before I even think about that.
    By handling the loading and saving part, I mean that in each format that you add support for (for instance, your BMP class), you can add the relative code needed to loading and saving bitmap files into that class itself, and transform it into RGB or pixel data that your application can handle - independent of whatever format it was procured from.

    It's a much better way of doing this rather than having, say, a class with a large switch statement which handles loading and saving image files on the specific format.

    Edited:

    Here's an example for your base Format class:

    Code:
    public abstract class Format
    {
    	/**
    	 * Loads an image from this format.
    	 */
    	public abstract void load();
    	
    	/**
    	 * Saves an image in this format.
    	 */
    	public abstract void save();
    }
    So, if you were to implement Bitmap support (like you've done), you'd simply override these methods:

    Code:
    public class Bitmap extends Format
    {
    	/**
    	 * Loads a Bitmap image.
    	 */
    	public void load()
    	{
    		...
    	}
    	
    	/**
    	 * Saves a Bitmap image.
    	 */
    	public void save()
    	{
    		...
    	}
    }
    Reply With Quote Edit / Delete Windows 8 Jersey Show Events

  37. Post #6437
    Gold Member
    NixNax123's Avatar
    August 2007
    5,133 Posts
    I understand! Thank you!
    Now I just need to know how to load the data from a bitmap into an array of bytes and convert those bytes to rgb values, and THEN convert those rgb values into an image that I can display. I'm having a work overload.
    Reply With Quote Edit / Delete United States Show Events

  38. Post #6438
    Gold Member
    DrTaxi's Avatar
    September 2009
    5,599 Posts
    Is that a question, or are you gonna figure that out yourself?
    Reply With Quote Edit / Delete Germany Show Events

  39. Post #6439
    Gold Member
    NixNax123's Avatar
    August 2007
    5,133 Posts
    Is that a question, or are you gonna figure that out yourself?
    I think I could figure out how to load the file info in the byte array, but I'm not sure how to store that info as rgb values and convert that to an image to draw.
    Reply With Quote Edit / Delete United States Show Events

  40. Post #6440
    LilDood's Avatar
    November 2008
    122 Posts
    Thank you so much for your reply! It helped me organise things a bit differently. Here is what I have now for the format() function:

    Code:
    def format(t):
        global minutes, seconds, tenths
        tenths  = t % 10
        seconds = t // 10
        minutes = t // 600
        timeText = '%d:%02d.%d' % ( minutes, seconds, tenths)
        return timeText
    Which is MUCH MUCH nicer than what I had lol
    I forgot to mention t is in tenths of a second, so this function is called every 0.1 seconds.

    This whole thing is a lot clearer to me now but I am still having trouble "resetting" the seconds back to start counting from 0 again once it ticks past a minute. So essentially 68.3 seconds looks like 1:68.3 instead of 1:13.8 which is what I need it to do.

    Simply assigning seconds a different value if it's higher than 59 like such:

    Code:
    if seconds > 59:
        seconds = 0
    doesn't seem to work, probably because the function reassigns seconds to t // 10 every time it is called or something? (This is all still magic to me)

    If you or someone else can help me figure out a way to do this I would be so grateful.
    Every time the function is called the code in the function is run in order from top to bottom, so seconds is et to t // 10. If you were to put the if section in after seconds has been set like this:
    Code:
    def format(t):
        global minutes, seconds, tenths
        tenths  = t % 10
        seconds = t // 10
        if seconds > 59:
            seconds = 0
        minutes = t // 600
        timeText = '%d:%02d.%d' % ( minutes, seconds, tenths)
        return timeText
    Then seconds would be set to zero if it was greater than 59.

    But that's not really how you want to do it.
    When you talk about resetting back to zero, this is what you've already done for the tenths using % 10.
    When you to seconds = t // 10 you are converting from tenths of seconds to seconds.
    What you need to do next if remove the excess that you don't need which is what your are doing with the tenths already.
    For example 11 tenths is 1.1 seconds but you only need the .1 in the tenths and when you do 11 % 10 you get that 1.
    You're going to need to use both // and % on the same line in the seconds calculation and you may need to use brackets to make sure things happen in the right order.
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events Friendly Friendly x 1 (list)