Showing posts with label ellipse(). Show all posts
Showing posts with label ellipse(). Show all posts

Wednesday, June 17, 2015

String of Random Circles!

Today I will be changing this program (by Cater Beeman/Karsten Weiss on Open Processing) to Python mode. 

As usual the first thing we will do is change void setup(){} and void draw(){} to def setup (): and def draw (): and get rid of all the semi colons (;) and all the curly brackets ({}) and add colons (:)next to all the if statements. Now get rid of the word float and the word break, as we do not need use these in this case in Python. So far your code should look like this:



Now we are going to get rid of the lines of code; switch(key) and case 'c': and instead put in  key.lowcase == "c" Your code will look like this: 

When you run it you should get a program that draws something like this (when you click and drag the mouse): 


Friday, June 12, 2015

combineCircular!

Today we will be converting this program by tara milani on open processing from java to python. This program uses math to draw a series of ellipse to make a pattern. 

As usual the first thing we will do is change void setup(){} and void draw(){} to def setup (): and def draw (): and get rid of all the semi colons ( ; ) Next we are going to get rid of the word float everywhere it appears, we d this because we do not need a float to declare a variable in python. So far your code should look like this:



 Now, right under def draw (): we are going to add global a (new line) global b (new line) global y (new line) global x We do this because in python when a variable is called in only looks for the variable under the draw function, but by adding global it knows to look outside the function. Your code should now look like this: 





Now you're done, your code should print out a program that draws a series of circles into a pattern. 



Thursday, June 11, 2015

Parabola!

In this tutorial I will be changing this code (made by 유창희 on open processing) to python from java. This code prints out a program that draws a parabola using math functions.   

First things first, we are going to change void setup(){} and void draw(){} to def setup (): and def draw (): Than delete all the semi colons and 
indent everything following our setup and draw functions. 
Than we are going to change float angle, y; to angle = 1. We do this because in
python we d not need to declare these as floats, we only need to set a value to angle. 
Than we are going to add global angle right under  def draw (): We do this because 
in python when we add angle into the math function it is only searching for angle in the 
def draw (): function, but by adding global angle it knows to look outside the function. 
So far your code should look like this:     



Than we are going to change the color codes for background and fill to RGB codes. background will be background(255,248,237) and fill will be fill(255,149,149)After that we change angle++ to angle+=1 Your code should look like this:  

When you run it you should get a program that draws a parabola and finishes like this:





Wednesday, June 10, 2015

BASICS & CIRCLE


 I will be following along part with this tutorial but I will show you how to convert it from Java (the mode used in to the tutorial) to Python.  
So first things first, we’re going to open up Processing and make sure its in Python mode:


After we are sure its in Python we are going to add our set up and draw function. In the linked tutorial the maker puts void setup () and void draw () followed by curly brackets where he store all the code he wants to follow these commands. Since we are doing it in python mode these must look a little different. Our setup and draw functions will instead be def setup (): and def draw (): like this:


After our def setup ():  we will add all the things we want to happen once and once only, for example our desired screen size, and background color. After our def draw (): function we will put all the things we want to show up on our screen, for example shapes and their colors. I’m setting the screen size to 500 by 400 pixels and the background to light blue. In the tutorial he does his commands followed by a colon, we do not need to do this in Python. 
You will set the screen size by putting size(500,400) indented under your def setup(): function. You will set the background color (light blue, in this case) by putting background(194, 244, 255) indented under your def setup(): function. The numbers in the brackets next to background are RGB color code numbers for light blue, if you wish to make your background color different you can find more RGB codes here.  
This is what your code should look like so far:

Now we are going to begin to add our shapes and playing with their colors. The shapes I will be doing today are circles (called ellipse in the code). Again, in the video tutorial linked he follows all lines of code with a colon, we do not need to do this. 
To make a circle we must put ellipse(250,200,150,150) indented under our def draw(): function. The number in brackets next to ellipse are the placement of the circle and the size, the placement of mine is 250 x and 200 y and the size is 150 by 150 pixels. To change the color of the stoke and fill of our ellipse we must add the stroke() and fill() command before our ellipse. I am going to make my stoke and fill both a dark purple. To do this we add the RGB color code to our brackets next to our stroke() and fill()command. 
Your code should now look like this:

And when you run your program it should look like this:


You have now successfully made a Python program that prints out a circle. Feel free to play around with the colors, sizes, and shapes position.