Skip to main content

Jelly Ball

One thing I enjoy when programming is to make weird interactive computer-generated objects. In this post, I'm showing you... a blob. To see the blob, simply click on the black box. The blob will immediately appear. Once you have the blob, you can drag it around with your mouse - just press down and move it around. When you let go, the blob will snap back with a little jiggle.


Click here!


There are a few things I'd like to point out about the blob:

First, when you stretch it, it actually gets narrower. When I designed this, I wanted it to shrink enough to look realistic, but not far enough that it looked weird.

Second, notice that it drags faster depending on how far you stretch it. The speed at which it drags is proportional to the square of the distance stretched. I found that this was much more realistic than making it directly proportional to the stretch. Also, if you only stretch it slightly, it doesn't drag at all (this simulates static friction).

Finally, there's gravity. The gravity isn't strong enough to drag the blob, but it is strong enough to stretch it slightly. When you first create the blob, it bounces slightly as a result of the gravity.


The graphics was probably one of the most interesting parts of writing this program. First I included my Firetools.js library for some simple graphics functions. Then I simply stacked a series of filled translucent circles. I placed the circles on a straight path from the base to the tip of the blob, and determined the size and color using some simple math.

One of the biggest challenges I faced in designing this blob was setting it up to move around the page. It took a long time to figure out how to disable the highlighting of text and the clicking of links below the blob. (For geeks who are interested in my solution, it involved disabling pointer events on the canvas, and using an event listener in the window to turn them back on whenever the mouse was over the blob.)

Overall, I'm really happy with my final result. I hope you enjoy it!


New posts every month - subscribe for free!


Comments

  1. hello I found you on khan academy and really like your projects!

    ---liah
    (http://myartandjournal.blogspot.com/)

    ReplyDelete

Post a Comment

Popular posts from this blog

Should Tau Replace Pi?

The digits of π, organized in a very new way Happy π-day! And happy π-month! Today's month and day - that is, March 14 or 3.14 - includes the first 3 digits of π. And today's month and year - March 2014 or 3.14 - also includes the first 3 digits of π. We won't have another double-day for π for the next 100 years, so enjoy this one! For the special occasion, I'm posting two π-related posts - one for π-month, and the other for π-day. In both posts, I'm setting the font size to approximately π * π + π + π. This is the first post, for π-month; to see the second, go to http://greatmst.blogspot.com/2014/03/pi-month-pi-day-post-2-5-common-pi-myths.html . In this post, I am including an essay I wrote about whether π or τ is the more superior constant. This was written for people who know very little about math, so the basic idea should be easy to understand even for people who are not mathematically inclined. Should Tau Replace Pi? A constant is any number or value that ne...

The Geminids

The Geminid meteor shower is coming up! At 2:00 AM, on December 14 (that's Thursday night, or Friday morning), you can see anywhere from 100 to 150 meteors per hour - depending on the sky and weather conditions. That's more than 1 meteor per minute! This particular meteor shower comes from a 5.1 km wide asteroid called 3200 Phaethon. Flecks of debris fall off this asteroid in a trail around the sun. These bits are called meteoroids . Every year, in December, Earth passes through this stream of meteoroids; when one of them enters Earth's atmosphere, it burns up and we see a meteor. If the meteor is brighter than Venus, it's called a fireball. Fireballs are much less common than meteors. This year, viewing conditions will be especially good; the peak occurs only 1 day past new moon. If you live in an area with lots of light pollution, you will definitely want to drive into the country. If you think the weather will be bad, go out a day or two before or after the peak. Kee...

Which Hurts More?

212° F Let's play a little game. I'll list a bunch of possible actions. Each action will have 2 variations, (a) and (b). You choose either (a) or (b), depending on which would be safer (or less painful). Each of the questions will involve an oven hot enough to bake a cake (350° F), and a pot of boiling water (assume we're at sea level). So... would you rather: 1.     (a) Stick your hand in the oven     (b) Stick your hand in the boiling water   ... for a period of 10 seconds 2.     (a) Leave a fork in the oven     (b) Leave a fork in boiling water   ... for a period of 15 minutes. Then hold the fork tight with your bare hand. 3. Fill a jar to the top with cool tap water. Then:    (a) Place the jar in the oven    (b) Place the jar in the boiling water   ... for a specific, but unknown, period of time. Then remove the jar and put your hand in it. First see if you can figure these out yourself. They shouldn't be too...