Last active
June 29, 2022 15:06
-
-
Save jdegenstein/16d2ead29b18d23a0d4b70176357c7a9 to your computer and use it in GitHub Desktop.
CadQuery Clock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cadquery as cq | |
from cadquery import Location, Vector | |
from math import degrees, sin, cos, radians, pi | |
od = 100 | |
dotr = 2 | |
rim = 4 | |
dot_offs = 10 | |
ov_th = 5 | |
dot_ang = 360/12 | |
ctime = 9.38 #current time | |
s1 =( #outercircle sketch | |
cq.Sketch() | |
.circle(od/2) | |
) | |
s1_c = ( #rim cut | |
cq.Sketch() | |
.circle(od/2-rim) | |
) | |
s2 = ( #hour hand | |
cq.Sketch() | |
.rect(3,od*.25) | |
.moved(Location(Vector(0,od*.25/2,0))) | |
) | |
s2_2 = ( #min hand | |
cq.Sketch() | |
.rect(3,od*.33) | |
.moved(Location(Vector(0,od*.33/2,0))) | |
) | |
s3 = ( #clock dots for hours and center | |
cq.Sketch() | |
.parray(r=od/2-dot_offs,da=360,a1=0,n=12) | |
.circle(dotr) | |
.push([(0,0)]) | |
.circle(dotr) | |
) | |
f0 = ( | |
cq.Workplane("XY") | |
.placeSketch(s1) | |
.extrude(ov_th) | |
.faces(">Z") | |
.workplane() | |
.placeSketch(s1_c) | |
.cutBlind(-ov_th/2) | |
.faces(">Z[1]") | |
.workplane().tag("clockface") | |
.placeSketch(s3) | |
.extrude(2) | |
.workplaneFromTagged("clockface") | |
.transformed(rotate=Vector(0,0,-dot_ang*ctime)) | |
.placeSketch(s2) | |
.extrude(1) | |
.workplaneFromTagged("clockface") | |
.transformed(rotate=Vector(0,0,-ctime%1*12*dot_ang)) | |
.placeSketch(s2_2) | |
.extrude(1.5) | |
.faces("<Z or >Z") | |
.edges() | |
.fillet(1) | |
) | |
if "show_object" in locals(): | |
show_object(f0) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment