• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 12:01
CET 17:01
KST 01:01
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
[ASL22] Finals Preview: Sweet Victory!12[ASL22] Ro4 Preview: Mirror Mirror6[ASL22] Ro8 Preview: Within Reach5[ASL22] Ro8 Preview: In A Tizzy11[ASL22] Ro16 Preview: Holy Diver5
Community News
Weekly Cups (October 19-25): Clem triples first in 5.0.175Evil Geniuses - shutting down20ISSL (IntoTheTV x SOOP SC2 League): Premier6Weekly Cups (October 12-18): 5.0.17 era begins1[$1250] International ShieldBattery League92
StarCraft 2
General
No more SC2 streamers on team liquid? Weekly Cups (October 19-25): Clem triples first in 5.0.17 How do you feel about the mass reverts in the 5.0.17 PTR? Evil Geniuses - shutting down REPORT: StarCraft 2: Remastered In Development
Tourneys
ISSL (IntoTheTV x SOOP SC2 League): Premier Stellar Fest TWO the Moon (Dec 16-20) RSL 2026 Offline Finals LCQ Sign-Ups Sparkling Tuna Cup - Weekly Open Tournament 2026 KungFu Cup Announcement
Strategy
[H] ZvP Mid-Late Game: Stalkers Collossi HT
Custom Maps
Simple Questions/Answers [G] How to playtest arcade maps [A] Nemrods 1/4 players
External Content
Mutation # 549 Endless Sparkles The PondCast: SC2 News & Results Mutation # 548 Shining Bright Mutation # 547 Temple Of Terror
Brood War
General
SCHNAIL now supports Remastered Rollback Netcode in Brood War BW General Discussion [Megathread] Daily Funny Videos SC4ALL II Brood War Complete Invited Player Lineup
Tourneys
[Megathread] Daily Proleagues [Women's StarCraft] MonstarZ vs BA 2026-10-30 Star Con San Diego 2026 Small VOD Thread 2.0
Strategy
50,000-Word Terran Builds Memo 2026-10-22 Cliff Jump Revisited (1 in a 1000 strategy) Simple Questions, Simple Answers
Other Games
General Games
Nintendo Switch Thread Stormgate/Frost Giant Megathread Mobile Legends: Bang Bang Armies of Exigo - YesYes? General RTS Discussion Thread
Dota 2
Dota 2 Champions League Season 3 Begins April 25!
League of Legends
[TL LoL EUW IHs] Teemo shall perish
Heroes of the Storm
Heroes of the Storm 2.0
Hearthstone
Deck construction bug
TL Mafia
TL Mafia Community Thread
Community
General
US Politics Mega-thread European Politico-economics QA Mega-thread R I P Patrick Stewart Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine
Fan Clubs
Reynor Fan Club The Flash Fan Club Serral Fan Club
Media & Entertainment
Anime Discussion Thread Movie Discussion! [Manga] One Piece
Sports
TeamLiquid Health and Fitness Initiative For 2023 Football (Soccer) Thread MLB/Baseball 2023
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Recent Gifted Posts
Blogs
Innovate or Game Over?
TrAiDoS
ShieldBattery on Mac
Kraekkling
[ASL22] Ro4 Day1 Ticket Giv…
bITt.mAN
Can Bots Beat Pros?? Starcr…
namkraft
Customize Sidebar...

Website Feedback

Closed Threads



Active: 8935 users

The Big Programming Thread - Page 436

Forum Index > General Forum
Post a Reply
Prev 1 434 435 436 437 438 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
Mavvie
Profile Blog Joined May 2012
Canada923 Posts
Last Edited: 2014-01-29 20:39:03
January 29 2014 20:38 GMT
#8701
On January 27 2014 21:28 actionbastrd wrote:
So i am trying to learn C programing, and am hoping to dive really deep into it. I have a task which i am having trouble with. I feel like accomplishing this task could be done way better, but none the less,

Prompt the user and accept the following types of values from a SINGLE input line: char float int char.

What i have is this(spoiler), which works when the question asked is "char int char float", but breaks, i am assuming because it cannot tell when the float number ends. I understand spacing is an issue to and i commented on that in the prompt,.. but i need a separator somehow, i am learning out of books and having come across anything. I personally would just have it ask in separate lines or something. D:

This is actually my first language and am really stoked on it, but its mostly a grind with little to no in person help lol. If anyone has good C programming resources i could check out and read that would be awesome too, about anything!

+ Show Spoiler +

char f, g;
int h;
float i;

printf("Enter a char, float, int, char; with no spaces in between each input: ");

scanf("%c%f%d%c", &f, &i, &h, &g);

printf("You entered: %c, %.3f, %d, %c.\n", f, i, h, g);


I believe this would work:
char f, g; 
int h;
float i;

printf("Enter a char, float, int, char; with no spaces in between each input: ");

scanf("%c %f %d %c", &f, &i, &h, &g);

printf("You entered: %c, %.3f, %d, %c.\n", f, i, h, g);


Only difference is the scanf() format string.

Just tested it, it works! The scanf() documentation probably explains it well, but it's very similar to a Regex.

See the following:
int i=0;
sscanf("Test s15tring", "Test s%dtring", &i);
// i==15


It'll try its hardest to match it.
Getting back into sc2 O_o
Manit0u
Profile Blog Joined August 2004
Poland17865 Posts
January 29 2014 23:17 GMT
#8702
Mavvie, I already explained earlier that you need sscanf for that, not scanf
Time is precious. Waste it wisely.
Mavvie
Profile Blog Joined May 2012
Canada923 Posts
January 30 2014 00:20 GMT
#8703
Ooh silly me! Missed that one.

scanf() is okay to get the job he's doing done; it's not like security is an issue. But yeah sscanf is the better choice. Note I used it in the second example!

I'm mostly a Rails guy, nobody here ever seems to have Rails questions
Getting back into sc2 O_o
dapierow
Profile Blog Joined April 2010
Serbia1316 Posts
Last Edited: 2014-01-30 03:36:56
January 30 2014 03:36 GMT
#8704
Hey guys I need some with formatting a number in SQL, How can I add a comma to a number after every thousand? ex: 1234567 to turn into 1,234,567?


SELECT COUNT(*) as "Tweets in Database"
from tweets_sml;

is what I have to count the number of "tweets"
Eat.Sleep.Starcraft 2
tofucake
Profile Blog Joined October 2009
Hyrule19265 Posts
January 30 2014 03:55 GMT
#8705
FORMAT(COUNT(*), 0)

also, COUNT(*) is generally considered bad
Liquipediaasante sana squash banana
Iceman331
Profile Joined April 2010
United States1306 Posts
January 30 2014 03:59 GMT
#8706
On January 30 2014 12:55 tofucake wrote:
FORMAT(COUNT(*), 0)

also, COUNT(*) is generally considered bad


Out of curiosity, why is count(*) bad?
tofucake
Profile Blog Joined October 2009
Hyrule19265 Posts
January 30 2014 04:07 GMT
#8707
first, because you have no where clause
second, because you are counting everything returned from the result
third, because you are doing both of those things at the same time

it's even worse if you're using innodb instead of myisam because of how inno works.

I don't know how your table is structured, but if tweets aren't ever deleted (unlikely) and you have a unique id column (which you should) that happens to be an auto_incrementing int you could do SELECT MAX(id) or SELECT id ORDER BY id DESC LIMIT 1

If (more likely) tweets are deleted, and you have a silly number of rows, you should use a set of triggers which update another table (preferably in a memory table for speed) with a count.
Liquipediaasante sana squash banana
dapierow
Profile Blog Joined April 2010
Serbia1316 Posts
January 30 2014 04:56 GMT
#8708
Thank you tofu <3
Eat.Sleep.Starcraft 2
mcc
Profile Joined October 2010
Czech Republic4646 Posts
Last Edited: 2014-01-30 18:10:59
January 30 2014 18:05 GMT
#8709
On January 30 2014 13:07 tofucake wrote:
first, because you have no where clause
second, because you are counting everything returned from the result
third, because you are doing both of those things at the same time

it's even worse if you're using innodb instead of myisam because of how inno works.

I don't know how your table is structured, but if tweets aren't ever deleted (unlikely) and you have a unique id column (which you should) that happens to be an auto_incrementing int you could do SELECT MAX(id) or SELECT id ORDER BY id DESC LIMIT 1

If (more likely) tweets are deleted, and you have a silly number of rows, you should use a set of triggers which update another table (preferably in a memory table for speed) with a count.

I can only strongly disagree with this advice.

If you need exact count, using MAX(id) to determine it is probably the worst idea. There are multiple ways where auto_incrementing columns can produce holes even without deletes.

Also do not worry about optimizations if there is no need to worry about optimizations. If your application works perfectly fine, it is actually bad idea to store the count separately as you introduce unnecessary complexity and possible point of inconsistency. In general never duplicate data if performance reasons do not force you to do it. Storing count is duplicating data. Of course in real-life systems you will be in the end forced to actually do that sometimes, but do it only as a response to the actual need.

Triggers are work of the devil and should be avoided.

Deleting data seems to me nearly always bad idea. If you have performance issues, partition, if not what is the point. Again do optimizations only in response to actual need.

EDIT: In short SELECT COUNT(*) is perfectly fine.
RoyGBiv_13
Profile Blog Joined August 2010
United States1275 Posts
January 30 2014 18:15 GMT
#8710
Let's play a game...

What is bar equal to? [C]:

uint8_t foo = 0x70;
uint8_t bar = (~foo) >> 4;
Any sufficiently advanced technology is indistinguishable from magic
Rannasha
Profile Blog Joined August 2010
Netherlands2398 Posts
January 30 2014 18:25 GMT
#8711
On January 31 2014 03:15 RoyGBiv_13 wrote:
Let's play a game...

What is bar equal to? [C]:

uint8_t foo = 0x70;
uint8_t bar = (~foo) >> 4;


In base-2:
foo = 01110000
~foo = 10001111
(~foo) >> 4 = 00001000

So bar = 8
Such flammable little insects!
Shenghi
Profile Joined August 2010
167 Posts
Last Edited: 2014-01-30 19:50:20
January 30 2014 18:38 GMT
#8712
On January 31 2014 03:25 Rannasha wrote:
Show nested quote +
On January 31 2014 03:15 RoyGBiv_13 wrote:
Let's play a game...

What is bar equal to? [C]:

uint8_t foo = 0x70;
uint8_t bar = (~foo) >> 4;


In base-2:
foo = 01110000
~foo = 10001111
(~foo) >> 4 = 00001000

So bar = 8

That is what you would expect. But it's wrong.

+ Show Spoiler [Solution] +

foo = 01110000
foo >> 4 = 00000111
(~foo) >> 4 = 11111000
bar == 248
People are not born stupid, they choose to be stupid. If you made that choice, please change your mind.
RoyGBiv_13
Profile Blog Joined August 2010
United States1275 Posts
January 30 2014 18:56 GMT
#8713
On January 31 2014 03:38 Shenghi wrote:
Show nested quote +
On January 31 2014 03:25 Rannasha wrote:
On January 31 2014 03:15 RoyGBiv_13 wrote:
Let's play a game...

What is bar equal to? [C]:

uint8_t foo = 0x70;
uint8_t bar = (~foo) >> 4;


In base-2:
foo = 01110000
~foo = 10001111
(~foo) >> 4 = 00001000

So bar = 8

That is what you would expect. But it's wrong.

+ Show Spoiler [Solution] +

foo = 01110000
foo >> 4 = 00000111
(~foo) >> 4 = 11111000
foo == 248


You had a typo in your last line, but it's correct:

+ Show Spoiler +
bar = 248+ Show Spoiler +

That is, assuming that your compiling for a target with a word size of greater than 1 byte.



+ Show Spoiler +

Let's assuming it's a target with a 32-bit word size. For an arithmetic operation (negation, in this case, ~) the lvalue (return value of the operation) will be the default word size, and any types smaller than the word size will be promoted to the default word size. In this case, foo is promoted to a signed 32-bit int:
foo = 0x00000070
~foo = 0xFFFFFF8F
~foo >> 4 = 0xFFFFFFF8 //in this case, since the result will fit within the type, it wont be sign extended
bar is then truncated to fit within the uint8 type
bar = 0xF8 //248
Any sufficiently advanced technology is indistinguishable from magic
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
January 31 2014 18:13 GMT
#8714
I've recently studied about the Actor model, but it sounds too good to be true. Anyway, is the model used at workplace?
obesechicken13
Profile Blog Joined July 2008
United States10467 Posts
January 31 2014 22:53 GMT
#8715
On February 01 2014 03:13 darkness wrote:
I've recently studied about the Actor model, but it sounds too good to be true. Anyway, is the model used at workplace?

That sounds like a very visual and understandable model
I think in our modern age technology has evolved to become more addictive. The things that don't give us pleasure aren't used as much. Work was never meant to be fun, but doing it makes us happier in the long run.
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
Last Edited: 2014-02-01 13:33:01
February 01 2014 13:24 GMT
#8716
Can anyone show me a quick example of the Memento pattern? The example from wikipedia is just using a string. What about a more complex object that has attributes? E.g.

Person
+ Show Spoiler +


public class Person {
private int age;
private String name;

public Person(int age, String name) {
this.age = age;
this.name = name;
}

public int getAge() {
return age;
}

public String getName() {
return name;
}

public void setAge(int age) {
this.age = age;
}

public void setName(String name) {
this.name = name;
}
}



I've tried the following but I don't know if it's correct.

Some save state method, e.g:


public Memento saveState() {
return new Memento(this); // this == Person
}


And the Memento class:

public class Memento {
int age;
String name;

public Memento(Person p) {
age = p.getAge();
name = p.getName();
}

public Person getState() {
return new Person(age, name);
}
}


Am I on the right track? I've omitted the data structure part because it's obvious although I think Stack would be suitable? I've also read that using object.clone() isn't recommended, so copy constructor then?
wozzot
Profile Joined July 2012
United States1227 Posts
February 02 2014 09:08 GMT
#8717
Made a Mandelbrot fractal generator, but the issue is that it runs really slowly: it takes a whole minute to generate a single fractal. Would like to know whether the problem is because my program is inefficient or because of Perl / the GD library. tia

+ Show Spoiler +

#!perl
use strict;
use GD;

# Mandelbrot fractal generator

my ($width, $height) = (900, 675);
my ($x_min, $x_max) = (-2, 1);
my ($y_min, $y_max) = (-1, 1);
my ($x_min, $x_max) = (-2, .65);
my ($y_min, $y_max) = (-1, 1);
my ($y_min, $y_max) = (-1, 1);

my $multi = 1/1.1;
$_ /= $multi for ($x_min, $x_max, $y_min, $y_max);

my $x_range = $x_max - $x_min;
my $y_range = $y_max - $y_min;
my $x_offset = 0;
my $y_offset = 0;
my $it_count = 30;
my $bound = 1000;

my $filename = 'fractal.png';
open STDOUT, ">", "$filename";
binmode STDOUT;

my $bitmap = new GD::Image($width, $height, 0) or die "Could not initialize bitmap\n";

my %colors = (); # keys: "$r $g $b"
# Allocate colors like this:
# $colors{"$r $g $b"} = $bitmap->colorAllocate($r, $g, $b)
# unless exists($colors{"$r $g $b"});
#
# Set pixel like this:
# $bitmap->setPixel($pix_h, $pix_v, $colortable{"$a $b $c"});

my $black = $bitmap->colorAllocate(0, 0, 0); # Black background
my @color_inner = (128, 255, 0);
my @color_outer = (0, 0, 96);

sub color {
my ($it, $pix_h, $pix_v) = @_;
my $percent = $it/ $it_count;
$percent *= .8;
$percent = 1 if $percent > 1;

my $r = int($color_inner[0] * $percent + $color_outer[0] * (1 - $percent));
my $g = int($color_inner[1] * $percent + $color_outer[1] * (1 - $percent));
my $b = int($color_inner[2] * $percent + $color_outer[2] * (1 - $percent));

$colors{"$r $g $b"} = $bitmap->colorAllocate($r, $g, $b)
unless exists($colors{"$r $g $b"});

$bitmap->setPixel($pix_h, $pix_v, $colors{"$r $g $b"});
}

sub calc {
my ($r, $i, $it, $pix_h, $pix_v, @c) = @_;

# (a + bi) ** 2 = a ** 2 + 2abi - b ** 2
# z = z**2 + c

my $real = $r ** 2 - $i ** 2 + $c[0];
my $imag = 2 * $r * $i + $c[1];
color($it, $pix_h, $pix_v) if ($real > $bound);
return ($real, $imag);
}

for my $pix_h (0..$width-1) {
for my $pix_v (0..$height-1) {
my $r = ($pix_h + 1) / $width * $x_range + $x_min + $x_offset;
my $i = ($pix_v + 1) / $height * $y_range + $y_min + $y_offset;
my @c = ($r, $i);

for (1..$it_count) {
($r, $i) = calc($r, $i, $_, $pix_h, $pix_v, @c);
}
}
}

print $bitmap->png;
(ノ´∀`*)ノ ♪ ♫ ヽ(´ー`)ノ ♪ ♫ (✌゚∀゚)☞ ♪ ♫ ヽ(´ー`)ノ ♫ ♫ (ノ´_ゝ`)ノ彡 ┻━┻
teamamerica
Profile Blog Joined July 2010
United States958 Posts
February 02 2014 11:05 GMT
#8718
On January 29 2014 09:01 Badboyrune wrote:
Ok I'm getting quite confused. I'm making a pretty basic android app, it's my first so my experience is very limited. It basically displays data from a database based on intent sent from the intent sent from another activity in the app. This all worked fine, I could navigate without any issue with the android OS back button.

However when I enable "getActionBar().setDisplayHomeAsUpEnabled(true);" and try to navigate backwards with the Home button that breaks any activity that relies on receiving an intent, because it doesn't receive any. I tried putting the information in the onSaveInstanceState bundle, but the activity does not receive the bundle when navigated to with the Home button (savedInstanceState != null returns false).

I've looked through all I've been able to find online (which has been limited because searches involving android home button are generally unhelpful) and all I've really been able to find is that the home button seems to not be programmable anymore, it either sends you to the app home activity, or the activities parent activity which is what I'm trying to achieve. I'm assuming there's some way of doing this so any help would be much appreciated.


Would you mind posting a code listing of the relevant activities? There are a lot of lifecycle callbacks - onRestoreInstanceState() for example.
RIP GOMTV. RIP PROLEAGUE.
bangsholt
Profile Joined June 2011
Denmark138 Posts
February 02 2014 12:30 GMT
#8719
On February 02 2014 18:08 wozzot wrote:
Made a Mandelbrot fractal generator, but the issue is that it runs really slowly: it takes a whole minute to generate a single fractal. Would like to know whether the problem is because my program is inefficient or because of Perl / the GD library. tia

+ Show Spoiler +

#!perl
use strict;
use GD;

# Mandelbrot fractal generator

my ($width, $height) = (900, 675);
my ($x_min, $x_max) = (-2, 1);
my ($y_min, $y_max) = (-1, 1);
my ($x_min, $x_max) = (-2, .65);
my ($y_min, $y_max) = (-1, 1);
my ($y_min, $y_max) = (-1, 1);

my $multi = 1/1.1;
$_ /= $multi for ($x_min, $x_max, $y_min, $y_max);

my $x_range = $x_max - $x_min;
my $y_range = $y_max - $y_min;
my $x_offset = 0;
my $y_offset = 0;
my $it_count = 30;
my $bound = 1000;

my $filename = 'fractal.png';
open STDOUT, ">", "$filename";
binmode STDOUT;

my $bitmap = new GD::Image($width, $height, 0) or die "Could not initialize bitmap\n";

my %colors = (); # keys: "$r $g $b"
# Allocate colors like this:
# $colors{"$r $g $b"} = $bitmap->colorAllocate($r, $g, $b)
# unless exists($colors{"$r $g $b"});
#
# Set pixel like this:
# $bitmap->setPixel($pix_h, $pix_v, $colortable{"$a $b $c"});

my $black = $bitmap->colorAllocate(0, 0, 0); # Black background
my @color_inner = (128, 255, 0);
my @color_outer = (0, 0, 96);

sub color {
my ($it, $pix_h, $pix_v) = @_;
my $percent = $it/ $it_count;
$percent *= .8;
$percent = 1 if $percent > 1;

my $r = int($color_inner[0] * $percent + $color_outer[0] * (1 - $percent));
my $g = int($color_inner[1] * $percent + $color_outer[1] * (1 - $percent));
my $b = int($color_inner[2] * $percent + $color_outer[2] * (1 - $percent));

$colors{"$r $g $b"} = $bitmap->colorAllocate($r, $g, $b)
unless exists($colors{"$r $g $b"});

$bitmap->setPixel($pix_h, $pix_v, $colors{"$r $g $b"});
}

sub calc {
my ($r, $i, $it, $pix_h, $pix_v, @c) = @_;

# (a + bi) ** 2 = a ** 2 + 2abi - b ** 2
# z = z**2 + c

my $real = $r ** 2 - $i ** 2 + $c[0];
my $imag = 2 * $r * $i + $c[1];
color($it, $pix_h, $pix_v) if ($real > $bound);
return ($real, $imag);
}

for my $pix_h (0..$width-1) {
for my $pix_v (0..$height-1) {
my $r = ($pix_h + 1) / $width * $x_range + $x_min + $x_offset;
my $i = ($pix_v + 1) / $height * $y_range + $y_min + $y_offset;
my @c = ($r, $i);

for (1..$it_count) {
($r, $i) = calc($r, $i, $_, $pix_h, $pix_v, @c);
}
}
}

print $bitmap->png;


Profile your code. Then it should be obvious if it's Perl, the library or your code that's bad.
wozzot
Profile Joined July 2012
United States1227 Posts
February 02 2014 18:06 GMT
#8720
On February 02 2014 21:30 bangsholt wrote:
Show nested quote +
On February 02 2014 18:08 wozzot wrote:
Made a Mandelbrot fractal generator, but the issue is that it runs really slowly: it takes a whole minute to generate a single fractal. Would like to know whether the problem is because my program is inefficient or because of Perl / the GD library. tia

+ Show Spoiler +

#!perl
use strict;
use GD;

# Mandelbrot fractal generator

my ($width, $height) = (900, 675);
my ($x_min, $x_max) = (-2, 1);
my ($y_min, $y_max) = (-1, 1);
my ($x_min, $x_max) = (-2, .65);
my ($y_min, $y_max) = (-1, 1);
my ($y_min, $y_max) = (-1, 1);

my $multi = 1/1.1;
$_ /= $multi for ($x_min, $x_max, $y_min, $y_max);

my $x_range = $x_max - $x_min;
my $y_range = $y_max - $y_min;
my $x_offset = 0;
my $y_offset = 0;
my $it_count = 30;
my $bound = 1000;

my $filename = 'fractal.png';
open STDOUT, ">", "$filename";
binmode STDOUT;

my $bitmap = new GD::Image($width, $height, 0) or die "Could not initialize bitmap\n";

my %colors = (); # keys: "$r $g $b"
# Allocate colors like this:
# $colors{"$r $g $b"} = $bitmap->colorAllocate($r, $g, $b)
# unless exists($colors{"$r $g $b"});
#
# Set pixel like this:
# $bitmap->setPixel($pix_h, $pix_v, $colortable{"$a $b $c"});

my $black = $bitmap->colorAllocate(0, 0, 0); # Black background
my @color_inner = (128, 255, 0);
my @color_outer = (0, 0, 96);

sub color {
my ($it, $pix_h, $pix_v) = @_;
my $percent = $it/ $it_count;
$percent *= .8;
$percent = 1 if $percent > 1;

my $r = int($color_inner[0] * $percent + $color_outer[0] * (1 - $percent));
my $g = int($color_inner[1] * $percent + $color_outer[1] * (1 - $percent));
my $b = int($color_inner[2] * $percent + $color_outer[2] * (1 - $percent));

$colors{"$r $g $b"} = $bitmap->colorAllocate($r, $g, $b)
unless exists($colors{"$r $g $b"});

$bitmap->setPixel($pix_h, $pix_v, $colors{"$r $g $b"});
}

sub calc {
my ($r, $i, $it, $pix_h, $pix_v, @c) = @_;

# (a + bi) ** 2 = a ** 2 + 2abi - b ** 2
# z = z**2 + c

my $real = $r ** 2 - $i ** 2 + $c[0];
my $imag = 2 * $r * $i + $c[1];
color($it, $pix_h, $pix_v) if ($real > $bound);
return ($real, $imag);
}

for my $pix_h (0..$width-1) {
for my $pix_v (0..$height-1) {
my $r = ($pix_h + 1) / $width * $x_range + $x_min + $x_offset;
my $i = ($pix_v + 1) / $height * $y_range + $y_min + $y_offset;
my @c = ($r, $i);

for (1..$it_count) {
($r, $i) = calc($r, $i, $_, $pix_h, $pix_v, @c);
}
}
}

print $bitmap->png;


Profile your code. Then it should be obvious if it's Perl, the library or your code that's bad.

Merging the subroutine calls into the main function saved around 20 seconds, seems that Perl is slow with floating point operations though. Thanks
(ノ´∀`*)ノ ♪ ♫ ヽ(´ー`)ノ ♪ ♫ (✌゚∀゚)☞ ♪ ♫ ヽ(´ー`)ノ ♫ ♫ (ノ´_ゝ`)ノ彡 ┻━┻
Prev 1 434 435 436 437 438 1032 Next
Please log in or register to reply.
Live Events Refresh
Epic.LAN
22:00
Epic.LAN 49 Group Stage
Liquipedia
GSL
21:00
GSL CK 6
IntoTheiNu 886
SHIN 136
Maru 88
CranKy Ducklings SOOP72
Zoun (SOOP) 54
herO (SOOP) 48
Solar (SOOP)38
Rogue 31
ByuN (SOOP) 29
Rex21
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Lowko481
SHIN 136
Maru 88
Zoun (SOOP) 54
herO (SOOP) 48
Solar (SOOP) 38
Rogue 31
ByuN (SOOP) 29
Rex 21
StarCraft: Brood War
Jaedong 1468
Light 1134
Horang2 1014
EffOrt 970
BeSt 399
FanTaSy 383
Soma 343
Snow 317
ggaemo 244
actioN 240
[ Show more ]
ZerO 175
Rush 147
Hyuk 145
White-Ra 137
Mind 114
Barracks 111
Hyun 85
hero 69
sSak 55
Yoon 52
Mong 50
Classic 48
Sea.KH 44
Shinee 35
ToSsGirL 32
910 26
Trap 26
HiyA 23
Sharp 22
soO 19
Terrorterran 18
JYJ 17
Rock 11
Bishop 11
Noble 3
Dota 2
Gorgc21775
qojqva1395
syndereN347
Fuzer 178
LuMiX0
League of Legends
Trikslyr39
Heroes of the Storm
crisheroes384
Other Games
singsing1593
Liquid`RaSZi1034
hiko1002
Mlord655
DeMusliM345
Hui .176
ArmadaUGS149
Liquid`VortiX149
KnowMe127
XaKoH 94
QueenE44
ZerO(Twitch)15
Organizations
Counter-Strike
PGL25255
StarCraft: Brood War
lovetv 8
[ Show 15 non-featured ]
StarCraft 2
• poizon28 65
• StrangeGG 55
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• Migwel
StarCraft: Brood War
• HerbMon 30
• FirePhoenix7
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Nemesis1967
• TFBlade518
Other Games
• Shiphtur345
Upcoming Events
Big Brain Bouts
59m
OSC
5h 59m
Replay Cast
6h 59m
Sparkling Tuna Cup
17h 59m
WardiTV Invitational
19h 59m
Epic.LAN
20h 59m
IPSL
23h 59m
eOnzErG vs McRibbed
LancerX vs StRyKeR
AI Arena Tournament
1d 1h
OSC
1d 21h
Yamato Cup
1d 22h
[ Show More ]
IPSL
2 days
Artosis vs RiceHat
Kyrie vs Sony
Map Test Tournament
2 days
WardiTV Weekly
2 days
Ultimate Battle
2 days
Rush vs BeSt
Replay Cast
3 days
Rogue vs Classic
Patches Events
3 days
PiGosaur Cup
4 days
Kung Fu Cup
4 days
The PondCast
5 days
KCM Race Survival
5 days
Liquipedia Results

Completed

Proleague 2026-10-28
Blizzard Classic Cup 2026
HCC Season 3

Ongoing

Acropolis #5
KCM Race Survival 2026 Season 4
International ShieldBattery League
BSL Season 23
PGL Masters Bucharest 2026
Stake Ranked Episode 5
1win Private Club #2
Thunderpick World Champ. '26
ESL Pro League Season 24
Stake Ranked Episode 4
1win Private Club #1
Logitech G Play Connect 2026
SL StarSeries Fall 2026
FISSURE Playground #3
BLAST Open Fall 2026
Esports World Cup 2026

Upcoming

IPSL Winter 2026-27
1xBet Invitational
SC4ALL II: Brood War
BSL 23: Non-Korean Championship
HSC XXX
Stellar Fest 2: Lunar Cup
SC4ALL II: StarCraft II
Kung Fu Cup 2026 Grand Finals
RSL Offline Finals
eXTREMESLAND 2026
PGL Major Singapore 2026
Stake Ranked Episode 6
BLAST Rivals Fall 2026
IEM Beijing 2026
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2026 TLnet. All Rights Reserved.