Create Square Wave Object

Hi all,
I am trying to generate a 3d object in the form of a Square wave but can’t seem to find a good way to do it. I’m sure I’m just forgetting about some operator…

I’ve tried using a wave chop to generate the Square wave and manipulating the Y axis of a SOP with it, but I wasn’t able to get the X axis to hold during the y value change so it wasn’t a 90 degree turn.

The goal is to generate paths that randomly turn at 90 degree angles.

I’ve simplified my project and uploaded what I’ve achieved using python, but I would rather use built in chops/sops.

This is the look I’m going for, minus any randomness.
Square Wave Pattern SOP.PNG

This is the code -

[code]import math
import random
table = op(‘table2’)
table.clear()
table.appendRow((‘index’,‘P(0)’,‘P(1)’,‘P(2)’,‘Pw’))

numPoints = 20

def build_box():
xPos = 0
previousYPos = 0
for i in range(1,numPoints+1):

	#create the square wave pattern
	yPos = math.ceil(math.sin(i))

	# if the y value changes, pass
	# else, keep incrementing the value
	if previousYPos == yPos:
		xPos = i

	previousYPos = yPos
	
	#create sop table
	table.appendRow((i,xPos,yPos,0,1))

build_box()[/code]

Does anyone have advice on how to create this pattern without python or GLSL? Also, advice on randomizing these paths would be greatly appreciated as well!

Thanks!
square_noise_pattern.tox (3.14 KB)

Usually better to use Patterns CHOP, it’s sort of the successor to the Wave CHOP.

Here’s an example with a random pattern that maybe helps your further
sop_from_patternchops.tox (1.16 KB)

Thanks for the reply!
I had tried this technique, but I believe you need to use a large number of points to achieve the desired effect. In this case, because I plan on making many many instances of this pattern, I’m trying to use as few points as possible. (I also have the time to experiment)

The pattern chops you provided use 1000 samples. When I bring down the length to something like 150 or smaller I get the same problem I had with the wave chop - the lines are not perfectly vertical. I believe it’s because the tx channel continues to increase when the ty changes, causing the angle.

Here are the channels that the python script creates with only 20 samples (without the randomness) which I believe is closer to what I’m looking for. I hold the tx whenever ty changes.

Square wave chop pattern.PNG

Can I create that with a pattern chop? Once I do begin to make parts of it random, I want to be able to ensure everything lines up.
Thanks again!

aah you are right, sorry I totally overlooked that.
Here’s an updated version with only 50 samples which uses a Script CHOP to correct any CHOP input you feed it.(as long as the channels are named tx, ty and tz. Currently I would not know of a way to achieve this in CHOPs only without any code.

So it still uses python which you did not want, but on the other hand you can play with the CHOPs to generate output.

If you need more speed than python can give it would be fairly easy to create a C++ CHOP that does the same as this script CHOP. If you have never tried c++ this would be a great simple case to start with.
sop_from_patternchops_V2.tox (1.87 KB)

This is perfect, exactly what I’m looking for! I took your advice and used this as motivation to learn how to write a C++ chop. I’ve uploaded it in case anyone else needs something like this.
Thanks again,
Tim
SquareWaveCHOP.zip (15.5 KB)