Wolfram Archive
Wolfram Programming Lab is a legacy product.
All the same functionality and features, including access to Programming Lab Explorations, are available with Wolfram|One.
Start programming now. »
Try it now »
(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}:

Graphics[Line[{{0, 0}, {1, 1}, {2, 0}}]]

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

Graphics[Line[{{0, 0}, {1, 1}, {2, 0}}], Axes -> True]

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:

RandomReal[1]

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

RandomReal[1, 2]

This gives four pairs of random numbers:

RandomReal[1, {4, 2}]

Use RandomReal to draw a line with 30 random coordinates:

Graphics[Line[RandomReal[1, {30, 2}]]]

HIDE DETAILS
Graphics[Line[RandomReal[1, {30, 2}]]]

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):

SeedRandom[123]; Graphics[Line[RandomReal[1, {6, 2}]]]

Heres a BezierCurve based on the same 6 points:

SeedRandom[123]; Graphics[BezierCurve[RandomReal[1, {6, 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:

Graphics[{ SeedRandom[123]; Line[RandomReal[1, {6, 2}]], Red, SeedRandom[123]; BezierCurve[RandomReal[1, {6, 2}]] }]

HIDE DETAILS
Graphics[BezierCurve[RandomReal[1, {30, 2}]]]

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):

Graphics[{AbsoluteThickness[5], BezierCurve[RandomReal[1, {30, 2}]]}]

HIDE DETAILS
Graphics[{AbsoluteThickness[5], BezierCurve[RandomReal[1, {30, 2}]]}]

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:

Graphics[{AbsoluteThickness[5], BezierCurve[RandomReal[1, {30, 2}]]}]

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:

Manipulate[ Graphics[{AbsoluteThickness[5], BezierCurve[RandomReal[1, {length, 2}]]}], {length, 10, 200, 1} ]

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:

Manipulate[ SeedRandom[12345]; Graphics[{AbsoluteThickness[5], BezierCurve[RandomReal[1, {length, 2}]]}], {length, 10, 200, 1} ]

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

Manipulate[ SeedRandom[54321]; Graphics[{AbsoluteThickness[5], BezierCurve[RandomReal[1, {length, 2}]]}], {length, 10, 200, 1} ]

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

Manipulate[ SeedRandom[seed]; Graphics[{AbsoluteThickness[5], BezierCurve[RandomReal[1, {length, 2}]]}], {length, 10, 200, 1}, {seed, 12345, 67890, 1} ]

HIDE DETAILS
Manipulate[ SeedRandom[seed]; Graphics[{AbsoluteThickness[5], BezierCurve[RandomReal[1, {length, 2}]]}], {length, 10, 200, 1}, {seed, 12345, 67890, 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:

Graphics[{AbsoluteThickness[5], Line[RandomReal[1, {30, 2}]]}]

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:

Graphics3D[{AbsoluteThickness[5], Line[RandomReal[1, {30, 3}]]}]

HIDE DETAILS
Graphics3D[{AbsoluteThickness[5], Line[RandomReal[1, {30, 3}]]}]

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:

Graphics3D[{AbsoluteThickness[5], BezierCurve[RandomReal[1, {30, 3}]]}]

HIDE DETAILS
Graphics3D[{AbsoluteThickness[5], BezierCurve[RandomReal[1, {30, 3}]]}]

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

Manipulate[ SeedRandom[seed]; Graphics3D[{AbsoluteThickness[5], BezierCurve[RandomReal[1, {length, 3}]]}], {length, 10, 200, 1}, {seed, 12345, 67890, 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:

CloudDeploy[ Manipulate[ SeedRandom[seed]; Graphics3D[{AbsoluteThickness[5], BezierCurve[RandomReal[1, {length, 3}]]}], {length, 10, 200, 1}, {seed, 12345, 67890, 1} ], Permissions -> "Public" ]

Click on the link in the output to visit the site.

Tell the world about your creation by sharing the link via email, tweet, or other message.

HIDE DETAILS
CloudDeploy[ Manipulate[ SeedRandom[seed]; Graphics3D[{AbsoluteThickness[5], BezierCurve[RandomReal[1, {length, 3}]]}], {length, 10, 200, 1}, {seed, 12345, 67890, 1} ], Permissions -> "Public" ]