let's make a CLI particle system :D 1700 let's make it in C so it can use structs 1701 [oh! also i started a c++ numeric solver but it turns out improvements i had added in my head were non-logical. so i had a whole bunch of ways to do it that didn't go together, all thinking the way to do it was to put them together :s . so it's kind of on hold. but one of the cool parts is that you can make an expression template system in only 1 class if you parameterize it with e.g. a function pointer or enum for the operation.] 1702 1703 ok how will we do display, it would be normal to use curses, right? but it could stimulate stopping to review the api too much. it could also stimulate stopping to copy code out of an AI. maybe i could just make a basic curses thing ... whta do i need. i just want to plot a pixel. blitting a buffer is a plus. hey, maybe I can write directly to the tty device. 1703 1704 that could work, then maybe i'll hardcode height and width? and ... hmm can i blit to the tty fast? 1705 it's a little slow to ... oh but i'm using cli for loops i should instead write to a buffer file 1705 1706 cat buf > /dev/tty seems to be fast enough for my vision for now. ok. 1719 i drafted structs. it looks like environment variables LINES and COLUMNS can get resolution ! oops i didn't make the display structure resizeable but i think it's not too hard to do 1737 i'm nerdsniped by random numbers a little. a problem that must have been solved a million times, how to produce a uniformly distributed integer in C, between two provided integers? thinking a correct way could be to figure out the chunk before RAND_MAX that is not modulo 0 the range, and to reselect a number if it's in that range. then otherwise just take the modulo. so ummmmmmmmmmmmm modulo gives remainder. so i think we want num < (RAND_MAX - (RAND_MAX % size)) unsure ... 1738 1748 here's what i drafted. maybe i'll websearch now and see what might be normal. ... wait there are type issues i should fix. 1750 1751 ok here's what i have: long int randi(long int start, long int end) { long int size = end - start; assert(size <= 0xffffffff); // to preserve uniform distribution, retry if greater than rand_max uint32_t rand_max = 0xffffffff - (0xffffffff % size); uint32_t r; do { r = mrand48(); } while (r >= rand_max); return start + (r % size); } 1752 it looks like this is what others do too, although i'm curious regarding solutions that don't involve looping. one approach is to consider the whole scale rather than the modulo, although this wasn't immediately seeming popular enough to find a discussion of aliasing issues. 1753 1755 i'm reading about linux timers to figure out how to get a media clock and starting to get task inhibition it was pretty cool to get this far, again. maybe continuing is what's up. 1756 1806 ok now i'm triyng to figure out how to get a nanosecond time-passed from two timespec structs. - if they have the same seconds, the nsec fields can be subtracted - if one second has advanced, the first nsec field can be inverted and added to the second - if more than one second has advanced, that number times a billion would be added to the above can i unify that ... ? into like a single expression without too many conditions? 2 and 3 can clearly be unified by treating 2 as 3 with 1-1=0 thinking of the theory ... basically when tv_sec difference is greater than 1, than those tv_secs between are fully filled. but when it is only 1 there are only partial tv_sec differences. when it is 0 these partial differences happen to be in the same tv_sec window ... it's kind of like ... i could maybe offset one of them by a billion, and compensate somehow ... right so i would subtract 1 from the newer tv sec, and then add a billion to the newer tv_nsec. :) i think it works. 1808 . thinking how to check this that i have not made a mistake as likely ... let's consider if the tv_secs are the same. then new_tv_sec becomes tv_sec - 1, and new_tv_nsec becomes +1000000000 so then (-1*1000000000) + (a + 1000000000 - b) == a - b :) wondering if i can do it without a negative to get that extra bit of magnitude 1810 fixed power cabling at library by nudging it i think negative can be removed by noticing wher eit comes from. (new_tp.tv_sec - old_tp.tv_sec - 1) * 1000000000 + (new_tp.tv_nsec + 1000000000 - old_tp.tv_nsec) now this looks like it would be the same as simply taking the scaled differences ! that is it would be the same as: (new_tp.tv_sec - old_tp.tv_sec) * 1000000000 + new_tp.tv_nsec - old_tp.tv_nsec let's check the 3 conditions 1. tv_sec difference is 0 this works because it's just the nsec difference 2. tv_sec difference is 1, new_tp.tv_nsec < old_tp.tv_nsec this works because the 1 turns into 1 billion and performs the subtraction with the old_tp.tv_nsec 3. tv_sec difference > 1 this should work too because it juts adds 1 billion for the intervals a little discouraging that this wasn't more intuitive to me, but i think it might work (i usually make mistakes of course) 1813 1814 oh let's websearch for doing this and see how others do it :) 1833 i posted https://stackoverflow.com/a/78983909/129550 although it's unchecked . i'm a little confused around the lifetime of the particles. relates coding inhibitions. one way i made particles as a kid was to slowly fill an array as the particles were generated but somehow i would also use fixed-size arrays, i wonder how this worked ?? it's weird cause there are inhibitions (amnesia triggers, roughly) around the intuition and parts of considering it uhhh so if i wanted them to spawn like at a set rate, how would i do this? ... i could have a timepoint when the next would spawn, and check this :) ok but atm i have time diffs not time points ... i guess i would need to accumulate these until they hit a threshold, and wrap around the overflow! 1840 still working with time, more inhibs. making an absolute time now! 1842 ok with the absolute time it's easy to figure out when to make another particle maybe but how does this line up with a fixed-size array? ok! maybe instead of giving particles a lifetime or a screen edge, we would cycle them when the array cycles. that sounds workable for a start. 1842 2003 ok i got something to compile and run, with concerns: - dumping a buffer to /dev/tty makes it scroll a lot, i might need a frame delay to make that work (it's not hard to find ways to home the cursor, have not done this here) - it segfaults unless run in gdb, when in gdb it runs fine ;p