Laser Projector Code Thread

Let’s share the code of the Laser Projector!

2 Likes

Heres the code to the one shown in the development sneak peek thread.

[code]x’ = x + 10 * sin((time + fraction * 4) * tau);
y’ = y + 10 * cos((time + fraction * 4) * tau);

h = (fraction + time / 2) * 360;
s = 0.5;
v = 1;[/code]

5 Likes

I’ll be sharing two laser expressions I’ve created. Both expressions are best used with a white laser color, due to how the hue and saturation outputs work! This first one is a clock that shows the time as a series of four circles:

Video demonstration of this pattern

### DOT CLOCK TEST - CIRCULAR - SIDE-BY-SIDE

## Use rectangular coordinates, 255 (17 x 15) beams

## VAMPYRIUM'S NOTES
## This represents your local system time as a series of four circular
## formations, with hours, minutes, seconds, and centiseconds. The hour
## formation has a central beam that changes color based on if the time is AM or
## PM.
##
## The masks are a bit of a mess since the expression compiler doesn't handle
## any "equal" cases (equal, less than or equal, and grater than or equal).
##
## The "configuration" section can be edited to set your own custom hue values
## for the AM/PM beam.

# Configuration
amhue = 0;
pmhue = 240;

# Initialization: time
ftime = floor(time);
secs = ftime % 60;
mins = floor(ftime / 60) % 60;
hrs = floor(ftime / 3600) % 24;
ampm = (hrs > 11);
hrs = hrs % 12;
hrs = hrs + (12 * (hrs < 1));
csec = floor((time - ftime) * 100);

# Initialization: AM/PM color
ampmhue = (amhue * (ampm < 1)) + (pmhue * (ampm > 0));

# Initialization: laser index masks
secmask = index < 60;
cursecmask = index < secs;
minmask = (index > 59) * (index < 120);
curminmask = (index > 59) * ((index - 60) < mins);
hrmask = (index > 119) * (index < 144);
curhrmask = (index > 119) * ((index - 120) < hrs);
csecmask = (index > 143) * (index < 244);
curcsecmask = (index > 143) * ((index - 144) < csec);
ampmmask = (index > 243) * (index < 245);

# Expression
x' = ((20 * sin((index / 60) * tau) + 25) * secmask) 
   + ((20 * sin(((index - 60) / 60) * tau) - 25) * minmask)
   + ((20 * sin(((index - 120) / 12) * tau) - 75) * hrmask)
   + ((20 * sin(((index - 144) / 100) * tau) + 75) * csecmask)
   + (-75 * ampmmask);
y' = (20 * cos((index / 60) * tau) * secmask) 
   + (20 * cos(((index - 60) / 60) * tau) * minmask)
   + (20 * cos(((index - 120) / 12) * tau) * hrmask)
   + (20 * cos(((index - 144) / 100) * tau) * csecmask);

h = (((((y' + 360) / 4) + ((time * 100) % 360))
  + (90 * secmask)
  + (180 * minmask)
  + (270 * hrmask)) * max(max(max(secmask, minmask), hrmask), csecmask)) + (ampmhue * ampmmask);
s = 1;
v = (1 * cursecmask) + (1 * curminmask) + (1 * curhrmask) + (1 * curcsecmask) + (1 * ampmmask);

This second one projects a sweeping “rose” pattern:

Video demonstration of this pattern

### PULSATING & SWEEPING ROSE PATTERN
## Built by Vampyrium
## Ver. 1.0 2017-09-23 11:50 PM EDT
## Use with rectangular coordinates, AT LEAST 200 beams (20 x 10) for best results

## VAMPYRIUM'S NOTES
## "fraction" is not used here due to its range of [0,1]. Since we're working
## with angles and a design that loops here, that has the potential of causing
## two beams to shine in the same spot at the "beginning"/"end" where the
## design loops. The "relindex" implementation below obviates this issue.
##
## The laser expression feature as a whole is meant for exploration and
## experimentation, but if you don't know what you're doing, just try
## changing the values in the "Configuration" section. If using whole
## numbers for "k", try a maxangle of 2*pi (or tau) for even numbers and pi for
## odd numbers.
##
## Much more information on rose graphs can be found here, if you're so inclined:
## https://en.wikipedia.org/wiki/Rose_(mathematics)

# Initialization
relindex = index/count;


# Configuration
time_offset = time;
k = 0.4;
c = cos(time_offset) * 0.05;
size = 100;
maxangle = pi * 10;

# Masks
firsthalf = (relindex < 0.5);
lasthalf = (firsthalf < 1);

# Expression
relangle = relindex * maxangle;
cos_k_relangle_c = cos(k * relangle) + c;
x' = size * cos_k_relangle_c * cos(relangle);
y' = size * cos_k_relangle_c * sin(relangle);

h = (((relindex * firsthalf) + ((1-relindex) * lasthalf)) * 120) + (time_offset * 120);
s = 1;
v = ((cos((relindex * pi * 8) + (time_offset * 3))) / 2) + 0.5;
8 Likes