Python 3D Graphics Tutorial 10: Program for Orb With Continuously Varying Color Rainbow

preview_player
Показать описание
You guys can help me out over at Patreon, and that will help me keep my gear updated, and help me keep this quality content coming:

In this video we show step-by-step instructions on how to program an orb with a smooth and continuous change of color. This is the solution to the homework I gave you in Lesson 9 in this series. We show how to create a mesmerizing orb that smoothly transitions through a range of colors.. I do not assume you are an expert, so these lessons are designed for complete beginners.
#Python
#Lessons
#Graphics
Рекомендации по теме
Комментарии
Автор

from vpython import *
import numpy as np
import random
import time

for z in np.linspace(0, 1, 10):
for y in np.linspace(0, 1, 10):
for x in np.linspace(0, 1, 10):
box(pos=vector(x, y, z), size=vector(0.1, 0.1, 0.1), color=vector(x, y, z), opacity=0.5)

miguelbernadez
Автор

I AM LEGEND! I made a nice, smoothly changing orb. I used the same increment for each color, but started each color at a different value. Now I have to try your solution and see how it is better. Thanks again for the most excellent lessons!

cbrombaugh
Автор

for homework, I have taken your hint and did something long. I used modulo of 3 and written "if" condition for all three places where red, green, and blue stays constant. After entering the if statement, I straight away typed the increment values. Every if statement contains, 0, 1, -1 increment values based on modulo values. Thus it became possible for me keep the brightness at 2

Thanks for your great tutorial Paul. Now, I am going to look how you have approached the problem

soundarrajankannan
Автор

you can change the python version easily from the bottom left corner of visual studio code screen.
Found this one tough. Not much programming experience apart from these videos but really enjoying them.

panicartist
Автор

I can watch that orb for hours....🙂. Good homework. Thanks for the explanation on paper as well.

zoltantakacs
Автор

I did the homework but did it differently using for loops. With my method I have a smooth color change but still suffer from the same brightness problem. Will try using your method now without looking at the video and then go on to try the next homework and come up with a solution to get a stable brightness level.

ecassar
Автор

Some bits of my previous homework worked out for this solution. Great lesson as always.

johnplowright
Автор

Id love to see u do a basic crank and piston! thatll get the trig out!!!

magnuswootton
Автор

Hi Paul - enjoyed that one. I am legend. Surprisingly only a few lines of coding for this one. Thanks for the series.

ardespmaker
Автор

I am a lawn chair :( great lesson Paul, Thanks a lot for what you do!
kind of difficult the Homework but once you think about it it's pretty simple.

danielsaenz
Автор

I am legend. That was a tough one, trying to get the if conditions correct. It will be interesting to see if everyone did it the same way.

GCRickerNH
Автор

I came up with a solution but I will be interested to compare it to yours!!

ellerycadel
Автор

Folded up like a cheap lawn chair!, I was close and got it to work when I applied it with "mySphere.color=vector(myRedCol, myGreenCol, myBlueCol)"

TheCourtoh
Автор

Very interesting lesson and it's going to be very very interesting in coming future... Eagerly waiting for the Arduino to come in the project. Thank u sir.

pralaymajumdar
Автор

As i think there is some mistake regarding constant brightness I think green would be 0.3 and blue would be 0.7 but it is not exactly 0.5 each, as i am true PAUL

aliakbar
Автор

I am legend. I did my orb the same as you did. I am now working on constant brightness without hints. Hope I don't FULACWMLC

petefontana
Автор

I am legend

from vpython import *
import random

curr, nex, delta, tmp = [random.uniform(0.5, 1), random.uniform(0.5, 1), random.uniform(0.5, 1)], [0, 0, 0], [0, 0, 0], [0, 0, 0]
Orb = sphere(radius = 1, color = vector(curr[0], curr[1], curr[2]))

while True:
bias = random.randint(0, 2)
curr[bias] = 1 # I wanted the colours to be 'strong' so I set one component to 1
for i in range(3):
if(i != bias):
nex[i] = random.uniform(0, 1) # also can set this range to 0.5 to 1 for different effects 🙂
tmp[i] = curr[i]
for j in range(200):
rate(100)
for i in range(3):
tmp[i] = tmp[i] + (nex[i] - curr[i])/200
Orb.color = vector(tmp[0], tmp[1], tmp[2])
for i in range(3):
curr[i] = tmp[i]

JackVersey
Автор

Pls advises me a nice book exercises for this course.

aladdinsamaddin
Автор

I folded, but not like a cheap Walmart lawn chair! I put up a pretty good fight before giving up! (EDIT: And I folded over a single typo! I actually had it! Aside from using different terms/names, I was scratching my head trying to figure out how mine was so different from yours that it didn't work. It wasn't any different. just a typo!)

wayneswan
Автор

I am Legend, maybe. I used a different methodology. I created three random numbers between 0 and 1, then calculated an adjustment factor so that their sum was 2. Then those adjusted numbers are used in the color vector. My program uses 13 lines of code.

jaywilhelmi