• What Do You Need Help With? V6
    7,544 replies, posted
I had in mind mind yesterday to code a simple "binary lighting" algorithm using dithering error propagation, and thus I came up with this prototype: [code]//Binary dithered lighting //Looks awful on purpose draw_set_color(c_black) //propagated error var err = 0 //radius before decay var l_r_rand = 20 var l_r_fixed = 120 //decay multiplyer var l_m_decay = 4 //ambient lighting var l_ambient = 16 //for every x column for (var i = 0; i < 320; i++) { //for every y line for (var j = 0; j < 240; j++) { //total contributed light var tt_d = 0 for (var o = 0; o < instance_number(light_source); o++) { //calculate light collaboration var obj = instance_find(light_source, o) var t_d = sqrt(power(obj.x - i, 2) + power(obj.y - j, 2)) * l_m_decay //can't be over 255, but can't be lower 0 t_d = min(255, max(0, 255-t_d+random(l_r_rand)+l_r_fixed)) //add light collaboration tt_d = tt_d + (t_d) } //do ambient lighting if we're below a certain threshould tt_d = max(random(l_ambient), tt_d) //lighting 'error' propagation - we get the dithering by //propagating the error until we reach a stablished number, //in this case, since we're doing binary dithered lighting, i'll use //$000000FF, or 255 if you prefer. err = err + (tt_d & $000000FF) //(err & $FFFFFF00) checks if we have enough error propagated //(tt_d == $000000FF) fixes random spots inside 'no-decay' zone if not ((tt_d >= $000000FF) or (err & $FFFFFF00)) { draw_point(i,j) } //what is above $000000FF can't be considered error, cancel it out err = err & $000000FF } }[/code] That creates this image: [t]http://i.imgur.com/d8rX7eT.png[/t] If you blur it, you'll notice the issue at hand: [t]http://i.imgur.com/MhtrMHZ.png[/t] Is this expected behaviour? If not, how do I fix this, and is there any documentation I can go by to learn proper lighting techniques (that you know of)?
I made a maze generator using Kruskal's algorithm in java (pick wall randomly, check if cells on either side are in the same group, if not, merge them and add all cells on one side to the other's group), but it's kind of slow, it took 7 minutes to make a 500x500 cell maze. Is there a simple way to make this better? [code] public class Maze { int xSize; int ySize; int xCells; int yCells; int[][] data; //0 = wall, 1 = empty public Maze(int x, int y){ xSize = x*2+1; ySize = y*2+1; data = new int[xSize][ySize]; xCells = x; yCells = y; } void kruskal(){ LinkedList<Coordinate> walls = new LinkedList<>(); Node[][] nodes = new Node[xCells][yCells]; for(int x = 0; x<xCells; x++){ for(int y = 0; y<yCells; y++){ data[2*x+1][2*y+1] = 1; nodes[x][y] = new Node(); } } for(int x = 1; x<xSize-1; x++){ for(int y = 1+x%2; y<ySize-1; y+=2){ walls.add(new Coordinate(x,y)); } } while(!walls.isEmpty()){ int n = walls.size(); if(n%1000 == 0){ System.out.println(n); } Coordinate c = walls.remove((int)(Math.random()*walls.size())); int x = c.x; int y = c.y; Coordinate a,b; if(x%2 == 1){ a = new Coordinate(x,y-1); b = new Coordinate(x,y+1); }else{ a = new Coordinate(x-1,y); b = new Coordinate(x+1,y); } //check if same Node d = nodes[(a.x-1)/2][(a.y-1)/2]; Node e = nodes[(b.x-1)/2][(b.y-1)/2]; Node f = d; Node g = e; while(d.parent != null){d = d.parent;} while(e.parent != null){e = e.parent;} if(f!=d){f.parent = d;} //small optimization attempt, should go a bit faster the next time it hits f or g if(g!=e){g.parent = e;} if(d != e){ data[x][y] = 1; //erase wall e.parent = d; //merge } } } } [/code] The node class is just a parent variable. I'm not sure what's taking the longest, but I did set it up to show a message every 1000 walls it checked. It takes much more time per 1000 walls in a larger maze, even in the early parts when merging big trees is unlikely. I do like the way the code for this algorithm looks though, it's probably the shortest maze generator I've written. EDIT: Figured it out, picking a random element from a list of half a million elements does take a very long time. Still not sure if I can make it better. EDIT: I put the walls of each row in different lists, and put those lists in another list. Accessing elements deeper in linkedlists takes longer than shallower ones, so this made it much, much faster. It can now make a 1000x1000 cell maze with almost 2 million walls in 30 seconds.
snip wrong thread
snip
[QUOTE=Over-Run;43990111]So like I said before, I am looking for ideas for a basic data mining project to help me learn it. I was thinking of doing something on rotten tomatoes. Is this possible? Any ideas for a decent project I could do with Rotton Tomatos? Something like find out if the average rating of hollywood films is increasing or decreasing every year?[/QUOTE] Ideas: How strong is the correlation between tomatometer and boxoffice earnings? How strong is the correlation between tomatometer and release date? Which directors have the highest box office/tomatometer ratio? Which have the lowest?
Can I get some fresh eyes on this, its been a long day. [code] int *rankGPUmem=new int[totalranks]; int *rankGPUffts=new int[totalranks]; int totalGPUs=0; int totalMEM=0; for(int i=0;i<totalranks;i++) rankGPUmem[i]=0; rankGPUmem[1]=1024000000; rankGPUmem[6]=1242000000; //Get info about workers-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- for (int i=1;i<totalranks;i++)//receive from all ranks>0 { //find out how many gpus there are and how much memory each one has if (rankGPUmem[i]>0) { totalGPUs++; totalMEM+=rankGPUmem[i]; } } [/code] The problem is in the second for loop. When i==1 totalMEM is correctly set to 1024000000, but when i==6 instead of increasing to 2266000000 it gets set to -2028967296, and i cannot for the life of me figure out why. I'm sure it's something really basic that I've missed (I've been on this nearly 13 hours). Anyone see anything? Language is C++ Edit: Scratch that, forgot int limits. Using unsigned now its just about big enough.
Is anyone familiar with 30log/lua? [code] --Base class. require 'event' class = require '30log' Base = class { onUpdate = nil, onDraw = nil, world = nil } function Base:__init( table ) self.onUpdate = table[1] self.onDraw = table[2] self.world = table[3] self.onDraw:add(self.update) self.onUpdate:add(self.draw) end function Base:update() end function Base:draw() end --derived class. require 'base' Borders = Base:extends() function Borders:__init(table) for key, value in pairs(table) do print(value) end Borders.super.__init(table) end function Borders:draw() end --creating an instance of Borders like so. b = Borders:new({onUpdate,onDraw,world}) [/code] When I print the table in the derived class none of the elements are nil, yet it fails with a nil value error on the call to the init super. [editline]22nd February 2014[/editline] It works fine without overwriting the constructor so I could just create a load method to get past it, but I'd prefer not to call load every time I create an instance. [editline]22nd February 2014[/editline] Fixed, you have to pass self. [code] Borders.super.__init(self,table)[/code]
Is there a way to keep a number if its X but minimize it if not? To explain myself, I have a circle whith a gradient effect that is white in the middle and goes to transparrent allowing whats behind to show I want to make the radius of this circle smaller so I times its color by 0.5 however this makes the center not be fully white
[QUOTE=Richy19;44006319]I want to make the radius of this circle smaller so I times its color by 0.5 however this makes the center not be fully white[/QUOTE] I don't think that this [QUOTE=Richy19;44006319]Is there a way to keep a number if its X but minimize it if not?[/quote] is going to help that, since only the very center of the circle (at best, a single pixel) will be completely white. It sounds like you want a smooth step function. That will allow the outside to be completely transparent, the inside to be completely white, and with a gradient between them.
I'm quite new to things such as planetary simulation and I'm not sure I understood what the Wikipedia page said about this. So, I know two-body problem can be easily analytically solved. Is the n-body problem where n is any number above 2 solved? If it can't be done analytically, is there any stable (ignoring rounding errors) numerical solution to it?
Depends on what kind of stability you want. Stable and non-chaotic orbits are called N-body choreographies. The simplest example is a bunch of equal masses spinning in a circle, equidistant from each other. Our solar system is an example of a mostly stable system even though it has N>2. Lagrange points are solutions for stable orbits when N>2 and the extra particles are negligible in mass. Then you probably have chaotic systems which are "stable" in the sense that they never result in a singularity nor let particles escape. I don't know about those though.
[QUOTE=ThePuska;44011931]Depends on what kind of stability you want. Stable and non-chaotic orbits are called N-body choreographies. The simplest example is a bunch of equal masses spinning in a circle, equidistant from each other. Our solar system is an example of a mostly stable system even though it has N>2. Lagrange points are solutions for stable orbits when N>2 and the extra particles are negligible in mass. Then you probably have chaotic systems which are "stable" in the sense that they never result in a singularity nor let particles escape. I don't know about those though.[/QUOTE] I'm talking about simulating something like our solar system, but where the planets also affect each other a little bit.
I have a question regarding design patterns in c#. So the problem comes from my 2d grid based game. Theres several processes for various parts of the game, the map editor, the overworld, the game itself, the main menu etc. Each process has its own managers required for it. For example, lets take the map editor. The interface manager is the edit mode interface that contains windows that contains sub windows regarding editing of the current grid. Say I select the change tile texture tool in a sub menu. And now when I click I want to change tiles on grid. Currently whenever I create an interface manager I pass the reference of the process to the constructor, and for each window I pass the interface manager to the constructor... and so on. The only way I can think of making modifications to the grid doing a chain of backwards references until I get to the parent process, where I will then go into the grid manager to change what I need to change. [img]http://i.imgur.com/vgiurK3.png[/img] I mean, what I'm doing works ok, but I know its bad practice. Whats the proper way to do this?
[QUOTE=ArgvCompany;44016636]I'm talking about simulating something like our solar system, but where the planets also affect each other a little bit.[/QUOTE] [url]http://physics.princeton.edu/~fpretori/Nbody/intro.htm[/url] It's a shame he kinda neglects a lot of physics and just throws the code in there, but this could help with further Googling.
[CODE] public static void readStoreInfo(ArrayList<Producer> productionList) throws FileNotFoundException { Producer currentArtist = new Producer(); File file = new File("data.txt"); if (!file.exists()) { System.out.println("Data file not found."); } Scanner fileReader = new Scanner(file); int i = 0; while (fileReader.hasNext()) { String artist = fileReader.nextLine(); currentArtist.setMusician(artist); String album = fileReader.nextLine(); currentArtist.setAlbum(album); //Am I casting this wrong? String sales = fileReader.nextLine(); sales = Integer.parseInt(sales); currentArtist.setSales(sales); i++; productionList.add(currentArtist); } fileReader.close();[/CODE] Trying to read this file and I get a message saying I'm not casting sales correctly? Am I doing something wrong?
[QUOTE=blacksam;44022956][CODE] public static void readStoreInfo(ArrayList<Producer> productionList) throws FileNotFoundException { Producer currentArtist = new Producer(); File file = new File("data.txt"); if (!file.exists()) { System.out.println("Data file not found."); } Scanner fileReader = new Scanner(file); int i = 0; while (fileReader.hasNext()) { String artist = fileReader.nextLine(); currentArtist.setMusician(artist); String album = fileReader.nextLine(); currentArtist.setAlbum(album); //Am I casting this wrong? String sales = fileReader.nextLine(); sales = Integer.parseInt(sales); currentArtist.setSales(sales); i++; productionList.add(currentArtist); } fileReader.close();[/CODE] Trying to read this file and I get a message saying I'm not casting sales correctly? Am I doing something wrong?[/QUOTE] You're creating a [I]string[/I] sales. Then you're trying to parse the exact same string as an int and store it as a string. Try something like: [CODE] int sales = Integer.parseInt(fileReader.nextLine()); currentArtist.setSales(sales); [/CODE]
Guys (and girls), I want to make something like this: [url]http://flapmmo.com/[/url] I know C# and XML/HMTL. How is that flappy game made? I guess its Javascript. Or is it something else? I don't think its flash since it doesn't have that "flash context menu" Are there any tutorials on how to make something like that? (like how to draw stuff etc) Ah, and also what IDE would you suggest to create something like this? Since I am SO used to intellisense, please tell me that a good (as in VS-good) editor also exists for js.
Turns out that somebody is using RottonTomatoes for the data mining project already so I need another idea. I was thinking about using metacritic. Would it be a good project if I was to find out the correlation between critic reviews and user reviews? Maybe see if a film has very high critic reviews but low user reviews, then you can sort of deduce that critics were paid off for good reviews or the film had a lot of controversy surrounding it which led to bad user reviews. Could even do it with games. Would that be possible on metacritic?
[QUOTE=Felheart;44029146]Guys (and girls), I want to make something like this: [url]http://flapmmo.com/[/url] I know C# and XML/HMTL. How is that flappy game made? I guess its Javascript. Or is it something else? I don't think its flash since it doesn't have that "flash context menu" Are there any tutorials on how to make something like that? (like how to draw stuff etc) Ah, and also what IDE would you suggest to create something like this? Since I am SO used to intellisense, please tell me that a good (as in VS-good) editor also exists for js.[/QUOTE] Yes, that's JavaScript. There are tons of tutorials for HTML 5 Canvas + JavaScript. A quick Google found: [url]http://www.lostdecadegames.com/how-to-make-a-simple-html5-canvas-game/[/url] and [url]http://www.html5rocks.com/en/tutorials/canvas/notearsgame/[/url] Visual Studio 2012+ (not sure about earlier versions) provide some sort of IntelliSense for JavaScript. I've used it at work and it's pretty good.
How would I go about creating sort of a word copier?. What I want to do is have my program read through a chatlog.txt file, only copying things such as "Contact: Firstname_Lastname" "PH: 555" and later allowing me to paste the info to a separate text file?
[QUOTE=MaikkiBoi;44031977]How would I go about creating sort of a word copier?. What I want to do is have my program read through a chatlog.txt file, only copying things such as "Contact: Firstname_Lastname" "PH: 555" and later allowing me to paste the info to a separate text file?[/QUOTE] In what programming language? If it's C# you can add me on Steam, i have time explaining.
[QUOTE=cartman300;44032080]In what programming language? If it's C# you can add me on Steam, i have time explaining.[/QUOTE] Yeah, C#. Sent you a friend request.
I hope this is the best place to ask this, but is using something like Phonegap to develop mobile applications looked down upon, and/or would I be better off learning Java/Objective-C for it?
Finally have Awesomium running as gui, turns out i was just being stupid xD And next issue. The javascript (and libraries, jquery in this case) is acting very strange. In general, most of it works. But things like events sometimes work or not. [CODE] $(document).ready(function() { document.write("Test"); }); [/CODE] This works (as does $("body").append(..);). But as soon as i want to use a click event (either jquery or regular javascript), it does nothing [code] $("#testButton").click(function () { document.write("Test"); }); [/code] This does nothing. Also, $(document).ready(); doesn't work if i call a C# method via the javascript. If i knew Awesomium was so frustrating, i might have taught twice :p Someone in here used Awesomium/C# before, who was it again? xD
[QUOTE=gokiyono;44032759]I hope this is the best place to ask this, but is using something like Phonegap to develop mobile applications looked down upon, and/or would I be better off learning Java/Objective-C for it?[/QUOTE] I don't see why it would, as long as the app runs well and has proper native UX. If you want to use this to skimp on work and just make it look like an iPhone app everywhere though, prepare to get slammed in the Play Store ratings etc.
I wrote some multithreaded code to import a file into an arraylist, and have each "thread" search that arraylist for a word from user input. [code]package wordsearcher; import java.util.ArrayList; import java.io.*; import java.util.Scanner; /** * * @author Bloodshot */ public class WordFinder extends Thread{ private int low; private int high; private String target; public ArrayList<String> list1 = new ArrayList<>(); public WordFinder(int low, int high, String target) { this.low = low; this.high = high; this.target = target; } public void run() { try { Scanner s = new Scanner(new File("words.dic")); while (s.hasNext()){ list1.add(s.nextLine()); } s.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } for (int a = low; a <= high; a++) { if (list1.get(a).contains(target)) { System.out.println("The word " + target + " has been found by " + this.getName()); } } } }[/code] And here's my driver class [code] package wordsearcher; import java.util.ArrayList; import java.util.Scanner; import java.io.*; /** * * @author Bloodshot */ public class WordFinderDemo { public static void main(String []args) { Scanner kbd = new Scanner(System.in); System.out.println("Please enter the word you want to pull from the dictionary"); String word = kbd.nextLine(); Thread t1 = new WordFinder(0,12,word); Thread t2 = new WordFinder(13,26,word); Thread t3 = new WordFinder(27,39,word); Thread t4 = new WordFinder(40,52,word); t1.start(); t2.start(); t3.start(); t4.start(); } } [/code] However, I believe my professor wants us to sort the threads with a range of letters, i.e. instead of the array index 0 - 12, I'd have to use letters, such as A - G for the range. After a while of searching around google and trying the figure things out, I'm not really sure how I'd accomplish this and have it search the array list from A - G in the first thread while checking if any of the words match the user input. Could anyone point me in the right direction?
I'm working on a game engine (DirectX 9, will eventually support OpenGL) and I was theorizing a fast render method. Should I do something like call RenderObject() on every entity and redo the VBO, or should I have the entities call methods like CreateMesh(), UpdateMesh(), and RemoveMesh() only when needed? I was thinking of using the latter because it's less call overhead, but I need some reassurance on this.
How long is a typical start time for an Android Virtual Device? I decided to play around with Android development, but it's been nearly 25 minutes since I started my AVD and it is still doing the "Android" animated-gradient thing. I had no idea what specs to use for it, so I used: Nexus 4, Android 4.4.2, ARM, 768 MB RAM, 64 Heap, 4 GiB Internal Storage, 8 GiB SD, no Snapshot or Use Host GPU. Intel Core i7-4770K @ 3.50GHz, 16GB RAM is my system setup. [editline]25th February 2014[/editline] Recreated it with 256MB internal memory and 2 GiB SD, and it loaded in less than a minute. Guess that was the issue. Now if only it didn't run so damn slow. :v: [editline]fish[/editline] Seriously over 0.5s delay for a button to register a click, and 3.77 seconds for the "Back" button to actually work. And it runs on what seems like 12fps. Oh well, still cheaper than buying an Android phone. :v:
[QUOTE=Bloodshot12;44034996]I wrote some multithreaded code to import a file into an arraylist, and have each "thread" search that arraylist for a word from user input. [code]package wordsearcher; import java.util.ArrayList; import java.io.*; import java.util.Scanner; /** * * @author Bloodshot */ public class WordFinder extends Thread{ private int low; private int high; private String target; public ArrayList<String> list1 = new ArrayList<>(); public WordFinder(int low, int high, String target) { this.low = low; this.high = high; this.target = target; } public void run() { try { Scanner s = new Scanner(new File("words.dic")); while (s.hasNext()){ list1.add(s.nextLine()); } s.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } for (int a = low; a <= high; a++) { if (list1.get(a).contains(target)) { System.out.println("The word " + target + " has been found by " + this.getName()); } } } }[/code] And here's my driver class [code] package wordsearcher; import java.util.ArrayList; import java.util.Scanner; import java.io.*; /** * * @author Bloodshot */ public class WordFinderDemo { public static void main(String []args) { Scanner kbd = new Scanner(System.in); System.out.println("Please enter the word you want to pull from the dictionary"); String word = kbd.nextLine(); Thread t1 = new WordFinder(0,12,word); Thread t2 = new WordFinder(13,26,word); Thread t3 = new WordFinder(27,39,word); Thread t4 = new WordFinder(40,52,word); t1.start(); t2.start(); t3.start(); t4.start(); } } [/code] However, I believe my professor wants us to sort the threads with a range of letters, i.e. instead of the array index 0 - 12, I'd have to use letters, such as A - G for the range. After a while of searching around google and trying the figure things out, I'm not really sure how I'd accomplish this and have it search the array list from A - G in the first thread while checking if any of the words match the user input. Could anyone point me in the right direction?[/QUOTE] I'm not sure if I'm reading your post right, but if you want to sort the list alphabetically try using [url=http://docs.oracle.com/javase/7/docs/api/java/util/Collections.html#sort%28java.util.List%29]Collections.sort[/url] to sort the list depending on the elements inside it. I would also recommend you use a [b]foreach[/b] loop to loop through the words in the list, as so: [code] foreach (String line : list1) { if (line.contains(target)) { //do something System.out.println("The word '" + target + "' has been found by " + this.getName + "!"); } } [/code]
Alright; there has got to be an easier way to do what I'm doing and I just don't know about it. First the code is here, [URL="https://github.com/Proclivitas/CPP_Early_Objects_Eighth_Edition/tree/master/Chapter%20Four/Programming%20Challenges/Problem%2021"]https://github.com/Proclivitas/CPP_Early_Objects_Eighth_Edition/tree/master/Chapter%20Four/Programming%20Challenges/Problem%2021[/URL], I'm specifically talking about my switch statement at line 38 in main.cpp. As you can see, I am passing values from instances of Package class which stores information on types of phone service packages you can receive; I am then passing the the values from the instance of the Package class to a variable in my newCustomer class. I would like to assume that there is a way to pass the instance of my Package class, say PackageA, and then call Package.A.getPricePerMonth() as you see I am trying to do within customer.cpp at line 39 with by using the parameter "Package p" and then I try to call the passed package, but it won't allow me to use Package as a user defined data type because it doesn't recognize it. I then tried to include the package.h file into my customer.cpp and that just threw a whole bunch of errors.
Sorry, you need to Log In to post a reply to this thread.