Intro to Python Scripting: 07 Control Flow IF ELIF ELSE
In this tutorial we look at control flow for our scripts. We take a look at IF ELIF and ELSE statements and how to use those to let out code make decisions. We also talk briefly about modulo and modular arithmetic. This can sometimes be a bit confusing if you haven't worked with it, but it is very handy for creating patterns.
#If/Else Statements import rhinoscriptsyntax as rs color01 = [255,0,255] #magenta color02 = [0,255,255] #cyan color03 = [125,38,205] #purple rs.EnableRedraw(False) for x in range(0,100,1): for y in range(0,100,1): pt = rs.AddPoint(x,y,0) if x % 3 == 0 and y % 5 == 0: rs.ObjectColor(pt,color01) elif x % 3 == 0 or y % 5 == 0: rs.ObjectColor(pt,color02) else: rs.ObjectColor(pt,color03) rs.Redraw()
Want to Contribute?
Want to be an author? Drop us a line here we'd love to have you.
Already have a video you'd like to post? Send us a link and we'll get you going.