java falling matrix code (like the movie)

2019-06-04 23:12发布

If you wanted to write a program in java that uses a JFrame to simulate the falling green code from the matrix movie using ascii string characters so it looks exactly like this php example

http://mgccl.com/2007/03/30/simple-version-matrix-like-animated-dropping-character-effect-in-php

what would be the best way of doing it? labels, drawString? etc...

I know that within a for-loop for example you could use the integer value i to decrease the y-axis values, darken the color setColor(new Color(255, 255 - (i * 5), 255));

but i don't know how you would leave the "imprint" behind.

thanks

标签: java graphics
2条回答
可以哭但决不认输i
2楼-- · 2019-06-04 23:26

This example shows how to fade text using alpha transparency, while this example illustrates how to fade text by varying the color saturation.

Addendum:

What would be the best gui layout to use?

I'd solve the problem in a single, columnar JPanel that is as wide as the chosen Font and arbitrarily tall. Use a javax.swing.Timer to control animation. Then use a new GridLaylout(1, 0) to contain any number of such columns as a single row.

查看更多
老娘就宠你
3楼-- · 2019-06-04 23:47

Once you reach 0 for i, you just start doing to same for two other channels so it will gradually turn black or disappear.

setColor(new Color(255 - (i * 5), 0, 255 - (i * 5)));

The length depends on the step size (which is 5 in your case and thus the length of the imprint is 51). So if you want short imprint, you have to do numSteps = 255 / length of the imprint (rounding issue should not be ignored):

i = numSteps..0
setColor(new Color(255 - (i * step), 0, 255 - (i * step)));
查看更多
登录 后发表回答