Try now in the
Open Cloud »
(no sign-in required)

Random Scribbles in 2D and 3D

Simulate scribbling by joining random points using smooth curves.

Run the code to make a line joining 30 random points. Try more than 30 points:

SHOW/HIDE DETAILS

This draws a line through the points at coordinates {0,0}, {1,1}, and {2,0}:

In[1]:=
X
Out[1]=

Turn on axes with AxesTrue in order to see the numeric coordinate positions:

In[2]:=
X
Out[2]=

Use RandomReal to draw a line with random coordinates.

This gives a random number between 0 and 1. Each time you run the code, you get a different number:

In[3]:=
X
Out[3]=

This gives a pair of numbers between 0 and 1. Each time you run the code, you get a different pair:

In[4]:=
X
Out[4]=

This gives four pairs of random numbers:

In[5]:=
X
Out[5]=

Use RandomReal to draw a line with 30 random coordinates:

In[6]:=
X
Out[6]=

HIDE DETAILS
In[1]:=
X
Out[1]=

Join the points with a Bezier curve instead. Try more than 30 points:

SHOW/HIDE DETAILS

Make a smooth curve by replacing Line with BezierCurve.

Heres a Line through 6 random points (you can ignore SeedRandom for the moment; well explain it later):

In[1]:=
X
Out[1]=

Heres a BezierCurve based on the same 6 points:

In[2]:=
X
Out[2]=

Here are the Line and BezierCurve drawn together so you can see how they correspond. The Bezier curve doesnt pass through all of the points, but is guided by them:

In[3]:=
X
Out[3]=

HIDE DETAILS
In[1]:=
X
Out[1]=

Make the curve thicker. Try thicknesses other than 5for example, 10:

SHOW/HIDE DETAILS

AbsoluteThickness specifies how thick to draw lines and curves. The thickness is measured in points, a standard measure used by printers (one point is 1/72 inch):

In[1]:=
X
Out[1]=

HIDE DETAILS
In[1]:=
X
Out[1]=

Make an interactive scribble, with a seed to determine the random choices. Drag the sliders to get different scribbles:

SHOW/HIDE DETAILS

This makes a random scribble with 30 points:

In[1]:=
X
Out[1]=

You can make an interactive interface to control the number of points in the scribble using Manipulate.

Wrap the scribble expression with Manipulate[...], replace 30 with the variable length, and specify that length varies from 10 to 200 in steps of 1. Drag the slider to get random scribbles of various lengths:

In[2]:=
X
Out[2]=

The scribble jumps around as you drag the slider because RandomReal gives different coordinate positions each time.

If you add SeedRandom[12345] to the code, the scribble stays the same as you drag the slider, but gets longer and shorter. Thats because SeedRandom resets the random number generator to the same point each time the scribble is drawn, so that you get the same sequence of random numbers:

In[3]:=
X
Out[3]=

You can give SeedRandom a different number54321 instead of 12345to reset the random number generator to a different point, and get a different scribble:

In[4]:=
X
Out[4]=

You might as well make the seed interactive too, so that you have a control that chooses the scribble:

In[5]:=
X
Out[5]=

HIDE DETAILS
In[1]:=
X
Out[1]=

Draw a random line in 3D. Try more than 30 points:

SHOW/HIDE DETAILS

If you know how to draw scribbles in 2D, its easy to do the same thing in 3D.

Heres a 2D scribble:

In[1]:=
X
Out[1]=

Replace Graphics with Graphics3D and RandomReal[1,{30,2}] with RandomReal[1,{30,3}] so the line has 3D coordinates instead of 2D. Thats it. You can rotate the scribble with the mouse:

In[2]:=
X
Out[2]=

HIDE DETAILS
In[1]:=
X
Out[1]=

Draw a Bezier curve scribble in 3D. Try more than 30 points, or thicknesses other than 5:

SHOW/HIDE DETAILS

Make a smooth 3D curve by replacing Line with BezierCurve:

In[1]:=
X
Out[1]=

HIDE DETAILS
In[1]:=
X
Out[1]=

Make it interactive. Drag the sliders to get different 3D scribbles. Rotate the scribbles with the mouse:

In[1]:=
X
Out[1]=

Share ItMake an interactive scribble website:

SHOW/HIDE DETAILS

Deploy the Manipulate to the Wolfram Cloud where anyone with a browser can use it:

In[1]:=
X
Out[1]=

Click the link in the output to visit the site.

Share the link by right-clicking it and choosing Copy Address. Paste the link into an email, tweet, or other message.

HIDE DETAILS
In[1]:=
X
Out[1]=