Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 491 492 [493] 494 495 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 886716 times)

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #7380 on: May 14, 2015, 02:58:23 am »

Quick question: Does anyone know if a Canvas is the only way to edit an image's pixels in Javascript?
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7381 on: May 14, 2015, 03:43:49 am »

In what Javascript library? Or is it just vanilla Javascript? I get so confused due to the general weirdness surrounding Javascript's library stuff.

EDIT: bahah speaking of which I actually looked up jquery just now and realized that I've been writing my own functions to do one of the things that it already does (DOM manipulation)

oh well how else do you learn a language than by reinventing the wheel
« Last Edit: May 14, 2015, 03:49:08 am by Putnam »
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #7382 on: May 14, 2015, 04:00:59 am »

Any Javascript.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7383 on: May 14, 2015, 04:06:28 am »

oh, okay, I see

...i'm going to be completely honest and say that there may actually be something in jquery

there's probably another library or two that can do that kind of thing

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #7384 on: May 14, 2015, 04:10:26 am »

I use d3, jquery is too mainstream :P

To me though, it seems that the way the whole Internet thing is designed is Image classes are just a wrapper to a link to a location (the image source), and to actually edit the images you need to blit them to a canvas and go from there.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7385 on: May 14, 2015, 04:15:23 am »

i didn't even know jquery EXISTED when i wrote my websites, you have no hipster cred on me

Now that I think of it, why exactly are you asking?

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #7386 on: May 14, 2015, 04:20:59 am »

I'm making a little tech demo/toy thing that requires just-in-time image manipulation :P

I have to be able to edit pixels directly, plus be able to instantiate new images that don't have a URL source.

edit: Also, how would one create the "oil slick"-like colors in this image?



I actually can't think of a way they would do that @.@
« Last Edit: May 14, 2015, 06:11:37 am by Skyrunner »
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Spehss _

  • Bay Watcher
  • full of stars
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7387 on: May 14, 2015, 08:17:48 am »

In that case, go into settings->compiler. It'll open up a window; first screen will have a bunch of checkboxes. Check the one that mentions using the C++11 standards.
Thanks. Did this, it's working.
Logged
Steam ID: Spehss Cat
Turns out you can seriously not notice how deep into this shit you went until you get out.

i2amroy

  • Bay Watcher
  • Cats, ruling the world one dwarf at a time
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7388 on: May 14, 2015, 01:46:27 pm »

edit: Also, how would one create the "oil slick"-like colors in this image?



I actually can't think of a way they would do that @.@
I assume you could start with a number of suitable color blotches on a canvas, then just start doing grab and drag transforms of image sections until it was suitably oil like.
Logged
Quote from: PTTG
It would be brutally difficult and probably won't work. In other words, it's absolutely dwarven!
Cataclysm: Dark Days Ahead - A fun zombie survival rougelike that I'm dev-ing for.

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7389 on: May 14, 2015, 04:32:34 pm »

Quick question: Does anyone know if a Canvas is the only way to edit an image's pixels in Javascript?

The only other way I can think of to manipulate actual image data would be to take advantage of base64 encoded image data directly in an image tag.  I at least think you can do that.  You'd need to generate the entire image data (that is exactly as if you were saving it as a .png, .jpg or whatever, not just the pixel data), base64 encode it, then set the src attribute on the img tag to be the new base64 data.  Or something like that.

I'm positive some JavaScript library somewhere would support the base64 encoding if it isn't supported natively in browsers these days, but finding one that will help you access and manipulate individual pixel data of images in JavaScript is another issue entirely that I don't know any examples of.

Canvas is probably going to be 100x easier.
Logged
Through pain, I find wisdom.

Spehss _

  • Bay Watcher
  • full of stars
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7390 on: May 14, 2015, 06:42:31 pm »

Not sure how to word this question. In c++, how do I make a vector like I would make an array[][]. Like, say I've been using an array of chars: "char arr
  • [y]", and I want to replace it with a vector. How would I define it? Would it be "vector<char> arr
  • [y]" ?
Logged
Steam ID: Spehss Cat
Turns out you can seriously not notice how deep into this shit you went until you get out.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7391 on: May 14, 2015, 06:51:11 pm »

Which part do you want to replace with a vector? You want a 2D vector basically? Or do you want a vector with char array strings inside it?

Vector is a 1D data structure. To make it 2D you have to have a vector of vectors (analogous to what [][] does, an array of arrays).

vector<vector<char>> arr;

I'm not going to make any claims about how usable or efficient this is however. Each time you instantiate a template, it creates a copy of the entire code for that template's inheritance tree with the current template parameter. vector<vector<char>> creates two separate class heirarchies with copies of the complete "vector" codebase, but with different template parameters compiled in, one for vector<char> and the other for vector<vector<char>>. So the standard templates are great for rapid development, but terrible for bloating the size of your exe file.

I outlined how to roll-your-own 2D array class on an earlier page. Though my implementation is bare-bones, you can add specialized stuff to it easily.
« Last Edit: May 14, 2015, 06:59:06 pm by Reelya »
Logged

Spehss _

  • Bay Watcher
  • full of stars
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7392 on: May 14, 2015, 06:59:05 pm »

Which part do you want to replace with a vector? You want a 2D vector basically? Or do you want a vector with char array strings inside it?

Vector is a 1D data structure. To make it 2D you have to have a vector of vectors (analogous to what [][] does, an array of arrays).

vector<vector<char>> arr;

I'm not going to make any claims about how usable or efficient this is however. I outlined how to roll-your-own 2D arrays on an earlier page.

It's for storing data for a map level for a roguelike I'm making. Still in the super early stages. If there's a better way to store data for what basically amount to an x-y graph of ascii symbols with different traits, like the x-y coordinate, whether the tile is a floor or wall, etc, I'd love to know. Previously I was using an array[][] of chars just to make sure I could print it through curses.

Logged
Steam ID: Spehss Cat
Turns out you can seriously not notice how deep into this shit you went until you get out.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7393 on: May 14, 2015, 07:01:18 pm »

Code: [Select]
template <class T> class grid
{
    T *data;
public:
    int sizex, sizey;

    grid(int _sizex, int _sizey) : sizex(_sizex), sizey(_sizey)
    {
        data = new T[sizex * sizey];
    }

    ~grid() { delete [] data; }

    T &operator[](int x, int y) { return data[x + sizex * y]; }
}

// usage:
grid<char> charArray2D(20,20);

grid<mapTile> mapArray2D(80,25);

You can add anything you want to this, e.g. bounds-checking. But I designed this for access speed, so it assumes you've already screened your inputs.

Spehss _

  • Bay Watcher
  • full of stars
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7394 on: May 14, 2015, 07:02:49 pm »

Cool, another thing I never heard of. Off to Google I go then. Thanks for the example.
Logged
Steam ID: Spehss Cat
Turns out you can seriously not notice how deep into this shit you went until you get out.
Pages: 1 ... 491 492 [493] 494 495 ... 796