• What Do You Need Help With? V6
    7,544 replies, posted
[QUOTE=NixNax123;46168143]So this is my Image constructor so far: [code] public Image( String filename, String ext, int width, int height, Effect effect) { this.filename = filename; this.width = width; this.height = height; this.effect = effect; ext = ext.toLowerCase(); switch(ext) { case "bmp": case "bitmap": // load the bitmap file break; } }[/code] How would I load that bitmap file, if class Bitmap is a subclass of class Format, and has a method load()?[/QUOTE] You probably want to have this.buffer which is a dynamic array for the pixels and make Format.load either return an array like that or otherwise fill one?
[QUOTE=esalaka;46168227]You probably want to have this.buffer which is a dynamic array for the pixels and make Format.load either return an array like that or otherwise fill one?[/QUOTE] You're right, and then give buffer to an image and then draw it! That's a great idea, thank you very much!
[QUOTE=KinderBueno;46168089]My upload speed is only 10.32 Mbps, that would be mad slow wouldn't it?[/QUOTE] If you're only wanting to prototype it, there's nothing wrong with hosting it on your local machine. If you're looking to actually distribute the application, however, I would recommend looking into buying a server and just hosting it from there. [editline]6th October 2014[/editline] In actual response to your question though, if it's just plain text than I doubt 10 megs would be slow unless you've got a lot of users.
[QUOTE=NixNax123;46168246]You're right, and then give buffer to an image and then draw it! That's a great idea, thank you very much![/QUOTE] I could also give Format a field called buffer, and have my functions just fill that field, and then get that field from Format in the Image class? Sort of like this: [code]public abstract class Format { /** * array holding image pixels, sized width x height */ public byte[][] buffer; ...[/code][code]public class Bitmap extends Format { /** * Loads a Bitmap image. */ @Override public void load() { byte[][] data = new byte[width][height]; super.buffer = data; }[/code] this should work, right?
[QUOTE=LilDood;46167749]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 [/code] 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.[/QUOTE] ohmigosh! I understand now! And it works :D Thank you so much for your help!! edit: I just turned on my calculator and saw on the history I had literally done the calculation to convert seconds 683/10 seconds in the last post I'm just not used to thinking with % and //! lol Thanks for helping me understand this
Alright, progress! And lots of it! [code] /** * Loads a Bitmap image. * @param filename the name of the file to be loaded * @throws FileNotFoundException */ @Override public void load(String filename) throws FileNotFoundException, IllegalArgumentException { // fetch bitmap file FileInputStream fin = null; try { fin = new FileInputStream(filename); } catch (FileNotFoundException ex) { System.err.printf("ERROR: File %s not found!\n", filename); Logger.getLogger(Bitmap.class.getName()).log(Level.SEVERE, null, ex); } // get file data in bytes byte bdata[] = new byte[54]; try { fin.read(bdata); } catch (IOException ex) { System.err.printf("ERROR: File %s is unreadable!\n", filename); Logger.getLogger(Bitmap.class.getName()).log(Level.SEVERE, null, ex); } // convert byte data to hex StringBuilder sb = new StringBuilder(); for (byte b : bdata) sb.append(String.format("%02X ", b)); String[] data = sb.toString().split(" "); if(!(data[offset].equals("42") && data[offset+1].equals("4D"))) isValid = false; // rest of data check if(!isValid) { System.err.printf("ERROR: File %s is not" + " registered as a bitmap!\n", filename); Logger.getLogger(Bitmap.class.getName()).log(Level.SEVERE, null, new IllegalArgumentException()); } }[/code]I just wanted to say thanks a ton for all the help you guys gave me! I really value it, and it helped me learn so much! Thank you all!
Hey guys, I'm having a bit of trouble with building a release program in Visual Studio 2013. The problem is that when I let my friend test the program when I send them the release build, it throws an 0xc000007b error, which is regarded as mixed 32bit/64bit .dlls. I used Dependency Walker to figure out where it was throwing the exception, and it was at opengl32.dll. My scope of computer programming is no where near trying to solve this problem, and Google has lead me to various false ends. I'm also very confused as to why I do not get this message, but they do, even when I had them install the latest .NET framework and redistributables packages from Microsoft.
So I'm having trouble converting a one-dimension array into a two dimension array. [code] // send pixels to the buffer array this.buffer = new byte[this.width][this.height]; for(int i = 0; i < this.width; i++) { for(int j = 0; j < this.height; j++) { this.buffer[i][j] = (byte) (Integer.parseInt(imageData[this.width*i + j + 54], 16) & 0xFF); System.out.print(this.buffer[i][j] + " "); } System.out.println(); }[/code] The + 54 is because this is image data after a header of 54 bytes. How do I convert the image data to an array of size [width][height]? My current method is not working.
[QUOTE=NixNax123;46171341]So I'm having trouble converting a one-dimension array into a two dimension array. [code] // send pixels to the buffer array this.buffer = new byte[this.width][this.height]; for(int i = 0; i < this.width; i++) { for(int j = 0; j < this.height; j++) { this.buffer[i][j] = (byte) (Integer.parseInt(imageData[this.width*i + j + 54], 16) & 0xFF); System.out.print(this.buffer[i][j] + " "); } System.out.println(); }[/code] The + 54 is because this is image data after a header of 54 bytes. How do I convert the image data to an array of size [width][height]? My current method is not working.[/QUOTE] Reverse the order of i and j when accessing the 1-dimensional array. Change this [code]Integer.parseInt(imageData[this.width*i + j + 54], 16)[/code] to [code]Integer.parseInt(imageData[this.width*j + i + 54], 16)[/code]
I am trying to get an image (a car) to move along a path (a road) in Java. I was thinking of describing the track with a parametric equation, for example for a circular track: x(t)=sin(t) y(t)=cos(t) I would then increase the t in small steps to get the new x and y coördinate of the car, which would then follow the road. For rotation of the car in the corners I was thinking of using the derivative of the function, so that the car 'turns' as the road does. (This is purely an idea for now, and I have not tried if this works, if there are easier ways to do this, please do tell me) The problem arises when I think of the shape I want the track to have, namely this shape: [img]http://cnx.org/resources/4a3fd1e69ac1e6e1d29a062f27a0d6c2/graphics51.png[/img] (ignore the scale) I am having a hard time describing this shape using a parametric equation, the x-coördinate is not the problem (using a 5sin(t) or 5cos(t)) but the movement along the y-axis is what I am struggling to get. The y(t) would have to look something like this: [img]http://i5.minus.com/iY5XyBhFefNEi.png[/img] Is this even mathematically possible? Or should I look for another way to solve this?
I realized i need to use WebSockets for my project now. Is PHP Sockets and WebSockets same thing? Can I setup WebSockets on PHP Server? P.S - I know I ask a lot of questions, but unfortunately I submitted Project Proposal already and there is no way back, gotta lash through this idea now so have to learn whatever is necessary.
Does anyone here use OneNote/Evernote for taking notes on a solo project? I use a pad of paper for every project, and reference that. But I'm now guessing it's easier now to use something like Evernote.
[QUOTE=rakker;46172832]I am trying to get an image (a car) to move along a path (a road) in Java. I was thinking of describing the track with a parametric equation, for example for a circular track: x(t)=sin(t) y(t)=cos(t) I would then increase the t in small steps to get the new x and y coördinate of the car, which would then follow the road. For rotation of the car in the corners I was thinking of using the derivative of the function, so that the car 'turns' as the road does. (This is purely an idea for now, and I have not tried if this works, if there are easier ways to do this, please do tell me) The problem arises when I think of the shape I want the track to have, namely this shape: [img]http://cnx.org/resources/4a3fd1e69ac1e6e1d29a062f27a0d6c2/graphics51.png[/img] (ignore the scale) I am having a hard time describing this shape using a parametric equation, the x-coördinate is not the problem (using a 5sin(t) or 5cos(t)) but the movement along the y-axis is what I am struggling to get. The y(t) would have to look something like this: [img]http://i5.minus.com/iY5XyBhFefNEi.png[/img] Is this even mathematically possible? Or should I look for another way to solve this?[/QUOTE] It's very possible, but you have to use a piecewise function. Just simulate your car on an infinite straight track (just a number, really), then you can project that onto the track shape with a modulus and a few if/elses. Same for the rotation, since while this function is continuous and smooth the derivative is still not something that is easy to describe in a single formula. (Technically you can use the theta function (the one that's an integral over the Dirac delta from negative infinity) to describe this, but that's really just a glorified if/else.) [editline]7th October 2014[/editline] [QUOTE=Drak_Thing;46173139]Does anyone here use OneNote/Evernote for taking notes on a solo project? I use a pad of paper for every project, and reference that. But I'm now guessing it's easier now to use something like Evernote.[/QUOTE] I usually use a simple mind map program, since it's easy to keep track of sub-tasks that way. Lately I've only been doing very modular programming though, and the self-contained modules are simple enough to just keep track without notes.
[QUOTE=Tamschi;46173276]It's very possible, but you have to use a piecewise function. Just simulate your car on an infinite straight track (just a number, really), then you can project that onto the track shape with a modulus and a few if/elses. Same for the rotation, since while this function is continuous and smooth the derivative is still not something that is easy to describe in a single formula. (Technically you can use the theta function (the one that's an integral over the Dirac delta from negative infinity) to describe this, but that's really just a glorified if/else.) [editline]7th October 2014[/editline] I usually use a simple mind map program, since it's easy to keep track of sub-tasks that way. Lately I've only been doing very modular programming though, and the self-contained modules are simple enough to just keep track without notes.[/QUOTE] Could you perhaps elaborate on 'projecting the car using a modulus'? I have never used piecewise functions, so I have no idea on how to do this, thank you very much for your insight though. Is there anywhere I can read up on this concept, or could you perhaps explain it in a bit more detail? Sorry for all the questions.
You basically redefine your function for different values of x (i.e. you'll have several if statements that figure out in which range x is and what that function should look like). I tinkered a bit and came up with half a solution for your problem :v: [IMG]http://quicklatex.com/cache3/ql_d66a07118a1fe2f232e8ac083858b7be_l3.png[/IMG] [url]https://www.desmos.com/calculator/15c3cacv3a[/url] The parameters can be changed to make a longer track, it's also possible to make a wider track I think, didn't look into that. You could use this function to compose [I]another[/I] piecewise function g(t) that plots f(x) for t between 0 and L/2, and -f(x) for t between L/2 and L. I think, you might have to make some adjustments to make it go the right direction when it crosses the x axis (change x to -x then or something like that) . Not sure if this is an elegant solution either...
[QUOTE=Number-41;46174368]You basically redefine your function for different values of x (i.e. you'll have several if statements that figure out in which range x is and what that function should look like). I tinkered a bit and came up with half a solution for your problem :v: [IMG]http://quicklatex.com/cache3/ql_d66a07118a1fe2f232e8ac083858b7be_l3.png[/IMG] [url]https://www.desmos.com/calculator/15c3cacv3a[/url] The parameters can be changed to make a longer track, it's also possible to make a wider track I think, didn't look into that. You could use this function to compose [I]another[/I] piecewise function g(t) that plots f(x) for t between 0 and L/2, and -f(x) for t between L/2 and L. I think, you might have to make some adjustments to make it go the right direction when it crosses the x axis (change x to -x then or something like that) . Not sure if this is an elegant solution either...[/QUOTE] Thank you, I'll try and tinker about with it a bit myself, very helpful, thanks. Now I've just gotta try and get my head around the formulae you used and try to mirror it in the x-axis [editline]7th October 2014[/editline] One thing I do not understand though, your formula uses y(x) = ... How would I go about letting a car follow this path, while there is no (t) which I could increase to get the new x and y co-ordinate. Sheesh, I am such a newbie when it comes to this. [editline]7th October 2014[/editline] I tried descibing the figure with four formulae, but I don't think the second and fourth ones are correct [img]http://i1.minus.com/iAblUXChBPHeJ.jpg[/img] First one: x(t) = -t y(t) = 2 [I]from t=0 until t=6[/I] Second one: x(t)= -6+cos(t+1/2pi) y(t)= 1+sin(t+1/2pi) [I]From t=6 until t=6+pi[/I] Third one: x(t)= -12-pi+t y(t)= 0 [I]From t=6+pi until t=12+pi[/I] Fourth one: x(t)= cos(t+1/1/2pi) y(t)= 1 + sin(t+1/1/2pi) [editline]7th October 2014[/editline] I fixed the x of the second and the fourth one second one: x(t)= -6+cos(6-t+1/2pi) fourth one: x(t)= cos(12+pi-t+1/1/2pi) Still can't figure out the y(t) for those though [editline]7th October 2014[/editline] Never mind, I figured it out, thanks for all of your help!
Man can somebody explain Git to me. Like I have made a repository on GitHub and using git I initialized the directory and everything and added stuff and tried to commit but it says that everything is up to date. But the only files on my git hub are those that initializing created. I just want to upload the entire project to it but can't seem to figure it out
try [code] git status [/code] then check if there's any untracked file that you wish to add, if you want to add it you type [code] git add <filename> [/code] or if you're confident every single file needs to be on there (you might have to adjust .gitignore to exclude some irrelevant file extensions/folders/files) [code] git add -A [/code] then you should be able to commit with [code] git commit -m "Your message" [/code] and upload it: [code] git push [/code] [editline]7th October 2014[/editline] [QUOTE=rakker;46174799]Thank you, I'll try and tinker about with it a bit myself, very helpful, thanks. Now I've just gotta try and get my head around the formulae you used and try to mirror it in the x-axis [editline]7th October 2014[/editline] One thing I do not understand though, your formula uses y(x) = ... How would I go about letting a car follow this path, while there is no (t) which I could increase to get the new x and y co-ordinate. [/QUOTE] Well it's mostly a matter of variable naming. If I write t I mean the actual arclength parameter, but you cannot feed that directly into y(x) because then you'll a) trace out only the upper half and b) if you fix a), you'll go in the positive x direction in both halves, but you want it to either clockwise or counter-clockwise So I introduce another piecewise function that keeps this in mind: [IMG]http://quicklatex.com/cache3/ql_4ac90b92fa0a114d8d44c779f3ea29eb_l3.png[/IMG] Note that t is restricted here to [0,L]
So it says it's up to date, but on my github I only have gitattributes, gitignore and the README. In Gitshell, when I type dir, it says I see those 3 things. If I type cd.. I end up in the main folder, which is what I wanted to upload. When I try git add -A it seems fine, then I try the commit and it gives me an error about one of the things and says something about not being able to build trees. Then when I type the push command it asks for the password for my bitbucket account, however I want it uploaded to github so I'm not sure how to fix it.
[QUOTE=Number-41;46174368]You basically redefine your function for different values of x (i.e. you'll have several if statements that figure out in which range x is and what that function should look like). I tinkered a bit and came up with half a solution for your problem :v: [IMG]http://quicklatex.com/cache3/ql_d66a07118a1fe2f232e8ac083858b7be_l3.png[/IMG] [url]https://www.desmos.com/calculator/15c3cacv3a[/url] The parameters can be changed to make a longer track, it's also possible to make a wider track I think, didn't look into that. You could use this function to compose [I]another[/I] piecewise function g(t) that plots f(x) for t between 0 and L/2, and -f(x) for t between L/2 and L. I think, you might have to make some adjustments to make it go the right direction when it crosses the x axis (change x to -x then or something like that) . Not sure if this is an elegant solution either...[/QUOTE] I don't think this formula is correct, it only traces gives the track as graph, not a correct projection. In a way you're solving a completely different problem here :v: What's necessary (and what rakker did a bit after your post) is a projection from the distance travelled along the track onto both x(t) and y(t), not an y(x) relation. [editline]7th October 2014[/editline] [QUOTE=Over-Run;46175838]So it says it's up to date, but on my github I only have gitattributes, gitignore and the README. In Gitshell, when I type dir, it says I see those 3 things. If I type cd.. I end up in the main folder, which is what I wanted to upload. When I try git add -A it seems fine, then I try the commit and it gives me an error about one of the things and says something about not being able to build trees. Then when I type the push command it asks for the password for my bitbucket account, however I want it uploaded to github so I'm not sure how to fix it.[/QUOTE] By using Mercurial :wink: In all seriousness though, if you're new to this get SourceTree, since Git really is not that easy to use (and I'm not saying that because of the CLI, Hg is at most 50% as complex to operate). [editline]7th October 2014[/editline] [QUOTE=Number-41;46175722]Well it's mostly a matter of variable naming. If I write t I mean the actual arclength parameter, but you cannot feed that directly into y(x) because then you'll a) trace out only the upper half and b) if you fix a), you'll go in the positive x direction in both halves, but you want it to either clockwise or counter-clockwise So I introduce another piecewise function that keeps this in mind: [IMG]http://quicklatex.com/cache3/ql_4ac90b92fa0a114d8d44c779f3ea29eb_l3.png[/IMG] Note that t is restricted here to [0,L][/QUOTE] You're unnecessarily complicating things without good reason. (That twist function can be applied here though, if the loop is cut twice either before or after the bends.) [editline]7th October 2014[/editline] Actually, it looks like you're still not getting the original question.
[QUOTE=KinderBueno;46173045]I realized i need to use WebSockets for my project now. Is PHP Sockets and WebSockets same thing? Can I setup WebSockets on PHP Server? P.S - I know I ask a lot of questions, but unfortunately I submitted Project Proposal already and there is no way back, gotta lash through this idea now so have to learn whatever is necessary.[/QUOTE] It is possible (PHP websockets, PHP sockets are something general, I suppose), but I don't think PHP should be your way to go. Post in the help megathread in the Web development section, it's just below the Programming one.
[QUOTE=Tamschi;46175966]I don't think this formula is correct, it only traces gives the track as graph, not a correct projection. In a way you're solving a completely different problem here :v: What's necessary (and what rakker did a bit after your post) is a projection from the distance travelled along the track onto both x(t) and y(t), not an y(x) relation. [/QUOTE] What I got from his question is that he wanted a curve that looks like the one in his image, depending on some parameter t. My function g(t) is (in a bit of an overcomplicated way) actually y(t) . But when I think of the actual implementation, I agree that I didn't supply x(t), and it probably is indeed easier to use trig functions. I think I had some tunnel vision because I saw the words "parametric function" and a shape that didn't look to hard to compose with some basic functions, so I just threw myself onto the problem and ignored the actual goal of his question (i.e. put a point at a spot (x(t),y(t)). In retrospect my comment didn't help all that much indeed...
[img]http://i.gyazo.com/e065287cb2ede512da9497acbb41f041.png[/img] Generally, how do games get surface wrapping textures shown above? I am trying to see if something similar is possible in the source engine, but I am not even sure what the real name for the process being shown is. If someone could just tell me that or lead me in the right direction I would be thankful.
What is a good way to check if a file is plain text (so txt, js, css and the likes)? A solution i found is to check whether there are 2 consecutive nulls in the file. If it is, it's a binary file. But this seems a bit wonky, or is it a valid way? I would rather not keep a valid file extension list and keep it correct to compare against (and extensions can be changed) To put it into context. Files need to be extracted and have some stuff in them replaced. (And it's C#)
-snip-
i fixed it and yes i did it
Working on an entity-component system thing. I have a class named Component and a child of that named PositionComponent. Both have member variables m_type. Is there any way I could access the m_type of PositionComponent if I only have a Component type pointer? I'm not sure if I can use casting as I'm not sure whether the pointer will point to PositionComponent or something else like SpriteComponent.
Is there anyway to de-serialize a property value with the name of "smbiosbiosversion" into the class property of "FirmwareVersion", so when people use the class to get information they don't have to use the long name of"smbiosbiosversion" but instead the property name of "FirmwareVersion" which is a lot more descriptive? I have tried using [XmlElement("FirmwareVersion")] and what not, but that just seems to map when you serialize the class into xml renames the element. If you need more information please let me know. [b]Scratch above - edit[/b] Looking deeper into the code I realized that it wouldn't of worked, so after some testing, ended up making an attribute that maps the powershell member/property into the correct class property. This is what the end results look like. [code] public class Bios { /// <summary> /// The current firmware version of the bios /// </summary> [PsObjectReferenceName("SMBIOSBIOSVERSION")] public string FirmwareVersion { get; set; } } [/code]
Hey guys, I know the basics of programming and I want to try to do some Java 2d programming, so I can eventually make apps for android phones. The only issue I am having is I have no idea how to structure a simple 2d game(engine). More or less I don't know how to get started, I am familiar with coding, I understand variables, loops, functions, classes etc... I just don't know where I should start building a simple 2d game.
I need to make some sort of pong game I am trying to get the movement for the little paddles right before I move onto collision. I am new to this and having trouble with keeping the paddles inside the canvas. This is my handler function for controlling movement: [code] def keydown(key): global paddle1_vel, paddle2_vel speed = 4 if key == simplegui.KEY_MAP["w"]: paddle1_vel = -speed elif key == simplegui.KEY_MAP["s"]: paddle1_vel = speed [/code] and here's the bit of code that updates the position of the paddle and checks that it's not going outside the canvas [code] if paddle1_pos >= (HEIGHT-1) - HALF_PAD_HEIGHT: paddle1_vel = 0 paddle1_pos += paddle1_vel [/code] I am basically just setting the speed to 0 if it comes near the edges, which makes it so it won't move in the other direction either. I need to ignore commands to move down if it's at the edge of the canvas, but how do I do that? [editline]12th October 2014[/editline] [QUOTE=BooTs;46205146]Hey guys, I know the basics of programming and I want to try to do some Java 2d programming, so I can eventually make apps for android phones. The only issue I am having is I have no idea how to structure a simple 2d game(engine). More or less I don't know how to get started, I am familiar with coding, I understand variables, loops, functions, classes etc... I just don't know where I should start building a simple 2d game.[/QUOTE] I'm at pretty much the same point where I know the syntax but not how to make an actual game out of it, I googled for a module that allows you to create a simple GUI and read about how to create stuff like buttons, moving objects, etc in it. Maybe search for a module that has the stuff you need and learn it to start off.
Sorry, you need to Log In to post a reply to this thread.