|
are you looking for a for loop?
|
# ? Jun 7, 2015 03:45 |
|
|
# ? May 26, 2024 05:34 |
|
you have definitely found the right thread
|
# ? Jun 7, 2015 03:46 |
|
Bloody posted:what does this post even say hey now that is not in the spirit of this thread articulating programing things is really hard
|
# ? Jun 7, 2015 03:50 |
|
try not to use globals if u can help it, it will make your life easier. good luck with that though if your on a micro lol
|
# ? Jun 7, 2015 04:20 |
|
Bloody posted:you have definitely found the right thread truth i know for loops. it just feels like the way I'm implementing a function that I need to have happen over time is... kludgy. like, surely there is a better way to do it than to have the function re-calculate parts of itself every time it gets called, but then when I get into static variables the function could hold, it limits the ability to run multiple instances of the function during the loop
|
# ? Jun 7, 2015 05:19 |
|
Fanged Lawn Wormy posted:truth this post right here is exactly why C should not be a starter language.
|
# ? Jun 7, 2015 05:21 |
|
Okay, so correct me if anything here isn't what you're actually doing/trying to do... 1. You want to slowly fade from one colour to another, over time 2. You have some sort of message loop that you're using to call your fade function every now and then 3. Your fade function uses static (i.e. global) variables to keep track of how much fading it's already done/how much it still needs to do I think the first step is to know what structs are and how to use them. A struct is just a way to wrap up a whole bunch of values and pass them around all in one thing. As a warm-up, try writing a struct to represent "colour", and rewrite your existing functions to use it instead of passing around an array of three values. The next important thing to do after that is to split out the "I want to do a fade from Cyan to Magenta" bit from the "here's what I call every tick to perform one step of the fade". You'll find structs useful here.
|
# ? Jun 7, 2015 05:42 |
|
thanks that's reassuring. I initially wanted to write this function w/ structs, but got intimidated and backed out. I think I'm going to re-try it now with structs to learn that part, and see where it rolls from there
|
# ? Jun 7, 2015 05:52 |
|
Fanged Lawn Wormy posted:thanks that's reassuring. I think a struct is a lot like what you're imagining a class is, in your head, so your class instinct was right.
|
# ? Jun 7, 2015 05:54 |
|
|
# ? Jun 7, 2015 06:11 |
|
Fanged Lawn Wormy posted:truth i'm not entirely sure this is what you're looking for, but a lot of what you're saying strongly points me toward the concept of dynamic programming. specifically, your mentions of calling the function repeatedly and recalculating parts of it each time sort of scream out for some caching to me. basically, the first time you do a fade from a particular state, you cache the inputs and outputs, and next time those particular inputs come up, you go to the cache instead of recalculating. i may be misunderstanding a bit about the amount of potential states and the amount of calculation going on though. wikipedia posted:In order to solve a given problem, using a dynamic programming approach, we need to solve different parts of the problem (subproblems), then combine the solutions of the subproblems to reach an overall solution. Often when using a more naive method, many of the subproblems are generated and solved many times. The dynamic programming approach seeks to solve each subproblem only once, thus reducing the number of computations: once the solution to a given subproblem has been computed, it is stored or "memo-ized": the next time the same solution is needed, it is simply looked up. the result in the cache would probably be the next step in the fade, based on what i'm understanding. then you'd basically end up with a cache of [start value, end value, # of steps] -> new RGB value and hopefully those are reusable. i'm assuming that if you get to the same start and end rgb values and number of steps remaining, the result will be the same, regardless of how many total steps you're taking.
|
# ? Jun 7, 2015 14:17 |
|
Fanged Lawn Wormy posted:thanks that's reassuring. http://stackoverflow.com/questions/13488957/interpolate-from-one-color-to-another pass in the initial time, elapsed time, and fade times as parameters to determine how much interpolation there should be between an initial colour and end colour. then use this decided interpolation to return the interpolated colour. your program will be more composable if you have separate functions for:
a recursive function for colour interpolation over time sounds like a bad idea encapsulating these colour interpolation functions so they don't reference global or static variables will make them re-usable for multiple ui components comedyblissoption fucked around with this message at 14:49 on Jun 7, 2015 |
# ? Jun 7, 2015 14:47 |
|
on the topic of encapsulating state... its as simple as stuffing all your state variables into a struct. you can then pass those objects to functions with a pointer and treat C functions like OO methods. idk anything about color, so say you're writing a synthesizer instead, code:
code:
code:
|
# ? Jun 8, 2015 07:35 |
|
stick some function pointers in the struct that take the struct and now you've created an
|
# ? Jun 8, 2015 13:47 |
|
don't sign your pooooosts
|
# ? Jun 8, 2015 14:35 |
|
there are some good reasons to create a struct of function pointers. like if you want to create an interface/protocol, or group a set of callbacks. e.g. iirc a bsd device driver has an instance of some struct that points to the open/close/read/write/&c functions that do the needful. C is great/terrible. you can get away with doing basically what ever you want. for instance, you can do single inheritance with structs! code:
dont, tho bc anyone else will look at you and say Bloody posted:and now you've created an
|
# ? Jun 8, 2015 15:15 |
|
i unironically frequently create structs of unions of structs of unions of structs
|
# ? Jun 8, 2015 15:16 |
|
unions are good and will free us from the tyranny of the class system
|
# ? Jun 8, 2015 17:48 |
|
Soricidus posted:unions are good and will free us from the tyranny of the class system
|
# ? Jun 8, 2015 18:36 |
|
Bloody posted:i unironically frequently create structs of unions of structs of unions of structs and pay what, two hours of debugging time per byte of ram saved?
|
# ? Jun 8, 2015 19:11 |
|
Soricidus posted:unions are good and will free us from the tyranny of the class system
|
# ? Jun 8, 2015 19:40 |
|
been listening to the old quake soundtrack whilst coding and it's very good. A++++ recommended. bye
|
# ? Jun 8, 2015 21:25 |
|
suffix posted:and pay what, two hours of debugging time per byte of ram saved? 0 seconds of debugging time for glorious in-place packet munging
|
# ? Jun 8, 2015 21:41 |
|
its literally my one-size-fits-most plug-n-play serial port interrupt pile-o-poo poo handler
|
# ? Jun 8, 2015 21:42 |
|
80% of my job most days is fling poo poo from a pc serial port to a spi port or something so its nice to have pleasant ways of doing that and struct-union-struct-union-struct-... blobs are comedically effective at it
|
# ? Jun 8, 2015 21:42 |
|
Power Ambient posted:been listening to the old quake soundtrack whilst coding and it's very good. A++++ recommended. bye thank you for this excellent life advice
|
# ? Jun 8, 2015 21:46 |
|
Bloody posted:80% of my job most days is fling poo poo from a pc serial port to a spi port or something so its nice to have pleasant ways of doing that and struct-union-struct-union-struct-... blobs are comedically effective at it so basically protocol buffers
|
# ? Jun 9, 2015 01:39 |
|
is there any way to do arbitrary bit swizzling with union-struct-...-union-structs? like ABCDEFGH -> AEBFCGDH?
|
# ? Jun 9, 2015 02:17 |
|
eschaton posted:so basically protocol buffers roll-your-own but yeah pmuch
|
# ? Jun 9, 2015 02:24 |
|
|
# ? Jun 9, 2015 05:27 |
|
jesus loving christ thanks microsoft for convincing me that i was going insane: http://stackoverflow.com/questions/5918534/why-cant-i-add-a-subfolder-in-a-f-project
|
# ? Jun 9, 2015 20:24 |
|
is there a sane way to use java classes generated by an .xsd xml schema as the data model in a desktop application? as a test, i injected an EventBus.post into the generated classes setters, and then put corresponding event handlers in the viewer, but it feels... not right
|
# ? Jun 9, 2015 22:13 |
|
OData looks kinda cool in theory but I bet it's really not in practice confirm deny
|
# ? Jun 9, 2015 22:36 |
|
AWWNAW posted:OData looks kinda cool in theory but I bet it's really not in practice the first link googling for OBdata is a ufo forum. not the kind of object oriented source you want to be taking cues from i think
|
# ? Jun 9, 2015 22:39 |
|
Barnyard Protein posted:is there a sane way to use java classes generated by an .xsd xml schema as the data model in a desktop application? as a test, i injected an EventBus.post into the generated classes setters, and then put corresponding event handlers in the viewer, but it feels... not right it doesn't feel right because it's probably dumb. why would pub sub logic be in your POJOs? don't do that.
|
# ? Jun 9, 2015 22:47 |
|
rrrrrrrrrrrt posted:it doesn't feel right because it's probably dumb. why would pub sub logic be in your POJOs? don't do that. who does the publishing then? the code that is making changes to the model (ie the controller)?
|
# ? Jun 9, 2015 22:51 |
|
gonadic io posted:jesus loving christ thanks microsoft for convincing me that i was going insane: http://stackoverflow.com/questions/5918534/why-cant-i-add-a-subfolder-in-a-f-project
|
# ? Jun 10, 2015 00:12 |
|
if you search online more about this F# limitation, youll find a bunch of stockholmed programmers defending it as making your code better because this is obviously the only way to prevent cycles in your definitions
|
# ? Jun 10, 2015 00:13 |
|
I like the way java does file structure. one public class per file, one package per directory, names must match. it has downsides too and the visibility rules could be better but whenever I read about poo poo like f# I realise how good I have it
|
# ? Jun 10, 2015 00:19 |
|
|
# ? May 26, 2024 05:34 |
|
Barnyard Protein posted:who does the publishing then? the code that is making changes to the model (ie the controller)? sounds fine
|
# ? Jun 10, 2015 00:38 |