I'm baaaaaack! (With a new graphics project)

Discussion specific to projects ideas and support.
stryker001
Posts: 125
Joined: 29 Sep 2010, 18:07
Contact:

I'm baaaaaack! (With a new graphics project)

Post by stryker001 »

Hey, I'm back ;)

After a long absence due to college, life, etc. I had an idea today and was, for once, able to sit down and code the whole thing in two sittings.

I coded the proof-of-concept all at once, and technically wasn't even at my computer; I was at my church running the projection systems and remotely logged in to my computer through the LogMeIn app on my iPod touch. (I highly recommend this app to anyone and everyone who has an iProduct running iOS!!!) So using the little Retina Display I pulled up BricxCC and started punching in bits of code until I (as usual) ran into something I wasn't sure about.

I needed a way to draw a line on the screen from Point A to Point B. I knew how to draw lines already, but that's assuming I already have a value to feed into the Point x/y coordinates. I wanted random data in those, however, but I wanted a random number in the range of the screen dimensions. Now, I could easily have done this in NXT-G (*shudders*) but I really was curious as to how I could do it in NXC. I figured something along the lines of Random(99) would give me a number between 0 and 99, and it did. Worked great.

In fact I had it render two lines, with an end from each line connected, so as to (usually) form an angle. This was the other thing I needed to learn about: keeping rendered lines connected. After a bit of thinking I realized this could be accomplished by forming 6 variables: an X/Y pair for Point A, an X/Y pair for Point B, and an X/Y pair for Point C; then I could use Points A and B for the start and end of Line 1, and Points B and C for the start and end of Line 2. It worked like a charm and I ended up with this:
[youtube]www.youtube.com/watch?v=mUhU--RXQCo[/youtube]


After working out the few little kinks found in such a tiny simple program, I made this:
[yt]http://www.youtube.com/watch?v=6mluL1EbhR4[/yt]


I really like how it turned out. I'm going to attempt to use this for performances of music and visuals, most likely having the abstract data (which is being visualized by the bezier) converted into motor movements, which will move mirrors and reflect a laser beam. Or two. :D

I also think that I should be able to tweak the code so that I can, say, twist the knob of a motor and have the NXT read that data and make the bezier have more or less points, relevant to which way I turn the knob, and that sort of thing. I really want to just splice some cables and make an audio input jack to use instead of the microphone or light sensor, but I have a feeling I should really use optoisolators for that, just to be safe.

Any thoughts on the videos, concept, or anything at all would be greatly appreciated. The thing artists need most is feedback! ;) I might try to make a video with a soundtrack, with the bezier synced with/controlled by the song playing. That's probably far off, though, as I'm quite deep in a few other projects, including making the music to use for such things XD

Also, I know this is already a long post but I have to say: it's good to be back. Even if I'm just popping my head in here to read the last 25 forum threads and make a post, it really makes me feel so much better to be doing what I used to enjoy doing! ^_^
stryker001
Posts: 125
Joined: 29 Sep 2010, 18:07
Contact:

Re: I'm baaaaaack! (With a new graphics project)

Post by stryker001 »

and it seems no matter what I do I can't get it to embed the youtube videos.

first:
www.youtube.com/watch?v=mUhU--RXQCo

second:
www.youtube.com/watch?v=6mluL1EbhR4

bleh
inxt-generation
Posts: 290
Joined: 03 Oct 2011, 00:06
Location: Gallifrey
Contact:

Re: I'm baaaaaack! (With a new graphics project)

Post by inxt-generation »

Wow. That's great! Only two coding sessions, one through an iTouch. Impressive.

Embedding YT vids seems to be broken at the moment. :x
A.K.A. NeXT-Generation.
"A kingdom of heaven for RobotC now has recursion!"
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: I'm baaaaaack! (With a new graphics project)

Post by mattallen37 »

Very cool!
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
stryker001
Posts: 125
Joined: 29 Sep 2010, 18:07
Contact:

Re: I'm baaaaaack! (With a new graphics project)

Post by stryker001 »

inxt-generation wrote:Wow. That's great! Only two coding sessions, one through an iTouch. Impressive.
Embedding YT vids seems to be broken at the moment. :x
I certainly surprised myself with this one, especially because my previous physics demos had some massive bug where anything bouncing off horizontal surfaces would gain about 10,000x acceleration!

And thanks for the tip about YT. Kinda sucks but at least they're linked now :P
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: I'm baaaaaack! (With a new graphics project)

Post by mattallen37 »

For bouncing physics like this, I use a speed factor. Each frame, I add or subtract it from x (depending on what direction it's traveling), and I add or subtract the opposite of it from the total speed, from y. So, if the speed is 3.7 out of 5 (where 5 is the total speed), and the object is traveling up and right, I add 3.7 to x for each frame, and add (5-3.7=1.3) to y for each frame. Every time there is a collision, I Random()ly add or subtract 0-1 from the speed (floating point though), clip it to being no more than e.g. 4, and no less than e.g. 1, and I invert the direction of travel in the proper axis (e.g. change from adding to subtracting). The result is that I can control overall speed (such as 5 in this example), and I can get a nice effect of the object not always bouncing exactly as it would in a perfectly theoretical world (it doesn't go from a 30 degree angle, to another 30 degree angle, to another 30...).

Edit: Maybe after I get some sleep I can post an NXC example.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
stryker001
Posts: 125
Joined: 29 Sep 2010, 18:07
Contact:

Re: I'm back! (With a new graphics project)

Post by stryker001 »

That's awesome. From Day 1 I've kept the speeds in each dimension separate, so I'm calculating the X speed separate from the Y speed. This allows me to not have to set a total speed, because calculating a total speed like that doesn't quite follow normal physics XD

Also, I'm wondering if there's a better way to do something. For the sake of the program I'm writing, I need to create 4 variables for each point: its X coordinate, its Y coordinate, its X velocity, and its Y velocity. I'm basically labeling these as x1, y1, x1_vel, and y1_vel. The code (when giving them values the first time) is like so:

Code: Select all

  int x1 = (Random(99)); 
  int y1 = Random(63);   // Set the first point anywhere on the screen
  int x1_vel = Random(5);// and give it two random velocities.
  int y1_vel = Random(5);
Of course I have to copy-paste that for each point, and after some time it becomes annoying to change every instance of 1 to 2, and 3, and 4, and so on.

Is there a better way to create large amounts of multiples of code like that? I've used the same copy-paste technique in other programs, just going through and one-upping the names of the variables, but never thought to ask if there was a better way.
stryker001
Posts: 125
Joined: 29 Sep 2010, 18:07
Contact:

Re: I'm back! (With a new graphics project)

Post by stryker001 »

Around 600 lines of code later, I have everything all coded in and am ready for debugging. The first thing that happens when I hit 'compile' is an error telling me I should have another } at the end of the program, but I don't recall adding any tasks, loops, or if statements without adding } at the end... now I have to go through 635 lines of code to find the missing }
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: I'm baaaaaack! (With a new graphics project)

Post by mattallen37 »

If you use consistent white-space, it should be quite easy to find the error.

If you can't find it after a while, try commenting out sections, using /* and */ and see if that helps.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
nxtboyiii
Posts: 366
Joined: 02 Oct 2010, 07:08
Location: Everywhere

Re: I'm baaaaaack! (With a new graphics project)

Post by nxtboyiii »

Can you post some code of the project?
:D
Thanks
Thanks, and have a nice day,
nxtboy III

programnxt.com
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests