# Python to SNAP conversion help sought!

Maths Python to Snap! block simple solution hopefully....
My knowledge of Python is limited. It all comes down to this last line on the Python script. In its simplest form just just add this variable (t) to that variable (inc) and add one to that (t) and then repeat in a sequential loop. But this last line of Python code has me stumped on my conversion, nothing works for me. t+=inc Any help appreciated on this challenge.
Thanks,

Pip

## from turtle import * from math import sin, cos, pi r=200 inc=2pi/100 t=0;n=1.5 for i in range(100): x1=rsin(t); y1=rcos(t) x2=rsin(t+n);y2=r*cos(t+n) speed('fastest') penup(); goto(x1,y1) pendown();goto(x2,y2) t+=inc

CHANGE t BY inc

under Variables.

Hi bh, I did try that but it did not work for me. You can have a look here and see what you think. Your suggestions welcome, this is as far as I got... its nearly there but not quite as i hoped.

Probably it's not working because you're expecting the trig functions to use angles in radians but we use angles in degrees.

In Python, you have to use the * operator to multiply. Having "2" and "pi" next to each other will result in a "SyntaxError: invalid syntax".

Good point. I had not noticed from my example Python script that my ‘cut-and-paste’ had removed all the asterisks ‘*’ on this forum. I am trying again here: I think it was the conversion from radians to degrees that originally made me confused. And you are right to point that out, thanks.

Hopefully this is correct with the asterisks:

from turtle import *
from math import sin, cos, pi
r=200
inc=2pi/100
t=0;n=1.5
for i in range(100):
x1=r
sin(t); y1=rcos(t)
x2=r
sin(t+n);y2=rcos(t+n)
speed('fastest')
penup(); goto(x1,y1)
pendown();goto(x2,y2)
# t+=inc
t+=inc # (increment angle for sin)

Fiddle. Its removed the asterisks (again). Oh well!
So - If anyone wants to play with it its also here:

Try putting 3 backticks () before and after your code to format it as code. If you need to put asterisks in non-code, you can try prefixing each with a backslash (\).

if you want to draw a circle, try something like

pen down
for i = 0, steps
go to (radius * cos(i * 360 / steps)) (radius * sin(i * 360 / steps))
pen up


you can also use

pen down
for i = 0, steps
move dist
rotate by (360 / steps)
pen up


you can sorta change this if you want it to draw a dotted circle by using pen up and pen down` in an if statement
you could also toggle the pen on and off