Here is the March 6th web exercise. Now that I have a working OpenGL environment to do these in, they really weren't too hard. You can see next to the images of the curve what code I added to make it work. The box was just a lot of glVertex3f calls, but again, not too difficult.
Monday, March 23, 2009
First GLUT compile
Yeah, I am a little behind getting these things done and posted, but here is the first simple run of an OpenGL and glut program in Dev-C++. I need to thank Mike Haizlip for the awesome walkthrough that he found and linked to get this working, I was not having much luck when I tried with visual studio.
Wednesday, March 4, 2009
Project 1 - Substrate with Curves



Here's a few images I got running the altered Substrate code. Honestly I don't feel like they are the most interesting images, but when you go to curves like this with far more random variables, I suppose it wouldn't come out looking as ordered and nice as the original.
The coding itself was not terribly difficult, it took a couple hours to figure out what affected what in the original code, but once I did it made plenty of sense. It uses only Cubic Bezier curves, and unfortunately I never got the sand painter to work with it.
Tuesday, February 3, 2009
Bezier Curves (hw 3 part 1)
Haven't yet figured out how to make an applet work, but here is an image of a cubic bezier curve.The linear and quadratics also work, but I don't have an image, if you want to play with it to make sure, the code is below.
void setup()
{
size (400, 400);
background (0,0,0);
stroke (255);
}
void draw()
{
saveFrame("bezier.jpeg");
}
int count = 0;
int x0=0,x1=0,x2=0,x3=0,y0=0,y1=0,y2=0,y3=0;
void mousePressed()
{
if (count == 0)
{
x0 = mouseX;
y0 = mouseY;
ellipse(x0, y0, 5, 5);
count++;
}
else if (count == 1)
{
x1 = mouseX;
y1 = mouseY;
ellipse(x1, y1, 5, 5);
linearB(x0, y0, x1, y1);
count++;
}
else if (count == 2)
{
x2 = mouseX;
y2 = mouseY;
background(0,0,0);
ellipse(x0, y0, 5, 5);
ellipse(x1, y1, 5, 5);
ellipse(x2, y2, 5, 5);
quadB(x0, y0, x1, y1, x2, y2);
count++;
}
else if (count == 3)
{
x3 = mouseX;
y3 = mouseY;
background(0,0,0);
ellipse(x0, y0, 5, 5);
ellipse(x1, y1, 5, 5);
ellipse(x2, y2, 5, 5);
ellipse(x3, y3, 5, 5);
cubicB(x0, y0, x1, y1, x2, y2, x3, y3);
count++;
}
else if (count >= 4)
{
background(0,0,0);
count = 0;
}
}
void linearB (int x0, int y0, int x1, int y1)
{
for (float t=0; t<1; t+=.001)
{
point ((1-t)*x0 + (t*x1), (1-t)*y0 + (t*y1));
}
}
void quadB (int x0, int y0, int x1, int y1, int x2, int y2)
{
for (float t=0; t<1; t+=.001)
{
point ((sq(1-t)*x0 + 2*(1-t)*t*x1 + sq(t)*x2),
(sq(1-t)*y0 + 2*(1-t)*t*y1 + sq(t)*y2));
}
}
void cubicB (int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3)
{
for (float t=0; t<1; t+=.001)
{
point ((pow((1-t),3)*x0 + 3*sq(1-t)*t*x1 + 3*(1-t)*sq(t)*x2 + pow(t,3)*x3),
(pow((1-t),3)*y0 + 3*sq(1-t)*t*y1 + 3*(1-t)*sq(t)*y2 + pow(t,3)*y3));
}
}
Homework 2 Revisited
I've finally gone back and tracked down my errors as well as compiled them into one nice image for homework 2. Here is the code:
void setup(){
size (400, 400);
background (0,0,0);
stroke (255);
}
void myCircle (int x0, int y0, int rad){
int f = 1 - rad;
int ddF_x = 1;
int ddF_y = -2 * rad;
int x = 0;
int y = rad;
point(x0, y0 + rad);
point(x0, y0 - rad);
point(x0 + rad, y0);
point(x0 - rad, y0);
while (x < y){
if (f >= 0){
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;
point (x0 + x, y0 + y);
point (x0 - x, y0 + y);
point (x0 + x, y0 - y);
point (x0 - x, y0 - y);
point (x0 + y, y0 + x);
point (x0 - y, y0 + x);
point (x0 + y, y0 - x);
point (x0 - y, y0 - x);
}
}
void web(){
int x1, x2, y1, y2, n;
n = 500;
x1 = 0;
x2 = n;
y1 = 1;
y2 = 0;
int i;
for (i = 0; i < n; i++){
line (x1, x2, y1, y2);
x2-=10;
y1+=10;
}
}
void myLine(int x0, int y0, int x1, int y1){
boolean steep = (abs(y1 - y0) > abs(x1 - x0));
int temp;
if (steep){
temp = x0;
x0 = y0;
y0 = temp;
temp = x1;
x1 = y1;
y1 = temp;
}
if (x0 > x1){
temp = x0;
x0 = x1;
x1 = temp;
temp = y0;
y0 = y1;
y1 = temp;
}
int delta_x = x1 - x0;
int delta_y = abs(y1 - y0);
float error = 0;
float delta_err = (float)delta_y/delta_x;
int y_step;
int y = y0;
if (y0
}
else{
y_step = -1;
}
for (int x = x0; x < x1; x++){
if (steep){
point (y, x);
}
else{
point (x, y);
}
error += delta_err;
if (error >= 0.5){
y += y_step;
error -= 1.0;
}
}
}
void draw(){
web();
myCircle (200,200,50);
myLine (300, 80, 269, 300);
saveFrame("hw1.jpeg");
}
And now on to homework 3...
Thursday, January 29, 2009
After looking around a little, while there are a ton of very impressive projects to look at, I am sure they were huge undertakings. The one I found that seems like I would enjoy using as a guideline for a project reminds me of a toy I love as a kid... Spiral-Doodle or something like that. You draw around and it makes a symmetrical sketch of surprising intricacy. This is works on that premise but without the locked in discs creating pre-designed results using your mouse and I find it fun to play with still. Here is the link to the app they have posted.
http://oimotabe.com/processing/20/
Don't see any code for it, but that's likely ok. It's not the most complicated seeming program, but I am a fan of the results even if more often than not it looks like a bunch of scribbles being drawn.
http://oimotabe.com/processing/20/
Don't see any code for it, but that's likely ok. It's not the most complicated seeming program, but I am a fan of the results even if more often than not it looks like a bunch of scribbles being drawn.
Thursday, January 22, 2009
Homework 2: Line, Circle, and web

Well, its by far the best of the 3 algorithms, mostly because it actually worked. Although, it also is a more interesting looking thing as well. Knowing how lines and other shapes are created is something that is good to know too though.

Had some problems with these two. The circle is essentially there, which I count as at least a partial success. As for the lines, the one at the angle was created with the built in liine function and the horizontal one was supposed to match it entirely with my own. Obviously I missed something but I haven't been able to determine where.
Thursday, January 8, 2009
Homework 1, An Intro to Processing

This software is actually surprisingly easy to catch on to. Considering I spent 40 min to an hour on it, the sword I threw together with the basic functions is neat enough. Below is the code used to create this image. And yes, I agree, that red background is way too bright, but I am ok with that.
void setup()
{
size (400,400);
stroke (225);
background (255, 0, 0);
}
void draw()
{
//blade
line (169, 50, 169, 280);
line (184, 50, 184, 280);
line (177, 10, 177, 273); //center line
line (169, 50, 177, 10);
line (184, 50, 177, 10);
//hilt left
line (169, 280, 140, 275);
line (169, 280, 177, 273);
line (140, 275, 137, 282);
line (137, 282, 168, 290);
//hilt right
line (184, 280, 213, 275);
line (184, 280, 177, 273);
line (213, 275, 216, 282);
line (216, 282, 185, 290);
//grip
line (168, 290, 185, 290);
line (168, 290, 170, 340);
line (185, 290, 183, 340);
//pommel
ellipse (176.5, 345, 20, 20);
//jewel
ellipse (176.5, 283, 5, 5);
saveFrame ("sword.png");
}
Subscribe to:
Posts (Atom)